eu.beesoft.gaia.util
Class Objects

java.lang.Object
  extended by eu.beesoft.gaia.util.Objects

public final class Objects
extends java.lang.Object

Utility class developed to make some operations with objects easier.


Method Summary
static java.lang.Object convert(java.lang.Object object, java.lang.Class<?> targetType)
          Converts given object to the instance of given targetType.
static boolean equals(java.lang.Object obj1, java.lang.Object obj2)
          Compares two objects and returns true if: they both are null they are identical they are equal The goal of this method is you don't need take a care about null values.
static java.lang.Class<?>[] getTypes(java.lang.Object... arg)
          Returns array of classes of objects that are in arg array.
static int hashCode(java.lang.Object... object)
          Computes hash code from given object(s).
static boolean isEmpty(java.util.Collection<?> collection)
          Returns true if given collection is null or is empty.
static boolean isEmpty(java.util.Map<?,?> map)
          Returns true if given map is null or is empty.
static boolean isEmpty(java.lang.Object object)
          Returns true if given object is null or is empty.
static boolean isEmpty(java.lang.Object[] array)
          Returns true if given array is null or is empty or contains only null values.
static boolean isEmpty(java.lang.String string)
          Returns true if given string is null, is empty String or contains only whitespace characters.
static java.lang.String toString(java.lang.Object object)
          Returns a text representation of the given object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

toString

public static java.lang.String toString(java.lang.Object object)
Returns a text representation of the given object. If object is null, returns empty String. If object is a String return it self. Otherwise calls toString() method on the object.

Parameters:
object - - the object, may be null
Returns:
a text representation of the object

hashCode

public static int hashCode(java.lang.Object... object)
Computes hash code from given object(s). Each item in given 'object' array is checked for non-null value and then is called hashCode() method on it. Results are added together and returned.

Parameters:
object - - the object(s) to calculate hash code, any if them may be null
Returns:
computed hash code

equals

public static boolean equals(java.lang.Object obj1,
                             java.lang.Object obj2)
Compares two objects and returns true if: The goal of this method is you don't need take a care about null values.

Parameters:
obj1 - - first object to compare
obj2 - - second object to compare
Returns:
true if objects are equal

getTypes

public static java.lang.Class<?>[] getTypes(java.lang.Object... arg)
Returns array of classes of objects that are in arg array. In the source array can be null values, then is null on the appropriate position in the output array, too. If in source array is class, it is stored to output array.

Parameters:
arg - - array of objects, may be null
Returns:
array of classes of given objects, never null

convert

public static java.lang.Object convert(java.lang.Object object,
                                       java.lang.Class<?> targetType)
Converts given object to the instance of given targetType. Currently it supports these conversions: If you try convert some other types, RuntimeException is thrown.

Parameters:
object - - object to convert
targetType - - instance of this class is required to return
Returns:
converted object
Throws:
java.lang.RuntimeException - if cannot convert

isEmpty

public static boolean isEmpty(java.lang.String string)
Returns true if given string is null, is empty String or contains only whitespace characters.

Parameters:
string - - String to check
Returns:
true if string is empty

isEmpty

public static boolean isEmpty(java.util.Collection<?> collection)
Returns true if given collection is null or is empty.

Parameters:
collection - - collection to check
Returns:
true if collection is empty

isEmpty

public static boolean isEmpty(java.util.Map<?,?> map)
Returns true if given map is null or is empty.

Parameters:
map - - map to check
Returns:
true if map is empty

isEmpty

public static boolean isEmpty(java.lang.Object[] array)
Returns true if given array is null or is empty or contains only null values.

Parameters:
array - - array to check
Returns:
true if array is empty

isEmpty

public static boolean isEmpty(java.lang.Object object)
Returns true if given object is null or is empty. Dispatches this task to the appropriate isEmpty() method in dependency on the type of object. Returns false, if object is not null, String, Collection, Map or Object array.

Parameters:
object - - object to check
Returns:
true if object is null or empty