PHP version: 5
Required modules:
standard
Required packages:
autoload.php, AutoloadException.php, Comparable.php, CastException.php
interface it\icosaedro\containers\Sortable
|
`--(it\icosaedro\containers\Comparable)
Objects that provide this interface can be sorted
Version: $Date: 2012/02/09 10:11:26 $
Author: Umberto Salsi <salsi@icosaedro.it>
{
int compareTo(
object $other)Compare this object with another object
The two objects (this and the other) MUST be comparable because the client algorithm expects they are sortable, so an exception MUST be thown if the two object cannot be compared because they belong to different classes. Note that a test like "$other instanceof __CLASS__" is not sufficient because $other might be an extended class; extended classes should override the Sortable interface, and all the objects must belong to this new class. To summarize, the recommended implementation follows:
function compareTo($other) { if( $other === NULL ) throw new CastException("NULL"); if( get_class($other) !== __CLASS__ ) throw new CastException("expected " . __CLASS__ . " but got " . get_class($other)); $other2 = cast(__CLASS__, $other); ...here, comparison specific of this class... return result_of_the_comparison; }Parameters:
$otherThe other object. Return: Negative, zero or positive if $this is less, equal or greater than $other respectively.
Throws:
- unchecked
CastExceptionIf the other object belongs to a different class and cannot be compared with this.boolean equals(
object $other)
inherited fromit\icosaedro\containers\Comparable
}
Generated by PHPLint Documentator