PATH |
- Package:
- com.webobjects.foundation
The NSArray.Operator interface defines an API for performing operations on the elements in an array. The method, compute, takes as its arguments an array and a key path. The array provides the objects on which to operate, and the optional key path further specifies a particular property on which to operate.
As an example, consider an operator that computes averages. To get the average salary for a set of Employee objects, send the operator a compute message with "salary" as the key path. The operator gets the salary value from each of the objects in the array and then returns the computed average.
Instead of invoking compute directly on an operator, you can use NSArray's key-value coding methods with a specially formatted key. The character "@" introduces the name of the operator you want to perform. For example, to compute the average salary of an array's elements, you could invoke valueForKeyPath on the array with "@avg.salary" as the key path. For more information, see the NSArray class specification.
Additionally, NSArray provides a set of default operators. To access the operators, use the method operatorForKey, specifying the name of the operator as an argument. For information on the default operators, see the NSArray class specification.
You can augment the set of default operators with your own custom operator. Simply create a class that implements NSArray.Operator. To make it available to NSArray for use with key-value coding, use the method setOperatorForKey.
public Object compute( NSArray values, String keyPath)
© 2001 Apple Computer, Inc. (Last Published April 17, 2001)