Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

burst.Comparator Class Reference

List of all members.

Detailed Description

Class representing a comparator function for a particular object type and behavior.

Each instance has either or both of a convert and a compare function. The convert function, if any, is called on each Array item exactly once prior to sorting, as preprocessing. The compare is used to compare two values (the return values of convert, if any). If no compare is defined, then the native sort comparator is used (presumably lexical String compare).

The convert may return undefined, null, or NaN to indicate something that cannot be parsed. The compare function need not test for those cases; it will not be given them.

The convert may assume that its input is a (non-null) String and is already left trimmed (via burst.Text.ltrim).

Note that the Array.sort comparator in ECMAScript is like Java and C, in that it returns a number less than, equal to, or greater than zero (like a - b). This differs from the C++ STL, which uses a boolean less function in its sort template.

The predefined comparators are these:

string:cs
case-sensitive String
string:cis
case-insensitive String
date:native
any String that Date.parse understands
integer:10
calls parseInt(v,10)
float
calls parseFloat(v)


Public Member Functions

 Comparator (String name, Function convert, Function compare)
 The constructor.


Static Public Member Functions

 getComparator (String name, Boolean missing_ok)
 Get an burst.Comparator instance by name.

Number stringCompare (String a, String b)
 An implementation of what (we believe) the native Array.sort does for String comparison when the sort function is not provided.


Constructor & Destructor Documentation

burst.Comparator.Comparator String  name,
Function  convert,
Function  compare
 

The constructor.

It automatically registers the instance using the name.

Parameters:
name Globally unique name.
convert Optional preprocessing function.
compare Comparison function to use if other than case-sensitive String compare.


Member Function Documentation

burst.Comparator.getComparator String  name,
Boolean  missing_ok
[static]
 

Get an burst.Comparator instance by name.

Parameters:
name The name of the comparator.
missing_ok optional. If true, and none exists, return null. Otherwise an error is thrown.


The documentation for this class was generated from the following file:
Generated on Tue Nov 30 04:03:08 2004 for BurstProject by doxygen 1.3.4