-
public interface TokenComparator
An object for comparing tokens of compatible types. While the interface is generically typed, usingTokenValued
, implementations are type specific, working on only tokens of one type (or, in the case of the number types, any number type).- See Also:
TokenComparators
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description int
compare()
Indicates the relative ordering of two token values.boolean
equal()
Indicates whether the currently bound values are equal.TokenOrder
getDirection()
Gets the direction of the comparator's ordering.TokenType
getType()
Gets the type of tokens for which the comparator is valid.void
setLeftSource(TokenValued source)
Binds the left-hand value of the comparator to the specified object.void
setRightSource(TokenValued source)
Binds the right-hand value of the comparator to the specified object.
-
-
-
Method Detail
-
getType
TokenType getType()
Gets the type of tokens for which the comparator is valid.- Returns:
- the valid token type for the comparator
-
getDirection
TokenOrder getDirection()
Gets the direction of the comparator's ordering.- Returns:
- the ordering direction
-
setLeftSource
void setLeftSource(TokenValued source)
Binds the left-hand value of the comparator to the specified object. Comparisons will be done using the value of the object at the time of the comparison.- Parameters:
source
- the value container to use on the left side of comparisons
-
setRightSource
void setRightSource(TokenValued source)
Binds the right-hand value of the comparator to the specified object. Comparisons will be done using the value of the object at the time of the comparison.- Parameters:
source
- the value container to use on the right side of comparisons
-
equal
boolean equal()
Indicates whether the currently bound values are equal. Two values are equal if and only if the following are true:- neither value is null valued
- the contained values are equal (according to the rules of the underlying type)
- Returns:
true
if the bound values are equal,false
otherwise.
-
compare
int compare()
Indicates the relative ordering of two token values. The ordering is interpreted under the direction associated with the comparator. Thus a descending comparator would place"banana"
before"apple"
, an inversion of the natural (ascending) ordering.Null valued tokens always compare equal under this method. Note that this disagrees with the behavior of
equal()
.- Returns:
- a negative integer, zero, or a positive integer if the bound value for the left is respectively before, equivalent to, or after the bound value for the right.
-
-