    All Packages  Class Hierarchy  This Package  Previous  Next  Index

# Class collections.FilteringEnumeration

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

public class FilteringEnumeration
extends Object
implements Enumeration

FilteringEnumerations allow you to filter out elements from other enumerations before they are seen by their `consumers' (i.e., the callers of `nextElement').

FilteringEnumerations 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 Predicate object (i.e., implementing interface Predicate). For example, if you want to screen out everything but Panel objects from a collection coll that might hold things other than Panels, write something of the form:

     Enumeration e = coll.elements();
     Enumeration panels = FilteringEnumeration(e, IsPanel);
     while (panels.hasMoreElements())
      doSomethingWith((Panel)(panels.nextElement()));

To use this, you will also need to write a little class of the form:

     class IsPanel implements Predicate {
      boolean predicate(Object v) { return (v instanceof Panel); }
     }

See Also:
  predicate

##

FilteringEnumeration(Enumeration, Predicate)
  Make a Filter using src for the elements, and p as the screener, selecting only those elements of src for which p is true
FilteringEnumeration(Enumeration, Predicate, boolean)
  Make a Filter using src for the elements, and p as the screener, selecting only those elements of src for which p.predicate(v) == sense.

##

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

##

FilteringEnumeration

     public FilteringEnumeration(Enumeration src,
                                 Predicate p)

  Make a Filter using src for the elements, and p as the screener, selecting only those elements of src for which p is true

FilteringEnumeration

     public FilteringEnumeration(Enumeration src,
                                 Predicate p,
                                 boolean sense)

  Make a Filter using src for the elements, and p as the screener, selecting only those elements of src for which p.predicate(v) == sense. A value of true for sense selects only values for which p.predicate is true. A value of false selects only those for which it is false.

##

hasMoreElements

     public synchronized boolean hasMoreElements()

  Implements java.util.Enumeration.hasMoreElements

nextElement

     public synchronized Object nextElement()

  Implements java.util.Enumeration.nextElement.

    All Packages  Class Hierarchy  This Package  Previous  Next  Index