// file:    PolylistEnum.java
// author:  Robert Keller
// purpose: Polylist enumeration class of polya package

package polya;

import java.lang.*;
import java.util.Enumeration;

/**
  *  PolylistEnum is an enumeration class for the class Polylist.  It 
  *  implements the interface java.util.Enumeration, i.e. the methods:
  *  hasMoreElements() and nextElement().  
 **/

public class PolylistEnum implements java.util.Enumeration
  {
  Polylist L;			// current list
 
  /**
    *  PolylistEnum constructs a PolylistEnum from a Polylist.
   **/

  public PolylistEnum(Polylist L)	// constructor
    {
    this.L = L;
    }


  /**
    *  hasMoreElements() indicates whether there are more elements left in 
    *  the enumeration.
   **/

  public boolean hasMoreElements()
    {
    return L.nonEmpty();
    }


  /**
    *  nextElement returns the next element in the enumeration.
   **/

  public Object nextElement() 
    {
    if( L.isEmpty() )
      throw new 
        java.util.NoSuchElementException("No next element in Polylist");

    Object result = L.first();
    L = L.rest();
    return result;
    }
  }

