compareTo
Determines the Order of this precedence with respect to other.
The result of x.compareTo(y)
may be Order.UNDETERMINED, in which case the order is determined by y.compareTo(x)
. If both of these are Order.UNDETERMINED, then the precedences are not ordered, which is valid.
This design supports extensibility. Old operators do not need to know about new operators; their precedence can (and should) compare as Order.UNDETERMINED to the precedence of operators they do not know about. This way, newly added operators can declare their precedence with respect to existing operators without having to change the code for existing operators.
This function should satisfy the following properties:
If
x.compareTo(y)
returns Order.LOWER, theny.compareTo(x)
must return Order.HIGHER or Order.UNDETERMINED.If
x.compareTo(y)
returns Order.HIGHER, theny.compareTo(x)
must return Order.LOWER or Order.UNDETERMINED.
However, this function is not required to be transitive or total. That is, not all operators are required to be ordered with respect to each other. This design facilitates modularity (see Parsing Mixfix Operators).
Note that two different objects implementing this interface can never denote the same precedence since Order does not have an EQUAL
option. If two operators have the same precedence, then Operator.precedence must return the same object for both.