All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class collections.MappingEnumeration

java.lang.Object
   |
   +----collections.MappingEnumeration

public class MappingEnumeration
extends Object
implements Enumeration
MappingEnumerations allow you to transform elements from other enumerations before they are seen by their `consumers' (i.e., the callers of `nextElement').

MappingEnumerations work as wrappers around other Enumerations. To build one, you need an existing Enumeration (perhaps one from coll.elements(), for some Collection coll), and a Function object (i.e., implementing interface Function). For example, if you want to process only the parent() fields of java.awt.Component elements held by a collection coll you could write something of the form:

 Enumeration e = coll.elements();
 Enumeration parents = MappingEnumeration(e, ParentFunction);
 while (parents.hasMoreElements()) 
  doSomethingWith((Container)(parents.nextElement()));
 
To use this, you will also need to write a little class of the form:
 class ParentFunction implements Function {
  Object function(Object v) {
    if (v instanceOf Component) return ((Component)v).getParent();
    else return null;
  }
 }
 

(This requires too much set-up to be reasonable in most situations, but is invaluable in others.)

See Also:
function

Constructor Index

 o MappingEnumeration(Enumeration, Function)
Make an enumeration wrapping src, returning p.function for each nextElement

Method Index

 o hasMoreElements()
Implements java.util.Enumeration.hasMoreElements
 o nextElement()
Implements java.util.Enumeration.nextElement.

Constructors

 o MappingEnumeration
 public MappingEnumeration(Enumeration src,
                           Function p)
Make an enumeration wrapping src, returning p.function for each nextElement

Methods

 o hasMoreElements
 public synchronized boolean hasMoreElements()
Implements java.util.Enumeration.hasMoreElements

 o nextElement
 public synchronized Object nextElement()
Implements java.util.Enumeration.nextElement.


All Packages  Class Hierarchy  This Package  Previous  Next  Index