|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.ckkloverdos.util.Util
public final class Util
General utility methods.
| Field Summary | |
|---|---|
static java.lang.Object[] |
EMPTY_ARRAY
Empty object array |
static java.util.Random |
RANDOM
A utility random instance. |
static java.text.SimpleDateFormat |
STD_DATE_FMT
The default date format |
| Method Summary | |
|---|---|
static java.lang.Object[] |
arrayFromItem(java.lang.Object object)
Returns either an empty array or a one-item array containing the given object. |
static java.lang.Object[] |
arrayFromItem(java.lang.Object component,
java.lang.Class componentType)
Returns either an empty array or a one-item array containing the given component. |
static boolean |
emptySafe(java.util.Collection collection)
Checks if the provided collection is empty. |
static boolean |
emptySafe(IL list)
Checks if the provided list is empty. |
static boolean |
emptySafe(java.lang.Object[] array)
Checks if the provided array is empty. |
static boolean |
emptySafe(java.lang.String s)
Checks if the provided string is empty. |
static boolean |
equalSafe(java.lang.Object a,
java.lang.Object b)
Checks if the two objects are equal by also taking into account that one of them (or even both) may be null. |
static java.lang.String |
getenv(java.lang.String name)
Returns the environment variable of the given name. |
static java.lang.String |
getEnvOrProperty(java.lang.String name)
Tries to obtain name either as an environment variable or as a system property. |
static java.lang.String |
getFormattedDate()
Formats the current date by using the default date format. |
static java.lang.String |
getFormattedDate(java.text.SimpleDateFormat sdf)
Formats the current date by using the given SimpleDateFormat. |
static java.lang.String |
getLocalHost()
Returns the localhost name. |
static java.lang.String |
getProperty(java.lang.String name)
A wrapper call around System.getProperty(String). |
static java.lang.String |
getPropertyOrEnv(java.lang.String name)
Tries to obtain name either as a system property or as an environment variable. |
static java.util.Random |
getRandom()
Creates a new Random instance, preferably of the SHA1PRNG
algorithm. |
static java.util.Random |
getRandom(java.lang.String algorithm)
Creates a new Random instance, of the algorithm
provided. |
static java.lang.String |
getStackTrace(java.lang.Throwable throwable)
Returns the string representation of the stacktrace provided by throwable. |
static boolean |
isInteger(java.lang.String s)
Returns true iff s can be parsed correctly by
Integer.parseInt(s). |
static boolean |
isLong(java.lang.String s)
Returns true iff s can be parsed correctly by
Long.parseLong(String). |
static java.lang.ClassLoader[] |
safe(java.lang.ClassLoader[] array)
Returns array "safe" value for array. |
static java.io.File[] |
safe(java.io.File[] array)
Returns array "safe" value for array. |
static java.lang.Object[] |
safe(java.lang.Object[] array,
java.lang.Class componentType)
Returns a "safe" value for array of the given componentType. |
static java.util.Set |
safe(java.util.Set set)
Returns a "safe" value for set. |
static java.lang.String |
safe(java.lang.String s)
Returns a "safe" value for s. |
static java.lang.String[] |
safe(java.lang.String[] array)
Returns array "safe" value for array. |
static double |
safe(java.lang.String s,
double safe)
Returns a "safe" value of the double represented by String s. |
static int |
safe(java.lang.String s,
int safe)
Returns a "safe" value of the int represented by String s. |
static long |
safe(java.lang.String s,
long safe)
Returns a "safe" value of the long represented by String s. |
static java.net.URL |
toURL(java.lang.String s)
Tries to convert s to a URL and ignores a possible MalformedURLException. |
static boolean |
trimmedEmpty(java.lang.String s)
Checks if the provided string is empty, after it is trimmed. |
static boolean |
trimmedEmptySafe(java.lang.String s)
Checks if the provided string is empty, after it is trimmed. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.Object[] EMPTY_ARRAY
public static final java.util.Random RANDOM
public static final java.text.SimpleDateFormat STD_DATE_FMT
| Method Detail |
|---|
public static java.lang.String getFormattedDate(java.text.SimpleDateFormat sdf)
SimpleDateFormat.
sdf -
public static java.lang.String getFormattedDate()
default date format.
public static java.util.Random getRandom()
Random instance, preferably of the SHA1PRNG
algorithm. If this is not possible, then just a new Random() is returned.
Random.public static java.util.Random getRandom(java.lang.String algorithm)
Random instance, of the algorithm
provided. If this is not possible, then just a new Random() is returned.
algorithm - the desired algorithm.
Random.public static boolean trimmedEmpty(java.lang.String s)
null, then you should consider using
trimmedEmptySafe(String).
s - the string to be checked.
0 == s.trim().length()public static java.lang.String getLocalHost()
localhost name. If this cannot be determined, then
localhost is returned.
localhost.public static java.lang.String getStackTrace(java.lang.Throwable throwable)
throwable.
In effect, the following algorithm is applied:
StringWriter w = new StringWriter(); PrintWriter pw = new PrintWriter(w); throwable.printStackTrace(pw); return w.toString();
throwable -
public static java.net.URL toURL(java.lang.String s)
s to a URL and ignores a possible MalformedURLException.
s -
URLpublic static java.lang.String getPropertyOrEnv(java.lang.String name)
name either as a system property or as an environment variable.
First, it tries to obtain name by using System.getProperty(name).
If this returns null and we are under Java 1.5+, then it uses System.getenv(name).
name -
name.public static java.lang.String getEnvOrProperty(java.lang.String name)
name either as an environment variable or as a system property.
First, if we are under Java version < 1.5, it just returns System.getProperty(name).
Otherwise, if we are under Java version >= 1.5, it first tries to obtain name by using System.getenv(name).
If this returns null it returns System.getProperty(name).
name -
name.public static boolean isInteger(java.lang.String s)
true iff s can be parsed correctly by
Integer.parseInt(s).
s -
true iff s contains an integer.public static boolean isLong(java.lang.String s)
true iff s can be parsed correctly by
Long.parseLong(String).
s -
true iff s contains a long.public static java.lang.String getenv(java.lang.String name)
name.
Since System.getenv(String) is deprecated for java 1.4, if we are
in a 1.4 VM then System.getProperty(String) is called, otherwise
System.getenv(String) is called.
name -
public static java.lang.String getProperty(java.lang.String name)
System.getProperty(String).
name -
name.
public static boolean equalSafe(java.lang.Object a,
java.lang.Object b)
NullPointerExceptions.
a - b -
true iff a and b are equal.public static boolean emptySafe(java.lang.String s)
null string is also considered empty.
s - the string to be checked.
s == null || 0 == s.length()public static boolean trimmedEmptySafe(java.lang.String s)
null string is also considered empty.
s - the string to be checked.
s == null || 0 == s.trim().length()public static java.lang.String safe(java.lang.String s)
s.
If s is null, then the empty string "" is returned.
s -
s if it is not null, otherwise "".
public static java.lang.Object[] safe(java.lang.Object[] array,
java.lang.Class componentType)
array of the given componentType.
If array is null, then an empty Object[] array is returned.
array - componentType -
array if it is not null, otherwise an empty Object[] array.public static java.util.Set safe(java.util.Set set)
set.
If set is null, then an empty Set is returned.
set -
set if it is not null, otherwise an empty Set.public static java.lang.Object[] arrayFromItem(java.lang.Object object)
object.
If object is null, then an empty array is returned.
Otherwise, an array of type object.getJavaClass() and length 1 is created
and filled with object.
object -
public static java.lang.Object[] arrayFromItem(java.lang.Object component,
java.lang.Class componentType)
component.
The array component type is determined by componentType.
If component is null, then an empty array is returned.
After succesfull return, the client can safely cast the return value to the proper array type.
component - componentType -
java.lang.NullPointerException - if componentType is null.public static boolean emptySafe(java.lang.Object[] array)
null value for array is also considered as an empty array.
array - the array to be checked.
null == array ? true : 0 == array.lengthpublic static java.lang.String[] safe(java.lang.String[] array)
array.
If array is null, then an empty String[] array is returned.
array -
array if it is not null, otherwise an empty String[] array.public static java.io.File[] safe(java.io.File[] array)
array.
If array is null, then an empty File[] array is returned.
array -
array if it is not null, otherwise an empty File[] array.public static java.lang.ClassLoader[] safe(java.lang.ClassLoader[] array)
array.
If array is null, then an empty ClassLoader[] array is returned.
array -
array if it is not null, otherwise an empty ClassLoader[] array.public static boolean emptySafe(java.util.Collection collection)
collection is empty.
A null value for collection is also considered as an empty collection.
collection - the collection to be checked.
collection as empty.public static boolean emptySafe(IL list)
list is empty.
A null value for list is also considered as an empty list.
list -
true iff it is safe to consider list as empty.
public static int safe(java.lang.String s,
int safe)
int represented by String s.
If s cannot be parsed correctly as an int, then the value
safe is returned.
s - the string representation of the int.safe - the safe value for the int.
int provided in String s.
public static long safe(java.lang.String s,
long safe)
long represented by String s.
If s cannot be parsed correctly as an long, then the value
safe is returned.
s - the string representation of the long.safe - the safe value for the long.
long provided in String s.
public static double safe(java.lang.String s,
double safe)
double represented by String s.
If s cannot be parsed correctly as an double, then the value
safe is returned.
s - the string representation of the double.safe - the safe value for the double.
double provided in String s.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||