FileDocCategorySizeDatePackage
FilterEnumeration.javaAPI DocExample1348Tue Dec 08 01:21:00 GMT 1998oisoft.togetherx.scripts.SQL.impl

FilterEnumeration.java

package oisoft.togetherx.scripts.SQL.impl;

import java.util.Enumeration;
import COM.objectspace.jgl.UnaryFunction;

public class FilterEnumeration implements Enumeration{
  public FilterEnumeration(Enumeration source, UnaryFunction filter){
    mySource = source;
    myFilter = filter;
    myCurrent = null;
    while( mySource.hasMoreElements()
      && myCurrent == null )
    {
      myCurrent = myFilter.execute(mySource.nextElement());
    }
  }

  /**
   * Tests if this enumeration contains more elements.
   *
   * @return  <code>true</code> if this enumeration contains more elements;
   *          <code>false</code> otherwise.
   * @since   JDK1.0
   */
  public boolean hasMoreElements(){
    return myCurrent != null;
  }

  /**
   * Returns the next element of this enumeration.
   *
   * @return     the next element of this enumeration.
   * @exception  NoSuchElementException  if no more elements exist.
   * @since      JDK1.0
   */
  public Object nextElement(){
    Object result = myCurrent;
    myCurrent = null;
    while( mySource.hasMoreElements()
      && myCurrent == null )
    {
      myCurrent = myFilter.execute(mySource.nextElement());
    }
    return result;
  }

  private Object myCurrent;
  private UnaryFunction myFilter;
  private Enumeration mySource;
}