A utility for performing a "lazy" chained comparison statement, which
performs comparisons only until it finds a nonzero result. For example:
The value of this expression will have the same sign as the
first
nonzero comparison result in the chain, or will be zero if every
comparison result was zero.
Once any comparison returns a nonzero value, remaining comparisons are
"short-circuited".
Example
public function compareTo (that :Object) :int
{
return ComparisonChain.start()
.compareStrings(this.aString, that.aString)
.compareInts(this.anInt, that.anInt)
.compareComparables(this.anEnum, that.anEnum)
.result();
}
public function compare(left:*, right:Function, comparator:* = null):ComparisonChain
Compares two Objects of any type, if the result of this comparison chain
has not already been determined. If a comparator is specified, that is used, otherwise
it tries to suss-out the types of the arguments and compares them that way.
Parameters
| left:* |
|
| right:Function |
|
| comparator:* (default = null )
|
Returns
public function compareBooleans(left:Boolean, right:Boolean):ComparisonChain
Compares two Booleans, if the result of this comparison chain
has not already been determined.
Parameters
| left:Boolean |
|
| right:Boolean |
Returns
public function compareComparables(left:Comparable, right:Comparable):ComparisonChain
Compares two comparable objects, if the result of this comparison chain
has not already been determined.
Parameters
Returns
public function compareInts(left:int, right:int):ComparisonChain
Compares two ints, if the result of this comparison chain
has not already been determined.
Parameters
Returns
public function compareNumbers(left:Number, right:Number):ComparisonChain
Compares two Numbers, if the result of this comparison chain
has not already been determined.
Parameters
Returns
public function compareStrings(left:String, right:String):ComparisonChain
Compares two Strings, if the result of this comparison chain
has not already been determined.
Parameters
Returns
public function compareStringsIgnoreCase(left:String, right:String):ComparisonChain
Compares two strings, ignoring case, if the result of this comparison chain
has not already been determined.
Parameters
Returns
public function result():int
Ends this ComparisonChain and returns its reuslt.
Returns
public static function start():ComparisonChain
Start a ComparisonChain.
Returns
protected static const ACTIVE:ComparisonChain
Copyright © 2007-2009 Three Rings Design, Inc.