Packagecom.threerings.util
Classpublic class ComparisonChain

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 Methods
 MethodDefined by
  
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.
ComparisonChain
  
compareBooleans(left:Boolean, right:Boolean):ComparisonChain
Compares two Booleans, if the result of this comparison chain has not already been determined.
ComparisonChain
  
Compares two comparable objects, if the result of this comparison chain has not already been determined.
ComparisonChain
  
compareInts(left:int, right:int):ComparisonChain
Compares two ints, if the result of this comparison chain has not already been determined.
ComparisonChain
  
compareNumbers(left:Number, right:Number):ComparisonChain
Compares two Numbers, if the result of this comparison chain has not already been determined.
ComparisonChain
  
compareStrings(left:String, right:String):ComparisonChain
Compares two Strings, if the result of this comparison chain has not already been determined.
ComparisonChain
  
compareStringsIgnoreCase(left:String, right:String):ComparisonChain
Compares two strings, ignoring case, if the result of this comparison chain has not already been determined.
ComparisonChain
  
result():int
Ends this ComparisonChain and returns its reuslt.
ComparisonChain
  
[static] Start a ComparisonChain.
ComparisonChain
Protected Constants
 ConstantDefined by
  ACTIVE : ComparisonChain
[static]
ComparisonChain
Method detail
compare()method
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
ComparisonChain
compareBooleans()method 
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
ComparisonChain
compareComparables()method 
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
left:Comparable
 
right:Comparable

Returns
ComparisonChain
compareInts()method 
public function compareInts(left:int, right:int):ComparisonChain

Compares two ints, if the result of this comparison chain has not already been determined.

Parameters
left:int
 
right:int

Returns
ComparisonChain
compareNumbers()method 
public function compareNumbers(left:Number, right:Number):ComparisonChain

Compares two Numbers, if the result of this comparison chain has not already been determined.

Parameters
left:Number
 
right:Number

Returns
ComparisonChain
compareStrings()method 
public function compareStrings(left:String, right:String):ComparisonChain

Compares two Strings, if the result of this comparison chain has not already been determined.

Parameters
left:String
 
right:String

Returns
ComparisonChain
compareStringsIgnoreCase()method 
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
left:String
 
right:String

Returns
ComparisonChain
result()method 
public function result():int

Ends this ComparisonChain and returns its reuslt.

Returns
int
start()method 
public static function start():ComparisonChain

Start a ComparisonChain.

Returns
ComparisonChain
Constant detail
ACTIVEconstant
protected static const ACTIVE:ComparisonChain