Class LList

java.lang.Object
antlr.collections.impl.LList
All Implemented Interfaces:
List, Stack

public class LList extends Object implements List, Stack
A Linked List Implementation (not thread-safe for simplicity) (adds to the tail) (has an enumeration)
  • Field Details

    • tail

      protected LLCell tail
    • length

      protected int length
  • Constructor Details

    • LList

      public LList()
  • Method Details

    • add

      public void add(Object o)
      Add an object to the end of the list.
      Specified by:
      add in interface List
      Parameters:
      o - the object to add
    • append

      public void append(Object o)
      Append an object to the end of the list.
      Specified by:
      append in interface List
      Parameters:
      o - the object to append
    • deleteHead

      protected Object deleteHead() throws NoSuchElementException
      Delete the object at the head of the list.
      Returns:
      the object found at the head of the list.
      Throws:
      NoSuchElementException - if the list is empty.
    • elementAt

      public Object elementAt(int i) throws NoSuchElementException
      Get the ith element in the list.
      Specified by:
      elementAt in interface List
      Parameters:
      i - the index (from 0) of the requested element.
      Returns:
      the object at index i NoSuchElementException is thrown if i out of range
      Throws:
      NoSuchElementException
    • elements

      public Enumeration elements()
      Return an enumeration of the list elements
      Specified by:
      elements in interface List
    • height

      public int height()
      How high is the stack?
      Specified by:
      height in interface Stack
    • includes

      public boolean includes(Object o)
      Answers whether or not an object is contained in the list
      Specified by:
      includes in interface List
      Parameters:
      o - the object to test for inclusion.
      Returns:
      true if object is contained else false.
    • insertHead

      protected void insertHead(Object o)
      Insert an object at the head of the list.
      Parameters:
      o - the object to add
    • length

      public int length()
      Return the length of the list.
      Specified by:
      length in interface List
    • pop

      public Object pop() throws NoSuchElementException
      Pop the top element of the stack off.
      Specified by:
      pop in interface Stack
      Returns:
      the top of stack that was popped off.
      Throws:
      NoSuchElementException - if the stack is empty.
    • push

      public void push(Object o)
      Push an object onto the stack.
      Specified by:
      push in interface Stack
      Parameters:
      o - the object to push
    • top

      public Object top() throws NoSuchElementException
      Specified by:
      top in interface Stack
      Throws:
      NoSuchElementException