de.esprit.common.util

## Class Util

- java.lang.Object
- - de.esprit.common.util.Util

-     public final class Util
      extends java.lang.Object

  This is a collection of useful utility methods which are basically reusable in any project.
  Author:
    Rainer Buesch

- - ### Method Summary

    Methods
    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> T` | `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> T` | `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.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### containsValue

          public static boolean containsValue(java.lang.String[] list,
                              java.lang.String value)

      Tests whether the array contains the given value.

    - #### containsValue

          public static boolean containsValue(int[] array,
                              int value)

      Tests whether the array contains the given value.

    - #### containsValue

          public static boolean containsValue(java.lang.String[] array,
                              java.lang.String value,
                              boolean ignoreCase)

      Tests whether the array contains the given value.

    - #### containsValue

          public static boolean containsValue(java.lang.Object[] array,
                              java.lang.Object value)

      Tests whether the array contains the given value.

    - #### concatArrays

          public static java.lang.Object[] concatArrays(java.lang.Object[] origEntries,
                                        java.lang.Object[] addedEntries)

      Concatenates the two given arrays to a single one. The resulting Object[] may be casted to the argument type. Both argument arrays must be of the same type.

    - #### bestOf

          public static <E> E bestOf(E o1,
                     E o2)

      Returns the first of the two arguments which is not null.

    - #### bestOf

          public static java.lang.String bestOf(java.lang.String s1,
                                java.lang.String s2)

      Returns the first of the two strings which is valid.

    - #### randomFlag

          public static boolean randomFlag()

      Returns a random true or false

    - #### checkValid

          public 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.

    - #### checkValid

          public 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.

    - #### checkValid

          public static <T extends java.util.Collection> T 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.

    - #### checkValid

          public 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.

    - #### checkValidValues

          public 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.

    - #### checkValid

          public static <T extends java.util.Map> T 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.

    - #### checkNotNull

          public static <T> T checkNotNull(java.lang.Object obj,
                           java.lang.String fieldName)

      Throws a `NullPointerException` if the given reference is null. The fieldName is contained in the error message.

    - #### checkNotNull

          public static <T> T checkNotNull(T obj,
                           java.lang.Class<T> myClass)

      Throws a `NullPointerException` if the given reference is null. The class name is contained in the error message.

    - #### isValid

          public static boolean isValid(java.lang.String str)

      Checks if the argument is a valid String object. A valid String must not consist of only blank characters.

    - #### isValid

          public static boolean isValid(java.lang.Object obj)

      Checks if the argument is a valid Object which has a non-empty `Object.toString()` method.

    - #### isValid

          public static boolean isValid(java.lang.Object[] objArray)

      Checks if the argument is a valid non empty Object array.

    - #### isValid

          public static boolean isValid(int[] intArray)

      Checks if the argument is a non null and non empty array.

    - #### isValid

          public static boolean isValid(byte[] byteArray)

      Checks if the argument is a non null and non empty array.

    - #### isValid

          public static boolean isValid(java.util.Collection list)

      Checks if the argument is a non null and non empty list.

    - #### isValid

          public static boolean isValid(java.util.Map map)

      Checks if the argument is a non null and non empty map.

    - #### isValid

          public static boolean isValid(java.awt.Rectangle rect)

      Checks if the argument is a non null rectangle that has a valid size.

    - #### isValidEmailAddress

          public static boolean isValidEmailAddress(java.lang.String emailAddr)

      Checks whether the given String syntactically is a valid email-address

    - #### beep

          public static boolean beep()

      Just beeps (acoustic signal)

    - #### classNameOf

          public static java.lang.String classNameOf(java.lang.Object object)

      Returns the base name of a fully qualified class name.

    - #### sleep

          public static void sleep(long millis)

      Just blocks for the given number of milliseconds.

    - #### deepClone

          public static <T> T deepClone(T src)

      This method does a deep clone of an object including their referenced sub-objects. It requires the whole Object tree to be fully serializable.

    - #### createExceptionMessages

          public static java.lang.String createExceptionMessages(java.lang.Throwable e)

      Builds a String containing all exception messages of all Exceptions in the stack.

    - #### createExceptionMessage

          public 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.

    - #### createExceptionStackTrace

          public static java.lang.String createExceptionStackTrace(java.lang.Throwable error)

      Returns the stack trace as a String.

    - #### createTruncatedExceptionStackTrace

          public static java.lang.String createTruncatedExceptionStackTrace(java.lang.Throwable e,
                                                            int maxLength)

      Returns a shortened stack trace with maxLength chars.

    - #### isEqualIgnoreCase

          public static boolean isEqualIgnoreCase(java.lang.String s1,
                                  java.lang.String s2)

      Performs a null safe and case insensitive equals check on the given Strings.

    - #### isEqual

          public static boolean isEqual(java.lang.Object o1,
                        java.lang.Object o2)

      Performs a null safe equals() check on both objects.

    - #### isEqual

          public static boolean isEqual(java.lang.Object[] a1,
                        java.lang.Object[] a2)

      Checks if all entries in both arrays match by their equals() method. Returns false if any of the arrays is null or if their length do not match.

    - #### roundedPercentage

          public static int roundedPercentage(double maxValue,
                              double value)

      Calculates the percentage and returns an according int value between 0 and 100

    - #### roundedPercentage

          public static int roundedPercentage(double maxValue,
                              double value,
                              boolean isLimited)

      Calculates the percentage and returns an according int value between 0 and 100
      Parameters:
        `isLimited` - if true then the resulting value will be limited to 100, may be > 100 otherwise

    - #### round

          public static double round(double value,
                     java.math.RoundingMode rounding,
                     int digits)

      Rounds the given value. WARNING this call is expensive!

    - #### calculateTickSize

          public static int calculateTickSize(double min,
                              double max)

    - #### reverse

          public static <E> E[] reverse(E[] array)

      Reverses the elements in the array

    - #### maxKeyLengthOf

          public static int maxKeyLengthOf(java.util.Map map)

      Calculates the maximal textual length of the keys contained in the given Map. Is useful for formatting Map entries.

    - #### lastOf

          public static <T> T lastOf(T[] values)

      Returns the last element of an array.

    - #### lastOf

          public static <T> T lastOf(java.util.List<T> list)

      Returns the last element of a list.

    - #### printConsoleMessage

          public static void printConsoleMessage(java.lang.String msg)

    - #### logConsoleMessage

          public static void logConsoleMessage(java.lang.String msg)

    - #### logConsoleError

          public static void logConsoleError(java.lang.String msg,
                             java.lang.Throwable error)

    - #### printControlledException

          public static void printControlledException(java.lang.Throwable e)

      Prints the given Exception to the error console in a well formatted manner

Copyright © 2014 EsprIT-Systems. All Rights Reserved.