Documentation Archive Developer
Search
PATH Documentation > WebObjects

Table of Contents

NSArray.Operator


Package:
com.webobjects.foundation

Interface Description


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.



Instance Methods



compute

public Object compute( NSArray values, String keyPath)

Performs an operation on the elements in values and returns the result. The keyPath argument optionally specifies a particular property of the elements in values to perform the operation on.

© 2001 Apple Computer, Inc. (Last Published April 17, 2001)


Table of Contents