|
andyLib v0.9 | ||||||||
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 |
getFileExt(String fileName)
|
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. |
static String |
removeFileExt(String fileName)
Remove the extension from a file name. |
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)
null
or its length is 0.
s
- the string to check
true
if the string is empty, false
otherwisepublic static void printException(String message, Throwable t)
Print (in this order):
null
or empty.
Note: if more flexibility is needed, the andyLog
Project
can be used.
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
null
if it
does not represent an Integerpublic 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
null
if it does
not represent a Longpublic 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
, using the string sep
.
If the list is empty, this method returns an empty string (not null
). If sep
is empty, it concats the elements with no
separator.
s
- strings to be concatedseparator
- separator
NullPointerException
- if s
is null
public static String concat(List l, String separator)
l
, using the string sep
.
If the list is empty, this method returns an empty string (not null
). If sep
is empty, it concats the elements with no
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
is 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
null
if there is no matchpublic static String removeFileExt(String fileName)
fileName
- the file name
public static String getFileExt(String fileName)
|
andyLib v0.9 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |