- java.lang.Object
-
- java.lang.Enum<CompareOperator>
-
- io.github.mmm.base.compare.CompareOperator
-
- All Implemented Interfaces:
Serializable,Comparable<CompareOperator>
public enum CompareOperator extends Enum<CompareOperator>
ACompareOperatorrepresents an operator able tocomparetwo given values.
-
-
Enum Constant Summary
Enum Constants Enum Constant Description EQUALCompareOperatorto check if objects areequal.GREATER_OR_EQUALCompareOperatorto check if some value is greater or equal to another.GREATER_THANCompareOperatorto check if some value is greater than another.LESS_OR_EQUALCompareOperatorto check if some value is less or equal than another.LESS_THANCompareOperatorto check if some value is less than another.NOT_EQUALCompareOperatorto check if objects are NOTequal.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description <T extends Comparable<T>>
booleanevalComparable(T arg1, T arg2)This method evaluates thisCompareOperatorfor the givenComparablearguments.abstract booleanevalDelta(int delta)booleanevalDouble(double arg1, double arg2)This method evaluates thisCompareOperatorfor the given arguments.booleanevalNumber(Number arg1, Number arg2)This method evaluates thisCompareOperatorfor the givenNumberarguments.booleanevalObject(Object arg1, Object arg2)Generic variant ofevalComparable(Comparable, Comparable)that tries to convert incompatible arguments: If both arguments are same it will returnevalDelta(0). If only exactly one of the arguments isnullit will returnevalDelta(Integer.MIN_VALUE). If both arguments areNumbers it delegates toevalNumber(Number, Number)If both arguments areComparables: If bothComparables have different types but each of them is a standardTemporalorDate/Calendar, then one of them is converted to the other.StringgetSymbol()abstract CompareOperatornegate()static CompareOperatorofSymbol(String value)This method gets theCompareOperatorfor the givensymbol.StringtoString()static CompareOperatorvalueOf(String name)Returns the enum constant of this type with the specified name.static CompareOperator[]values()Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
GREATER_THAN
public static final CompareOperator GREATER_THAN
CompareOperatorto check if some value is greater than another.
-
GREATER_OR_EQUAL
public static final CompareOperator GREATER_OR_EQUAL
CompareOperatorto check if some value is greater or equal to another.
-
LESS_THAN
public static final CompareOperator LESS_THAN
CompareOperatorto check if some value is less than another.
-
LESS_OR_EQUAL
public static final CompareOperator LESS_OR_EQUAL
CompareOperatorto check if some value is less or equal than another.
-
EQUAL
public static final CompareOperator EQUAL
CompareOperatorto check if objects areequal.
-
NOT_EQUAL
public static final CompareOperator NOT_EQUAL
CompareOperatorto check if objects are NOTequal.
-
-
Method Detail
-
values
public static CompareOperator[] 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 (CompareOperator c : CompareOperator.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static CompareOperator 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 nameNullPointerException- if the argument is null
-
getSymbol
public String getSymbol()
- Returns:
- the symbol of this
CompareOperator("==", ">", ">=", "<", or "<=")
-
negate
public abstract CompareOperator negate()
- Returns:
- the negation of this
CompareOperatorthatevaluatesto the negated result.
-
evalDelta
public abstract boolean evalDelta(int delta)
- Parameters:
delta- the signum ofComparable.compareTo(Object)orInteger.MIN_VALUEif the arguments are incompatible (e.g. exactly one isnullorStringcompared withBoolean).- Returns:
- the result of the
CompareOperatorfor the givendelta.
-
evalDouble
public boolean evalDouble(double arg1, double arg2)This method evaluates thisCompareOperatorfor the given arguments.- Parameters:
arg1- is the first argument.arg2- is the second argument.- Returns:
- the result of the
CompareOperatorapplied to the given arguments.
-
evalComparable
public <T extends Comparable<T>> boolean evalComparable(T arg1, T arg2)
This method evaluates thisCompareOperatorfor the givenComparablearguments.- Type Parameters:
T- type of theComparableobjects.- Parameters:
arg1- is the first argument.arg2- is the second argument.- Returns:
- the result of the
CompareOperatorapplied to the given arguments. - See Also:
evalObject(Object, Object)
-
evalObject
public boolean evalObject(Object arg1, Object arg2)
Generic variant ofevalComparable(Comparable, Comparable)that tries to convert incompatible arguments:- If both arguments are same it will return
evalDelta(0). - If only exactly one of the arguments is
nullit will returnevalDelta(Integer.MIN_VALUE). - If both arguments are
Numbers it delegates toevalNumber(Number, Number) - If both arguments are
Comparables:- If both
Comparables have different types but each of them is a standardTemporalorDate/Calendar, then one of them is converted to the other. Please note that some combinations are still invalid so e.g.LocalDateandLocalTimeare not comparable. - If we now have two
Comparables of the same type, we delegate toevalComparable(Comparable, Comparable).
- If both
- Parameters:
arg1- is the first argument.arg2- is the second argument.- Returns:
- the result of the
CompareOperatorapplied to the given arguments.
- If both arguments are same it will return
-
evalNumber
public boolean evalNumber(Number arg1, Number arg2)
This method evaluates thisCompareOperatorfor the givenNumberarguments.- Parameters:
arg1- is the first argument.arg2- is the second argument.- Returns:
- the result of the
CompareOperatorapplied to the given arguments. - See Also:
evalObject(Object, Object)
-
toString
public String toString()
- Overrides:
toStringin classEnum<CompareOperator>
-
ofSymbol
public static CompareOperator ofSymbol(String value)
This method gets theCompareOperatorfor the givensymbol.- Parameters:
value- is thesymbolof the requestedCompareOperator.- Returns:
- the requested
CompareOperatorornullif no suchCompareOperatorexists.
-
-