org.jivesoftware.spark.util
Class ModelUtil

java.lang.Object
  extended by org.jivesoftware.spark.util.ModelUtil

public final class ModelUtil
extends java.lang.Object

Utility methods frequently used by data classes and design-time classes.


Method Summary
static boolean areBooleansDifferent(java.lang.Boolean b1, java.lang.Boolean b2)
          This is a utility method that compares two Booleans when one or both of the objects might be null The result of this method is determined as follows: If b1 and b2 are both TRUE or neither b1 nor b2 is TRUE, return false.
static boolean areBooleansEqual(java.lang.Boolean b1, java.lang.Boolean b2)
          This is a utility method that compares two Booleans when one or both of the objects might be null The result of this method is determined as follows: If b1 and b2 are both TRUE or neither b1 nor b2 is TRUE, return true.
static boolean areDifferent(java.lang.Object o1, java.lang.Object o2)
          This is a utility method that compares two objects when one or both of the objects might be null.
static boolean areEqual(java.lang.Object o1, java.lang.Object o2)
          This is a utility method that compares two objects when one or both of the objects might be null The result of this method is determined as follows: If o1 and o2 are the same object according to the == operator, return true.
static java.lang.String concat(java.lang.String[] strs)
          Returns a single string that is the concatenation of all the strings in the specified string array.
static java.lang.String concat(java.lang.String[] strs, java.lang.String delim)
          Returns a single string that is the concatenation of all the strings in the specified string array.
static java.lang.String getTimeFromLong(long diff)
          Returns a formatted String from time.
static boolean hasLength(java.lang.String s)
          Returns true if the specified String is not null and has a length greater than zero.
static boolean hasNonNullElement(java.lang.Object[] array)
          Returns true if the specified array is not null and contains a non-null element.
static boolean hasStringChanged(java.lang.String oldString, java.lang.String newString)
          Determines if a string has been changed.
static java.util.List iteratorAsList(java.util.Iterator i)
          Build a List of all elements in an Iterator.
static java.lang.String nullifyIfEmpty(java.lang.String s)
          Returns null if the specified string is empty or null.
static java.lang.String nullifyingToString(java.lang.Object o)
          Returns null if the specified object is null or if its toString() representation is empty.
static java.util.Iterator reverseListIterator(java.util.ListIterator i)
          Creates an Iterator that is the reverse of a ListIterator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

areEqual

public static final boolean areEqual(java.lang.Object o1,
                                     java.lang.Object o2)
This is a utility method that compares two objects when one or both of the objects might be null The result of this method is determined as follows:
  1. If o1 and o2 are the same object according to the == operator, return true.
  2. Otherwise, if either o1 or o2 is null, return false.
  3. Otherwise, return o1.equals(o2).

This method produces the exact logically inverted result as the areDifferent(Object, Object) method.

For array types, one of the equals methods in Arrays should be used instead of this method. Note that arrays with more than one dimension will require some custom code in order to implement equals properly.


areBooleansEqual

public static final boolean areBooleansEqual(java.lang.Boolean b1,
                                             java.lang.Boolean b2)
This is a utility method that compares two Booleans when one or both of the objects might be null The result of this method is determined as follows:
  1. If b1 and b2 are both TRUE or neither b1 nor b2 is TRUE, return true.
  2. Otherwise, return false.

This method produces the exact logically inverted result as the areDifferent(Boolean, Boolean) method.


areDifferent

public static final boolean areDifferent(java.lang.Object o1,
                                         java.lang.Object o2)
This is a utility method that compares two objects when one or both of the objects might be null. The result returned by this method is determined as follows:
  1. If o1 and o2 are the same object according to the == operator, return false.
  2. Otherwise, if either o1 or o2 is null, return true.
  3. Otherwise, return !o1.equals(o2).

This method produces the exact logically inverted result as the areEqual(Object, Object) method.

For array types, one of the equals methods in Arrays should be used instead of this method. Note that arrays with more than one dimension will require some custom code in order to implement equals properly.


areBooleansDifferent

public static final boolean areBooleansDifferent(java.lang.Boolean b1,
                                                 java.lang.Boolean b2)
This is a utility method that compares two Booleans when one or both of the objects might be null The result of this method is determined as follows:
  1. If b1 and b2 are both TRUE or neither b1 nor b2 is TRUE, return false.
  2. Otherwise, return true.

This method produces the exact logically inverted result as the areBooleansEqual(Boolean, Boolean) method.


hasNonNullElement

public static final boolean hasNonNullElement(java.lang.Object[] array)
Returns true if the specified array is not null and contains a non-null element. Returns false if the array is null or if all the array elements are null.


concat

public static final java.lang.String concat(java.lang.String[] strs)
Returns a single string that is the concatenation of all the strings in the specified string array. A single space is put between each string array element. Null array elements are skipped. If the array itself is null, the empty string is returned. This method is guaranteed to return a non-null value, if no expections are thrown.


concat

public static final java.lang.String concat(java.lang.String[] strs,
                                            java.lang.String delim)
Returns a single string that is the concatenation of all the strings in the specified string array. The strings are separated by the specified delimiter. Null array elements are skipped. If the array itself is null, the empty string is returned. This method is guaranteed to return a non-null value, if no expections are thrown.


hasLength

public static final boolean hasLength(java.lang.String s)
Returns true if the specified String is not null and has a length greater than zero. This is a very frequently occurring check.


nullifyIfEmpty

public static final java.lang.String nullifyIfEmpty(java.lang.String s)
Returns null if the specified string is empty or null. Otherwise the string itself is returned.


nullifyingToString

public static final java.lang.String nullifyingToString(java.lang.Object o)
Returns null if the specified object is null or if its toString() representation is empty. Otherwise, the toString() representation of the object itself is returned.


hasStringChanged

public static boolean hasStringChanged(java.lang.String oldString,
                                       java.lang.String newString)
Determines if a string has been changed.

Parameters:
oldString - is the initial value of the String
newString - is the new value of the String
Returns:
true If both oldString and newString are null or if they are both not null and equal to each other. Otherwise returns false.

getTimeFromLong

public static java.lang.String getTimeFromLong(long diff)
Returns a formatted String from time.

Parameters:
diff - the amount of elapsed time.
Returns:
the formatte String.

iteratorAsList

public static java.util.List iteratorAsList(java.util.Iterator i)
Build a List of all elements in an Iterator.


reverseListIterator

public static java.util.Iterator reverseListIterator(java.util.ListIterator i)
Creates an Iterator that is the reverse of a ListIterator.