public final class Util
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static boolean |
beep()
Just beeps (acoustic signal)
|
static <E> E |
bestOf(E o1,
E o2)
Returns the first of the two arguments which is not null.
|
static java.lang.String |
bestOf(java.lang.String s1,
java.lang.String s2)
Returns the first of the two strings which is valid.
|
static int |
calculateTickSize(double min,
double max) |
static <T> T |
checkNotNull(java.lang.Object obj,
java.lang.String fieldName)
Throws a
NullPointerException if the given reference is null. |
static <T> T |
checkNotNull(T obj,
java.lang.Class<T> myClass)
Throws a
NullPointerException if the given reference is null. |
static <T extends java.util.Collection> |
checkValid(java.util.Collection list,
java.lang.String errorMessage)
Returns the Collection passed in unchanged, but throws an IllegalArgumentException with the
given errorMessage if the Collection is null or empty.
|
static int |
checkValid(int positiveNumber,
java.lang.String errorMessage)
Returns the input number unchanged, but throws an IllegalArgumentException with the given
errorMessage if the number is not positive.
|
static <T extends java.util.Map> |
checkValid(java.util.Map map,
java.lang.String errorMessage)
Returns the Map passed in unchanged, but throws an IllegalArgumentException with the given
errorMessage if the Map is null or empty.
|
static java.lang.String |
checkValid(java.lang.String text,
java.lang.String errorMessage)
Returns the input text unchanged, but throws an IllegalArgumentException with the given
errorMessage if the text is not valid.
|
static <T> T[] |
checkValid(T[] array,
java.lang.String errorMessage)
Returns the array unchanged, but throws an IllegalArgumentException with the
given errorMessage if the array is null or empty.
|
static <T> T[] |
checkValidValues(T[] array,
java.lang.String errorMessage)
Returns the array unchanged, but throws an IllegalArgumentException with the
given errorMessage if the array is null or empty or contains any null values.
|
static java.lang.String |
classNameOf(java.lang.Object object)
Returns the base name of a fully qualified class name.
|
static java.lang.Object[] |
concatArrays(java.lang.Object[] origEntries,
java.lang.Object[] addedEntries)
Concatenates the two given arrays to a single one.
|
static boolean |
containsValue(int[] array,
int value)
Tests whether the array contains the given value.
|
static boolean |
containsValue(java.lang.Object[] array,
java.lang.Object value)
Tests whether the array contains the given value.
|
static boolean |
containsValue(java.lang.String[] list,
java.lang.String value)
Tests whether the array contains the given value.
|
static boolean |
containsValue(java.lang.String[] array,
java.lang.String value,
boolean ignoreCase)
Tests whether the array contains the given value.
|
static java.lang.String |
createExceptionMessage(java.lang.Throwable e)
Formats the Exception message string to show up with the SQL error code if it is an
SQLException - and avoids null messages.
|
static java.lang.String |
createExceptionMessages(java.lang.Throwable e)
Builds a String containing all exception messages of all Exceptions in the stack.
|
static java.lang.String |
createExceptionStackTrace(java.lang.Throwable error)
Returns the stack trace as a String.
|
static java.lang.String |
createTruncatedExceptionStackTrace(java.lang.Throwable e,
int maxLength)
Returns a shortened stack trace with maxLength chars.
|
static <T> T |
deepClone(T src)
This method does a deep clone of an object including their referenced sub-objects.
|
static boolean |
isEqual(java.lang.Object[] a1,
java.lang.Object[] a2)
Checks if all entries in both arrays match by their equals() method.
|
static boolean |
isEqual(java.lang.Object o1,
java.lang.Object o2)
Performs a null safe equals() check on both objects.
|
static boolean |
isEqualIgnoreCase(java.lang.String s1,
java.lang.String s2)
Performs a null safe and case insensitive equals check on the given Strings.
|
static boolean |
isValid(byte[] byteArray)
Checks if the argument is a non null and non empty array.
|
static boolean |
isValid(java.util.Collection list)
Checks if the argument is a non null and non empty list.
|
static boolean |
isValid(int[] intArray)
Checks if the argument is a non null and non empty array.
|
static boolean |
isValid(java.util.Map map)
Checks if the argument is a non null and non empty map.
|
static boolean |
isValid(java.lang.Object obj)
Checks if the argument is a valid Object which has a non-empty
Object.toString() method. |
static boolean |
isValid(java.lang.Object[] objArray)
Checks if the argument is a valid non empty Object array.
|
static boolean |
isValid(java.awt.Rectangle rect)
Checks if the argument is a non null rectangle that has a valid size.
|
static boolean |
isValid(java.lang.String str)
Checks if the argument is a valid String object.
|
static boolean |
isValidEmailAddress(java.lang.String emailAddr)
Checks whether the given String syntactically is a valid email-address
|
static <T> T |
lastOf(java.util.List<T> list)
Returns the last element of a list.
|
static <T> T |
lastOf(T[] values)
Returns the last element of an array.
|
static void |
logConsoleError(java.lang.String msg,
java.lang.Throwable error) |
static void |
logConsoleMessage(java.lang.String msg) |
static int |
maxKeyLengthOf(java.util.Map map)
Calculates the maximal textual length of the keys contained in the given Map.
|
static void |
printConsoleMessage(java.lang.String msg) |
static void |
printControlledException(java.lang.Throwable e)
Prints the given Exception to the error console in a well formatted manner
|
static boolean |
randomFlag()
Returns a random true or false
|
static <E> E[] |
reverse(E[] array)
Reverses the elements in the array
|
static double |
round(double value,
java.math.RoundingMode rounding,
int digits)
Rounds the given value.
|
static int |
roundedPercentage(double maxValue,
double value)
Calculates the percentage and returns an according int value between 0 and 100
|
static int |
roundedPercentage(double maxValue,
double value,
boolean isLimited)
Calculates the percentage and returns an according int value between 0 and 100
|
static void |
sleep(long millis)
Just blocks for the given number of milliseconds.
|
public static boolean containsValue(java.lang.String[] list, java.lang.String value)
public static boolean containsValue(int[] array, int value)
public static boolean containsValue(java.lang.String[] array, java.lang.String value, boolean ignoreCase)
public static boolean containsValue(java.lang.Object[] array, java.lang.Object value)
public static java.lang.Object[] concatArrays(java.lang.Object[] origEntries, java.lang.Object[] addedEntries)
public static <E> E bestOf(E o1, E o2)
public static java.lang.String bestOf(java.lang.String s1, java.lang.String s2)
public static boolean randomFlag()
public static java.lang.String checkValid(java.lang.String text, java.lang.String errorMessage)
public static int checkValid(int positiveNumber, java.lang.String errorMessage)
public static <T extends java.util.Collection> T checkValid(java.util.Collection list, java.lang.String errorMessage)
public static <T> T[] checkValid(T[] array, java.lang.String errorMessage)
public static <T> T[] checkValidValues(T[] array, java.lang.String errorMessage)
public static <T extends java.util.Map> T checkValid(java.util.Map map, java.lang.String errorMessage)
public static <T> T checkNotNull(java.lang.Object obj, java.lang.String fieldName)
NullPointerException
if the given reference is null. The fieldName is
contained in the error message.public static <T> T checkNotNull(T obj, java.lang.Class<T> myClass)
NullPointerException
if the given reference is null.
The class name is contained in the error message.public static boolean isValid(java.lang.String str)
public static boolean isValid(java.lang.Object obj)
Object.toString()
method.public static boolean isValid(java.lang.Object[] objArray)
public static boolean isValid(int[] intArray)
public static boolean isValid(byte[] byteArray)
public static boolean isValid(java.util.Collection list)
public static boolean isValid(java.util.Map map)
public static boolean isValid(java.awt.Rectangle rect)
public static boolean isValidEmailAddress(java.lang.String emailAddr)
public static boolean beep()
public static java.lang.String classNameOf(java.lang.Object object)
public static void sleep(long millis)
public static <T> T deepClone(T src)
public static java.lang.String createExceptionMessages(java.lang.Throwable e)
public static java.lang.String createExceptionMessage(java.lang.Throwable e)
public static java.lang.String createExceptionStackTrace(java.lang.Throwable error)
public static java.lang.String createTruncatedExceptionStackTrace(java.lang.Throwable e, int maxLength)
public static boolean isEqualIgnoreCase(java.lang.String s1, java.lang.String s2)
public static boolean isEqual(java.lang.Object o1, java.lang.Object o2)
public static boolean isEqual(java.lang.Object[] a1, java.lang.Object[] a2)
public static int roundedPercentage(double maxValue, double value)
public static int roundedPercentage(double maxValue, double value, boolean isLimited)
isLimited
- if true then the resulting value will be limited to 100, may be > 100 otherwisepublic static double round(double value, java.math.RoundingMode rounding, int digits)
public static int calculateTickSize(double min, double max)
public static <E> E[] reverse(E[] array)
public static int maxKeyLengthOf(java.util.Map map)
public static <T> T lastOf(T[] values)
public static <T> T lastOf(java.util.List<T> list)
public static void printConsoleMessage(java.lang.String msg)
public static void logConsoleMessage(java.lang.String msg)
public static void logConsoleError(java.lang.String msg, java.lang.Throwable error)
public static void printControlledException(java.lang.Throwable e)
Copyright © 2014 EsprIT-Systems. All Rights Reserved.