// file:    polycell.java
// author:  Robert Keller
// purpose: polycell used in implementation of Polylists

package polya;

import java.io.*;
import java.lang.*;
	
/**
  *  NonEmptyList is the sub-class of List consisting of non-empty 
  *  lists.  Every NonEmptyList has a first and a rest.
 **/

class polycell
  {
  private Object First;
  private Object Rest;


  /**
    *  first() returns the first element of a NonEmptyList.
   **/ 

  Object first()
    {
    return First;
    }


  /**
    *  rest() returns the rest of a NonEmptyList.
   **/ 

  Polylist rest()
    {
    if( Rest instanceof Seed ) 
      {
      Rest = ((Seed)Rest).grow();
      }
    return (Polylist)Rest;
    }


  /**
    *  polycell is the constructor for the cell of a Polyist, 
    *  given a First and a Rest.
    *
    *  Use static method cons of class Polylist to avoid using 'new' 
    *  explicitly.
   **/ 

  polycell(Object First, Object Rest)
    {
    this.First = First;
    this.Rest = Rest;
    }


  /**
    *  setFirst() sets the first element of a NonEmptyList.
   **/ 

  void setFirst(Object value)
    {
    First = value;
    }
  }  // class polycell
