Home | Trees | Index | Help |
|
---|
Package Modeling :: Module SortOrdering |
|
Module SortOrdering holds a "command" pattern for sorting objects, and the appropriate methods for building and using the commands.
A command for sorting is an instance of L{SortOrdering}; it can be built either directly or with the method L{sortOrderingsWithString}. A command can be used alone or inserted in a sequence of sorting command; in the later case, the resulting sorting method simply consists in sorting objects with the first method in the sequence, than sorting the objects which are equal wrt the first method using the second one in the sequence, etc.
A command consists in a key and an operator (see below: L{compareAscending}, ...); the sorting mechanism uses L{KeyValueCoding.valueForKeyPath<KeyValueCoding.KeyValueCoding.valueForKeyPath>} with the command's key to access the values for objects' attributes.
Sorted objects must implement the KeyValueCoding interface's method L{KeyValueCoding.valueForKeyPath<KeyValueCoding.KeyValueCoding.valueForKeyPath>}): it is used to access objects' values.
Example of use:
>>> from Modeling.SortOrdering import sortOrderingsWithString, sortedArrayUsingKeyOrderArray >>> name_age=sortOrderingsWithString('lastName, age desc') >>> sortedArrayUsingKeyOrderArray(self.authors, name_age)
CVS Information: $Id: SortOrdering.py,v 1.8 2004/07/20 06:21:37 sbigaret Exp $
Classes | |
---|---|
SortOrdering |
The canonical sorting command has a key and an operator. |
Function Summary | |
---|---|
This operator allows to sort values in ascending order | |
This operator allows to sort strings in ascending order, case-insensitively | |
This operator allows to sort strings in descending order, case-insensitively | |
This operator allows to sort values in descending order | |
Converts a string to the corresponding operator. | |
Sorts array with respect to the list of sort commands supplied in sortOrderings. | |
Builds a sequence of SortOrdering from the supplied string. | |
Alternate constructor for a L{SortOrdering} |
Function Details |
---|
compareAscending(value1, value2)This operator allows to sort values in ascending order |
compareCaseInsensitiveAscending(value1, value2)This operator allows to sort strings in ascending order, case-insensitively |
compareCaseInsensitiveDescending(value1, value2)This operator allows to sort strings in descending order, case-insensitively |
compareDescending(value1, value2)This operator allows to sort values in descending order |
operatorFromString(str)Converts a string to the corresponding operator. Recognized strings are: 'asc', 'desc' and their case-insensitive counterparts: 'iasc' and 'idesc' |
sortedArrayUsingKeyOrderArray(array, sortOrderings)Sorts array with respect to the list of sort commands supplied in sortOrderings. Object's values are accessed using L{SortOrdering}.key and L{KeyValueCoding.valueForKeyPath}.
@parameter sortOrderings: a sequence of L{SortOrdering} commands. @return: the sorted array |
sortOrderingsWithString(str)Builds a sequence of SortOrdering from the supplied string. A valid string is: C{<key1> [<operator1>], ..., <key_n> [<operator_n>]} Valid operators are the one accepted by L{operatorFromString}. When C{<operator>} is omitted, it defaults to C{'asc'}. Example of a valid string: C{"name, age desc"} meaning; sort by name (ascending), then by age (descending). |
sortOrderingWithKey(key, operator)Alternate constructor for a L{SortOrdering} |
Home | Trees | Index | Help |
|
---|
Generated by Epydoc 2.1 on Sat Mar 4 13:36:24 2006 | http://epydoc.sf.net |