package flare.util {
/**
* Utility class for sorting and creating sorting functions. This class
* provides a static $() method for creating sorting
* comparison functions from sort criteria. Instances of this class can be
* used to encapsulate a set of sort criteria and retrieve a corresponding
* sorting function.
*
*
Sort criteria are generally expressed as an array of property names
* to sort on. These properties are accessed by sorting functions using the
* Property class. Sort criteria are expressed as an
* array of property names to sort on. These properties are accessed
* by sorting functions using the Property class.
* The default is to sort in ascending order. If the field name
* includes a "-" (negative sign) prefix, that variable will instead
* be sorted in descending order.
*
*/
public class Sort {
/** Prefix indicating an ascending sort order. */
public static const ASC : Number = '+'.charCodeAt(0);
/** Prefix indicating a descending sort order. */
public static const DSC : Number = '-'.charCodeAt(0);
private var _comp : Function;
private var _crit : Array;
/** Gets the sorting comparison function for this Sort instance. */
public function get comparator() : Function {
return _comp;
}
/** The sorting criteria. Sort criteria are expressed as an
* array of property names to sort on. These properties are accessed
* by sorting functions using the Property class.
* The default is to sort in ascending order. If the field name
* includes a "-" (negative sign) prefix, that variable will instead
* be sorted in descending order. */
public function get criteria() : Array {
return Arrays.copy(_crit);
}
public function set criteria(crit : *) : void {
if (crit is String) {
_crit = [crit];
} else if (crit is Array) {
_crit = crit;
} else if (crit is Vector.