info.javelot.functionalj.util
Class Utils

java.lang.Object
  extended by info.javelot.functionalj.util.Utils

public final class Utils
extends Object

Contains general utility methods.

Author:
Copyright © 2006 Frederic Daoud

Method Summary
static void disallowNull(Object p_parameter, String p_name)
          Verifies if the parameter is null, and throws an exception if it is.
static int getInt(Object p_object)
          Returns an int from an Object, using the numerical value of its String representation.
static int safeCompare(Comparable p_first, Comparable p_second)
          Returns the result of comparing two objects, by considering two null values to be equal, a null to come after a non-null value, and by using the compareTo() method to compare two non-null values.
static boolean safeEqualArrays(Object[] p_first, Object[] p_second)
          Verifies if two arrays of objects are equal, considering null values to be equal, and comparing corresponding elements of each array.
static boolean safeEquals(Object p_first, Object p_second)
          Verifies if two objects are equal, by considering two null values to be equal, a null and non-null value not to be equal, and by using the equals() method to compare two non-null values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

disallowNull

public static void disallowNull(Object p_parameter,
                                String p_name)
                         throws FunctionException
Verifies if the parameter is null, and throws an exception if it is. Does nothing if the parameter is not null.

Parameters:
p_parameter - the parameter that is checked for null.
p_name - the name of the parameter. This name will be displayed as part of the message of the FunctionException, if thrown, as follows: "The {name} parameter cannot be null."
Throws:
FunctionException - thrown if the parameter is null.

safeEquals

public static boolean safeEquals(Object p_first,
                                 Object p_second)
Verifies if two objects are equal, by considering two null values to be equal, a null and non-null value not to be equal, and by using the equals() method to compare two non-null values.

Parameters:
p_first - the first object to consider for equality.
p_second - the second object to consider for equality.
Returns:
true if the two objects are considered equal, false otherwise.

safeEqualArrays

public static boolean safeEqualArrays(Object[] p_first,
                                      Object[] p_second)
Verifies if two arrays of objects are equal, considering null values to be equal, and comparing corresponding elements of each array.

Parameters:
p_first - the first array to consider for equality.
p_second - the second array to consider for equality.
Returns:
true if the two arrays are considered equal, false otherwise.

safeCompare

public static int safeCompare(Comparable p_first,
                              Comparable p_second)
Returns the result of comparing two objects, by considering two null values to be equal, a null to come after a non-null value, and by using the compareTo() method to compare two non-null values.

Parameters:
p_first - the first object to consider for comparison.
p_second - the second object to consider for comparison.
Returns:
-1 if the first object should come before the second, 1 if it is vice versa, and 0 if the two objects are considered equal.

getInt

public static int getInt(Object p_object)
Returns an int from an Object, using the numerical value of its String representation.

Parameters:
p_object - the object to be converted to an int.
Returns:
the int value of the Object.
Throws:
NumberFormatException - thrown if the Object's String representation is not a valid integer value.