WebObjects 5.2

com.webobjects.foundation
Interface NSArray.Operator

Enclosing class:
NSArray

public static interface NSArray.Operator

Objects implementing NSArray.Operator are used to perform operations on an array's elements.

To compute an operation on an array's elements, the key-value coding methods with a specially formatted key are used. The character @ introduces the name of the operator to be performed. For example, to compute the average salary of an array's elements, the method valueForKeyPath can be used with "@avg.salary" as key path.

The new operator class can be made available for use with NSArrays with the method setOperatorForKey. The operatorNames method returns the keys for the operators that NSArray knows about, and operatorForKey returns the operator for a specified key.

See Also:
compute(com.webobjects.foundation.NSArray, java.lang.String), NSArray.valueForKeyPath(java.lang.String), NSArray.operatorForKey(java.lang.String), NSArray.setOperatorForKey(java.lang.String, com.webobjects.foundation.NSArray.Operator), NSArray

Method Summary
 Object compute(NSArray values, String keyPath)
          This interface must be implemented in order to add new operators to NSArray.
 

Method Detail

compute

public Object compute(NSArray values,
                      String keyPath)
This interface must be implemented in order to add new operators to NSArray. A typical implementation would be as follows:
class CountOperator implements NSArray.Operator { CountOperator() {} public Object compute(NSArray values, String keyPath) { return new Integer(values.count()); } }

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.

Parameters:
values - array of input objects
keyPath - property of the elements in values to perform the operation on
Returns:
the computed value

Last updated Fri Feb 21 13:15:00 PST 2003.

Copyright © 2003 Apple Computer, Inc.