- 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>
ACompareOperator
represents an operator able tocompare
two given values.
-
-
Enum Constant Summary
Enum Constants Enum Constant Description EQUAL
CompareOperator
to check if objects areequal
.GREATER_OR_EQUAL
CompareOperator
to check if some value is greater or equal to another.GREATER_THAN
CompareOperator
to check if some value is greater than another.LESS_OR_EQUAL
CompareOperator
to check if some value is less or equal than another.LESS_THAN
CompareOperator
to check if some value is less than another.NOT_EQUAL
CompareOperator
to 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 thisCompareOperator
for the givenComparable
arguments.abstract boolean
evalDelta(int delta)
boolean
evalDouble(double arg1, double arg2)
This method evaluates thisCompareOperator
for the given arguments.boolean
evalNumber(Number arg1, Number arg2)
This method evaluates thisCompareOperator
for the givenNumber
arguments.boolean
evalObject(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 isnull
it will returnevalDelta
(Integer.MIN_VALUE
). If both arguments areNumber
s it delegates toevalNumber(Number, Number)
If both arguments areComparable
s: If bothComparable
s have different types but each of them is a standardTemporal
orDate
/Calendar
, then one of them is converted to the other.String
getSymbol()
abstract CompareOperator
negate()
static CompareOperator
ofSymbol(String value)
This method gets theCompareOperator
for the givensymbol
.String
toString()
static CompareOperator
valueOf(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
CompareOperator
to check if some value is greater than another.
-
GREATER_OR_EQUAL
public static final CompareOperator GREATER_OR_EQUAL
CompareOperator
to check if some value is greater or equal to another.
-
LESS_THAN
public static final CompareOperator LESS_THAN
CompareOperator
to check if some value is less than another.
-
LESS_OR_EQUAL
public static final CompareOperator LESS_OR_EQUAL
CompareOperator
to check if some value is less or equal than another.
-
EQUAL
public static final CompareOperator EQUAL
CompareOperator
to check if objects areequal
.
-
NOT_EQUAL
public static final CompareOperator NOT_EQUAL
CompareOperator
to 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
CompareOperator
thatevaluates
to the negated result.
-
evalDelta
public abstract boolean evalDelta(int delta)
- Parameters:
delta
- the signum ofComparable.compareTo(Object)
orInteger.MIN_VALUE
if the arguments are incompatible (e.g. exactly one isnull
orString
compared withBoolean
).- Returns:
- the result of the
CompareOperator
for the givendelta
.
-
evalDouble
public boolean evalDouble(double arg1, double arg2)
This method evaluates thisCompareOperator
for the given arguments.- Parameters:
arg1
- is the first argument.arg2
- is the second argument.- Returns:
- the result of the
CompareOperator
applied to the given arguments.
-
evalComparable
public <T extends Comparable<T>> boolean evalComparable(T arg1, T arg2)
This method evaluates thisCompareOperator
for the givenComparable
arguments.- Type Parameters:
T
- type of theComparable
objects.- Parameters:
arg1
- is the first argument.arg2
- is the second argument.- Returns:
- the result of the
CompareOperator
applied 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
null
it will returnevalDelta
(Integer.MIN_VALUE
). - If both arguments are
Number
s it delegates toevalNumber(Number, Number)
- If both arguments are
Comparable
s:- If both
Comparable
s have different types but each of them is a standardTemporal
orDate
/Calendar
, then one of them is converted to the other. Please note that some combinations are still invalid so e.g.LocalDate
andLocalTime
are not comparable. - If we now have two
Comparable
s 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
CompareOperator
applied to the given arguments.
- If both arguments are same it will return
-
evalNumber
public boolean evalNumber(Number arg1, Number arg2)
This method evaluates thisCompareOperator
for the givenNumber
arguments.- Parameters:
arg1
- is the first argument.arg2
- is the second argument.- Returns:
- the result of the
CompareOperator
applied to the given arguments. - See Also:
evalObject(Object, Object)
-
toString
public String toString()
- Overrides:
toString
in classEnum<CompareOperator>
-
ofSymbol
public static CompareOperator ofSymbol(String value)
This method gets theCompareOperator
for the givensymbol
.- Parameters:
value
- is thesymbol
of the requestedCompareOperator
.- Returns:
- the requested
CompareOperator
ornull
if no suchCompareOperator
exists.
-
-