WebObjects 5.4.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:
NSArray.Operator.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

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:
         <blockquote>
          class CountOperator implements NSArray.Operator {
              CountOperator() {}
              public Object compute(NSArray values, String keyPath) {
                  return new Integer(values.count());
              }
          }
          </blockquote>
 

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 June 2008

Copyright © 2000-2008 Apple Inc.