|
WebObjects 5.2 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.webobjects.eocontrol.EOSortOrdering
An EOSortOrdering object specifies the way that a group of objects should be sorted, using a property key and a method selector for comparing values of that property. EOSortOrderings are used both to generate SQL when fetching rows from a database server, and to sort objects in memory. EOFetchSpecification objects use an array of EOSortOrderings, which are applied in series to perform sorts by more than one property.
Defined Name | SQL Expression |
CompareAscending | (key) asc |
CompareDescending | (key) desc |
CompareCaseInsensitiveAscending | upper(key) asc |
CompareCaseInsensitiveDescending | upper(key) desc |
Using the mapping in the table above, the array of EOSortOrderings (nameOrdering) created in the following code example:
EOSortOrdering lastNameOrdering =
EOSortOrdering.sortOrderingWithKey("lastName", EOSortOrdering.CompareAscending);
EOSortOrdering firstNameOrdering =
(EOSortOrdering.sortOrderingWithKey("firstName", EOSortOrdering.CompareAscending);
NSMutableArray nameOrdering = new NSMutableArray();
nameOrdering.addObject(lastNameOrdering);
nameOrdering.addObject(firstNameOrdering);
results in this ORDER BY clause:
order by (lastName) asc, (firstName) asc
The methods sortedArrayUsingKeyOrderArray
and
sortArrayUsingKeyOrderArray
are used to sort objects
in memory. Given an array of objects and an array of EOSortOrderings,
sortedArrayUsingKeyOrderArray
returns a new array of objects
sorted according to the specified EOSortOrderings. Similarly,
sortArrayUsingKeyOrderArray
sorts the provided array of objects
in place. This code fragment, for example, sorts an array of Employee objects
in place, by last name, then first name using the array of EOSortOrderings
created above:
EOSortOrdering.sortArrayUsingKeyOrderArray(employees, nameOrdering);
sortArrayUsingKeyOrderArray(com.webobjects.foundation.NSMutableArray, com.webobjects.foundation.NSArray)
,
sortedArrayUsingKeyOrderArray(com.webobjects.foundation.NSArray, com.webobjects.foundation.NSArray)
, Serialized FormInner Class Summary | |
static interface |
EOSortOrdering.Comparison
The Comparison interface defines methods for comparing values. |
static class |
EOSortOrdering.ComparisonSupport
ComparisonSupport provides default implementations of the EOSortOrdering.Comparison interface and a registry for support objects. |
Inner classes inherited from class com.webobjects.foundation.NSCoding |
NSCoding.Support |
Inner classes inherited from class com.webobjects.eocontrol.EOKeyValueArchiving |
EOKeyValueArchiving.Awaking, EOKeyValueArchiving.FinishInitialization, EOKeyValueArchiving.Support |
Field Summary | |
static NSSelector |
CompareAscending
|
static NSSelector |
CompareCaseInsensitiveAscending
|
static NSSelector |
CompareCaseInsensitiveDescending
|
static NSSelector |
CompareDescending
|
Constructor Summary | |
EOSortOrdering(String key,
NSSelector selector)
Creates a new EOSortOrdering object. |
Method Summary | |
Class |
classForCoder()
Conformance to NSCoding. |
static Object |
decodeObject(NSCoder coder)
Conformance to NSCoding. |
static Object |
decodeWithKeyValueUnarchiver(EOKeyValueUnarchiver unarchiver)
Conformance to EOKeyValueArchiving. |
void |
encodeWithCoder(NSCoder coder)
Conformance to NSCoding. |
void |
encodeWithKeyValueArchiver(EOKeyValueArchiver archiver)
Conformance to EOKeyValueArchiving. |
String |
key()
Returns the key by which the receiver orders items. |
NSSelector |
selector()
Returns the method selector used to compare values when sorting. |
static void |
sortArrayUsingKeyOrderArray(NSMutableArray array,
NSArray sortOrderings)
Sorts objects in array in place according to the
EOSortOrderings in sortOrderings . |
static NSArray |
sortedArrayUsingKeyOrderArray(NSArray array,
NSArray sortOrderings)
Creates and returns a new array by sorting objects according to the EOSortOrderings in sortOrderings . |
static EOSortOrdering |
sortOrderingWithKey(String key,
NSSelector selector)
Creates an EOSortOrdering based on key and selector. |
String |
toString()
Returns a description of the receiver. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final NSSelector CompareAscending
public static final NSSelector CompareCaseInsensitiveAscending
public static final NSSelector CompareCaseInsensitiveDescending
public static final NSSelector CompareDescending
Constructor Detail |
public EOSortOrdering(String key, NSSelector selector)
key
- property key to sort objects byselector
- selector to use when comparing values for key in objectssortOrderingWithKey(java.lang.String, com.webobjects.foundation.NSSelector)
Method Detail |
public Class classForCoder()
classForCoder
in interface NSCoding
NSCoding.classForCoder()
public static Object decodeObject(NSCoder coder)
coder
- the NSCoder object used to create a new EOSortOrdering fromcoder
public static Object decodeWithKeyValueUnarchiver(EOKeyValueUnarchiver unarchiver)
unarchiver
- the EOKeyValueUnarchiver object that contains the state of the object to be decodedunarchiver
EOKeyValueArchiver
public void encodeWithCoder(NSCoder coder)
encodeWithCoder
in interface NSCoding
coder
- the NSCoder that will be the destination for class type and object information encoded by the receiverpublic void encodeWithKeyValueArchiver(EOKeyValueArchiver archiver)
encodeWithKeyValueArchiver
in interface EOKeyValueArchiving
archiver
- the EOKeyValueArchiver object to encode the receiver's state intoEOKeyValueArchiver
public String key()
selector()
public NSSelector selector()
key()
public static void sortArrayUsingKeyOrderArray(NSMutableArray array, NSArray sortOrderings)
array
in place according to the
EOSortOrderings in sortOrderings
.
The objects are compared by extracting the sort properties using
the NSKeyValueCoding method valueForKey
and sending them
compare...
messages. See the table in
"Sorting with SQL" for a list of the compare methods.array
- array of objects to sortsortOrderings
- an array of sort orderings to use to sort array
bysortedArrayUsingKeyOrderArray(com.webobjects.foundation.NSArray, com.webobjects.foundation.NSArray)
public static EOSortOrdering sortOrderingWithKey(String key, NSSelector selector)
key
- property key to sort objects byselector
- selector to use when comparing values for key
in objectskey
and selector
public static NSArray sortedArrayUsingKeyOrderArray(NSArray array, NSArray sortOrderings)
sortOrderings
. The objects are compared by
extracting the sort properties using the added EOKeyValueCoding
method valueForKey
and sending them compare...
messages.
See the table in "Sorting with SQL" for a list of the compare methods.array
- array of objects to sortsortOrderings
- array of EOSortOrderings to sort objects in array
byarray
sorted according to sortOrderings
sortArrayUsingKeyOrderArray(com.webobjects.foundation.NSMutableArray, com.webobjects.foundation.NSArray)
public String toString()
toString
in class Object
|
Last updated Fri Feb 21 13:15:00 PST 2003. | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |