Class ConsList

java.lang.Object
edu.ksu.cis.viewer.ConsList

public final class ConsList extends Object
An immutable linear recursive structure with a head, which is an Object, and a tail, which is a ConsList.
Author:
Rod Howell (rhowell@ksu.edu)
  • Constructor Details

    • ConsList

      public ConsList()
      Constructs an empty ConsList.
    • ConsList

      public ConsList(Object h, ConsList lst)
      Constructs a ConsList with the given head and tail. If the given tail is null, an empty ConsList is used in its place.
      Parameters:
      h - the head of the list
      lst - the tail of the list
  • Method Details

    • isEmpty

      public boolean isEmpty()
      Returns true if this list is empty.
      Returns:
      whether this list is empty
    • getHead

      public Object getHead() throws EmptyListException
      Returns the head of this list.
      Returns:
      the head of this list
      Throws:
      EmptyListException - If this list is empty.
    • getTail

      public ConsList getTail() throws EmptyListException
      Returns the tail of the list.
      Returns:
      the tail of this list
      Throws:
      EmptyListException - If this list is empty.