ncsa.tools.common.util
Class ComparisonUtils

java.lang.Object
  extended byncsa.tools.common.util.ComparisonUtils

public class ComparisonUtils
extends java.lang.Object

Wrapper static methods for doing arbitrary object comparisons. Also includes static method for matching filter against a map.

Author:
Albert L. Rossi

Method Summary
static boolean compare(java.lang.Object arg1, java.lang.Object arg2, int comparator, java.lang.Class cast)
          First attempts any primitive cast indicated.
static boolean compare(java.lang.Object arg1, java.lang.Object arg2, int type, int comparator)
          Compares a File to either another File, a Long or a String; checks the type parameter for the semantics of the comparison.
static java.lang.String getComparator(int comparatorValue)
           
static int getComparatorValue(java.lang.String s)
           
static boolean matches(ClassFilter filter, java.lang.Class clzz)
          Checks to see if the class of the type is assignable from the given class.
static boolean matches(MatchFilter filter, java.util.Map properties)
          Checks the match filter against the map of properties.
static boolean matches(MatchFilter filter, java.util.Map properties, boolean convertTypes)
          Checks the match filter against the map of properties.
static boolean matches(TypeFilter filter, java.lang.String type)
          Checks to see if the type strings are equal (case-insensitive).
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

compare

public static boolean compare(java.lang.Object arg1,
                              java.lang.Object arg2,
                              int type,
                              int comparator)
                       throws FailedComparisonException
Compares a File to either another File, a Long or a String; checks the type parameter for the semantics of the comparison.

Throws:
FailedComparisonException
See Also:
#applyFileComparator

compare

public static boolean compare(java.lang.Object arg1,
                              java.lang.Object arg2,
                              int comparator,
                              java.lang.Class cast)
                       throws FailedComparisonException
First attempts any primitive cast indicated. Then type-checks the two arguments. If both arguments are null, they are considered equal. If one of the two arguments is null, they are considered not equal (all other comparisons being invalid). According to the types of the args, the appropriate comparison is applied.

Parameters:
arg1 - to compare
arg2 - to compare to.
comparator - to use.
cast - class to cast to (for primitive conversion; can be null).
Returns:
result of the comparison.
Throws:
NCSAException - if types do not match.
FailedComparisonException

getComparatorValue

public static int getComparatorValue(java.lang.String s)
                              throws java.lang.IllegalArgumentException
Parameters:
s - string representation.
Returns:
comparator as an integer value.
Throws:
java.lang.IllegalArgumentException

getComparator

public static java.lang.String getComparator(int comparatorValue)
Parameters:
comparatorValue - int value.
Returns:
a normalized string representation of the comparator.

matches

public static boolean matches(ClassFilter filter,
                              java.lang.Class clzz)
Checks to see if the class of the type is assignable from the given class.

Parameters:
filter - to match.
clzz - to check against filter.
Returns:
if the filter is null, returns true; if clzz satisfies filter, returns true; else returns false.

matches

public static boolean matches(TypeFilter filter,
                              java.lang.String type)
Checks to see if the type strings are equal (case-insensitive).

Parameters:
filter - to match.
type - to check against filter.
Returns:
if the filter is null, returns true; if type satisfies filter, returns true; else returns false.

matches

public static boolean matches(MatchFilter filter,
                              java.util.Map properties)
                       throws FailedComparisonException
Checks the match filter against the map of properties.

Parameters:
filter - to match.
properties - map of properties against which to match.
Returns:
if the filter is null, returns true; if the filter is empty (no clauses), returns the negation of the filter's 'not' field; if property map satisfies filter, returns true; else returns false.
Throws:
FailedComparisonException

matches

public static boolean matches(MatchFilter filter,
                              java.util.Map properties,
                              boolean convertTypes)
                       throws FailedComparisonException
Checks the match filter against the map of properties.

Parameters:
filter - to match.
properties - map of properties against which to match.
convertTypes - whether to try to flexibly convert the types to match String/numeric values
Returns:
if the filter is null, returns true; if the filter is empty (no clauses), returns the negation of the filter's 'not' field; if property map satisfies filter, returns true; else returns false.
Throws:
FailedComparisonException