Interface Comparable
Defines a method that a class implements to provide natural order of sorting to instances.
This interface imposes a total ordering on the objects of each class
that implements it. This ordering is referred to as the natural ordering
of the class, and the method PhpCommon\Comparison\Comparable::compareTo()
is referred to as its
natural comparison method.
The natural ordering for a class C
is said to be consistent with
PhpCommon\Comparison\Equatable::equals() if and only if
$a->compareTo($b) === 0
has the same boolean value as $a->equals($b)
for
every $a
and $b
of class C
.
It is strongly recommended (though not required) that natural orderings
be consistent with PhpCommon\Comparison\Equatable::equals(). This is
so because in certain cases these methods can be used together in a
complementary way to achieve specific results. For example, some structures,
such as sets and maps, may use the methods PhpCommon\Comparison\Equatable::equals() and PhpCommon\Comparison\Comparable::compareTo()
as part
of the strategy to determine where to store or retrieve data. In that way,
such inconsistency may lead to unwanted results.
It is inspired by the Comparable
interface, from Java API.
Author: Marcos Passos marcos@croct.com
Link: Java Comparable interface
Located at Comparable.php
public
boolean
|
#
compareTo(
Compares the current object with another for order. |