net.sf.mmm.util.lang.api
Enum Comparator

java.lang.Object
  extended by java.lang.Enum<Comparator>
      extended by net.sf.mmm.util.lang.api.Comparator
All Implemented Interfaces:
Serializable, Comparable<Comparator>, Datatype<String>

public enum Comparator
extends Enum<Comparator>
implements Datatype<String>

A Comparator represents a function that compares two given values.

Since:
2.0.0
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)

Enum Constant Summary
EQUAL
          Comparator to check if objects are equal.
GREATER_OR_EQUAL
          Comparator to check if some value is greater or equal to another.
GREATER_THAN
          Comparator to check if some value is greater than another.
LESS_OR_EQUAL
          Comparator to check if some value is less or equal than another.
LESS_THAN
          Comparator to check if some value is less than another.
NOT_EQUAL
          Comparator to check if objects are NOT equal.
 
Field Summary
private  boolean evalTrueIfEquals
           
private  Boolean less
           
private  String title
           
private  String value
           
 
Method Summary
private  Object convert(Object object, Class<?> otherType)
          This method converts the given value to a more common type.
abstract  boolean eval(double arg1, double arg2)
          This method evaluates this Comparator for the given arguments.
 boolean eval(Object arg1, Object arg2)
          This method evaluates this Comparator for the given arguments.
private  boolean evalComparable(Comparable arg1, Comparable arg2)
          This method handles eval(Object, Object) for two Comparables.
static Comparator fromValue(String value)
          This method gets the Comparator for the given symbol.
 String getTitle()
          This method gets the title of this datatype.
 String getValue()
          This method gets the symbol of the Comparator.
 String toString()
          This method needs to return the same result a Datatype.getTitle().
static Comparator valueOf(String name)
          Returns the enum constant of this type with the specified name.
static Comparator[] values()
          Returns an array containing the constants of this enum type, in the order they are declared.
 
Methods inherited from class java.lang.Enum
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, valueOf
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Enum Constant Detail

GREATER_THAN

public static final Comparator GREATER_THAN
Comparator to check if some value is greater than another.


GREATER_OR_EQUAL

public static final Comparator GREATER_OR_EQUAL
Comparator to check if some value is greater or equal to another.


LESS_THAN

public static final Comparator LESS_THAN
Comparator to check if some value is less than another.


LESS_OR_EQUAL

public static final Comparator LESS_OR_EQUAL
Comparator to check if some value is less or equal than another.


EQUAL

public static final Comparator EQUAL
Comparator to check if objects are equal.


NOT_EQUAL

public static final Comparator NOT_EQUAL
Comparator to check if objects are NOT equal.

Field Detail

value

private final String value
See Also:
getValue()

title

private final String title
See Also:
getTitle()

evalTrueIfEquals

private final boolean evalTrueIfEquals
See Also:
eval(Object, Object)

less

private final Boolean less
See Also:
evalComparable(Comparable, Comparable)
Method Detail

values

public static Comparator[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
for (Comparator c : Comparator.values())
    System.out.println(c);

Returns:
an array containing the constants of this enum type, in the order they are declared

valueOf

public static Comparator valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)

Parameters:
name - the name of the enum constant to be returned.
Returns:
the enum constant with the specified name
Throws:
IllegalArgumentException - if this enum type has no constant with the specified name
NullPointerException - if the argument is null

getValue

public String getValue()
This method gets the symbol of the Comparator. E.g. "==", ">", ">=", etc.

Specified by:
getValue in interface Datatype<String>
Returns:
the comparator symbol.

getTitle

public String getTitle()
This method gets the title of this datatype. The title is a string representation intended to be displayed to end-users (i18n will be done externally - see NlsMessage).
Since the general contract of Datatype.toString() is quite weak, this method is added to explicitly express the presence of the title and to ensure implementors of this interface can NOT miss to implement this.

Specified by:
getTitle in interface Datatype<String>
Returns:
the display title of this datatype.
See Also:
Datatype.toString()

eval

public abstract boolean eval(double arg1,
                             double arg2)
This method evaluates this Comparator for the given arguments.

Parameters:
arg1 - is the first argument.
arg2 - is the second argument.
Returns:
the result of the Comparator applied to the given arguments.

convert

private Object convert(Object object,
                       Class<?> otherType)
This method converts the given value to a more common type. E.g. instances of Calendar or XMLGregorianCalendar will be converted to Date.

Parameters:
object - is the value to convert.
otherType - the type of the value to compare that differs from the type
Returns:
a simpler representation of value or the same value if on simpler type is known.

evalComparable

private boolean evalComparable(Comparable arg1,
                               Comparable arg2)
This method handles eval(Object, Object) for two Comparables.

Parameters:
arg1 - is the first argument.
arg2 - is the second argument.
Returns:
the result of the Comparator applied to the given arguments.

eval

public boolean eval(Object arg1,
                    Object arg2)
This method evaluates this Comparator for the given arguments.

Parameters:
arg1 - is the first argument.
arg2 - is the second argument.
Returns:
the result of the Comparator applied to the given arguments.

toString

public String toString()
This method needs to return the same result a Datatype.getTitle().

Specified by:
toString in interface Datatype<String>
Overrides:
toString in class Enum<Comparator>
Returns:
the display title of this datatype.

fromValue

public static Comparator fromValue(String value)
This method gets the Comparator for the given symbol.

Parameters:
value - is the symbol of the requested Comparator.
Returns:
the requested Comparator or null if no such Comparator exists.


Copyright © 2001-2010 mmm-Team. All Rights Reserved.