|
WebObjects 5.4.2 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.webobjects.eocontrol.EOSortOrdering
public class 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);
EOSortOrdering.sortArrayUsingKeyOrderArray(com.webobjects.foundation.NSMutableArray, com.webobjects.foundation.NSArray),
EOSortOrdering.sortedArrayUsingKeyOrderArray(com.webobjects.foundation.NSArray, com.webobjects.foundation.NSArray),
Serialized Form| Nested 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. |
| Nested classes/interfaces inherited from interface com.webobjects.foundation.NSCoding |
|---|
NSCoding.Support |
| Nested classes/interfaces inherited from interface 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 CompareDescending
public static final NSSelector CompareCaseInsensitiveAscending
public static final NSSelector CompareCaseInsensitiveDescending
| Constructor Detail |
|---|
public EOSortOrdering(String key,
NSSelector selector)
key - property key to sort objects byselector - selector to use when comparing values for key in objectsEOSortOrdering.sortOrderingWithKey(java.lang.String, com.webobjects.foundation.NSSelector)| Method Detail |
|---|
public static EOSortOrdering sortOrderingWithKey(String key,
NSSelector selector)
key - property key to sort objects byselector - selector to use when comparing values for key in objects
key 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 by
array sorted according to sortOrderingsEOSortOrdering.sortArrayUsingKeyOrderArray(com.webobjects.foundation.NSMutableArray, com.webobjects.foundation.NSArray)
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 byEOSortOrdering.sortedArrayUsingKeyOrderArray(com.webobjects.foundation.NSArray, com.webobjects.foundation.NSArray)public String key()
EOSortOrdering.selector()public NSSelector selector()
EOSortOrdering.key()public String toString()
toString in class Objectpublic Class classForCoder()
classForCoder in interface NSCodingNSCoding.classForCoder()public static Object decodeObject(NSCoder coder)
coder - the NSCoder object used to create a new EOSortOrdering from
coderpublic void encodeWithCoder(NSCoder coder)
encodeWithCoder in interface NSCodingcoder - the NSCoder that will be the destination for class type and object information encoded by the receiverNSCoderpublic void encodeWithKeyValueArchiver(EOKeyValueArchiver archiver)
encodeWithKeyValueArchiver in interface EOKeyValueArchivingarchiver - the EOKeyValueArchiver object to encode the receiver's state intoEOKeyValueArchiverpublic static Object decodeWithKeyValueUnarchiver(EOKeyValueUnarchiver unarchiver)
unarchiver - the EOKeyValueUnarchiver object that contains the state of the object to be decoded
unarchiverEOKeyValueArchiver
|
Last updated June 2008 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||