|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
Interface expected by methods in the Map class.
When using the map function (see Map), the data
returned by the evaluation function may actually be more items than are
processed as inputs. This is a common idiom in Perl, often used in the
creation of associate arrays (the Perl equivalent of
java.util.HashTable). Because of this, map and
grep (see Grep) use different interfaces for the
specification of the evaluation objects they operate upon.
To allow a map operation to potentially generate more items
than it is fed, the signature of the eval method dictates that
the return value is an array. Though this may be inconvenient for code that
implements 1-to-1 mapping, it allows maximum flexibility. In cases where the
programmer knows for certain that the map usage will only need
to do a 1-to-1 data mapping, map can also accept a
GrepBlock instance.
The MapBlock interface faces the same block-based limitations
as GrepBlock. In particular, while this can be used in the
declaration of anonymous inner-classes on the fly, these classes are limited
in what values from the current lexical scope can be accessed. Only those
values that are declared both final and static may be
referenced in one of these inner-classes. The solution to this is to use the
interface in the declaration of a named inner-class, one that defines its
own members and methods. This can then be used to encapsulate the local
information that needs to be passed to the particular call to
map. For an example of this, see GrepBlock.
| Method Summary | |
java.lang.Object[] |
eval(java.lang.Object object)
When the map function is called with an object implementing
this interface, this is the function it will expect to be able to
invoke for each element in the list it also receives. |
| Method Detail |
public java.lang.Object[] eval(java.lang.Object object)
map function is called with an object implementing
this interface, this is the function it will expect to be able to
invoke for each element in the list it also receives. The implementing
class should provide this such that it takes a single argument, and
returns an array of zero or more objects (or null, which is also
acceptable).
object - An arbitrary object passed in by map
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||