|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectit.andynaz.utils.Utils
public abstract class Utils
Generic useful methods.
Constructor Summary | |
---|---|
private |
Utils()
|
Method Summary | |
---|---|
static String |
concat(List l,
String separator)
Concat the elements in a list l, using the string sep. |
static String |
concat(String[] s,
String separator)
Concat the elements in an array s, using the string sep. |
static String |
getInitParam(String paramName,
String[] args)
Returns a paramenter taken from a string array (for instance the one passed to a 'main' method). |
static boolean |
isEmpty(String s)
Check if a string is empty. |
static String |
pad(String s,
String p,
int l)
Pad the string s on the left with the pattern p ,
till the length of (at least) l . |
static Integer |
parseInt(String s)
Get an Integer from a string. |
static Long |
parseLong(String s)
Get a Long from a string. |
static void |
printException(String message,
Throwable t)
Write the log of an exception/error on the standard output, preceed by a custom message. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
private Utils()
Method Detail |
---|
public static boolean isEmpty(String s)
s
- the string to check
public static void printException(String message, Throwable t)
This method print (in this order):
Note: every element is printed only if it is "present", ie it is not null and not empty.
message
- the custom messaget
- exception or error to be loggedpublic static Integer parseInt(String s)
Integer
from a string.
If it is not possible to convert the string, null is returned.
Note: this method does not throw any NumberFormatException
.
s
- a string representing a number
public static Long parseLong(String s)
Long
from a string.
If it is not possible to convert the string, null is returned.
Note: this method does not throw any NumberFormatException
.
s
- a string representing a number
public static String pad(String s, String p, int l)
s
on the left with the pattern p
,
till the length of (at least) l
.
Note: the returned string can be longer than l
.
s
- a string to padp
- pattern to use to pad the stringl
- minimun length of the returned string
NullPointerException
- if at least one of s
or
p
is null.
IllegalArgumentException
- il l<0 or the pattern
p
is emptypublic static String concat(String[] s, String separator)
s
- strings to be concatedseparator
- separator
NullPointerException
- if s==null
public static String concat(List l, String separator)
Note: the method accepts a non-generic list because the access to the elements is in read-only mode.
l
- a listseparator
- a separator
NullPointerException
- if l==null
public static String getInitParam(String paramName, String[] args)
The parameter in the array has to be preceed by the character '-'. If there is no match on the parameter name, the method returns null.
If the parameter name is repeated, only the first occourrence is considered. If the paramenter name is the last element of the array, it is not considered (and null is returned).
As an example, in the strings sequence
ab c -or de finvoking the method as getInitParam("or", args), "de" is returned.
paramName
- the name of the parameterargs
- the array
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |