Class ListQueue<E>

  • Type Parameters:
    E - the element type
    All Implemented Interfaces:
    java.lang.Iterable<E>, java.util.Collection<E>, Queue<E>

    public class ListQueue<E>
    extends AbstractQueue<E>
    A ListQueue implements a first-in, first-out container using a List as a data structure.
    Version:
    $Revision$
    • Constructor Summary

      Constructors 
      Constructor Description
      ListQueue()
      Construct a new unconstrained ListQueue using a LinkedList for a data-structure.
      ListQueue​(int maxSize)
      Construct a new constrained ListQueue using a LinkedList for a data-structure.
      ListQueue​(java.util.List<E> list)
      Construct a new unconstrained ListQueue.
      ListQueue​(java.util.List<E> list, int maxSize)
      Construct a new constrained ListQueue.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected boolean addLast​(E obj)
      Appends the given element to the end of this list.
      E getBack()
      Get the object at the back of the queue.
      E getFront()
      Get the object at the front of the queue.
      java.util.Iterator<E> iterator()
      Returns an iterator over the elements in this list in proper sequence.
      protected E removeFirst()
      Remove the first object in the queue.
      java.util.Iterator<E> reverseIterator()
      Returns an iterator over the elements in this list in reverse sequence.
      int size()
      Get the size of the queue.
      java.lang.String toString()
      Return a String representation of this queue.
      • Methods inherited from class java.util.AbstractCollection

        addAll, contains, containsAll, remove, removeAll, retainAll, toArray, toArray
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        addAll, contains, containsAll, equals, hashCode, parallelStream, remove, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArray, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
    • Field Detail

      • list

        protected final java.util.List<E> list
        List container
    • Constructor Detail

      • ListQueue

        public ListQueue​(java.util.List<E> list,
                         int maxSize)
        Construct a new constrained ListQueue.
        Parameters:
        list - The list which will be used to store queued objects.
        maxSize - The maximum size of the queue.
        Throws:
        java.lang.IllegalArgumentException - List is null.
      • ListQueue

        public ListQueue​(int maxSize)
        Construct a new constrained ListQueue using a LinkedList for a data-structure.
        Parameters:
        maxSize - The maximum size of the queue.
      • ListQueue

        public ListQueue​(java.util.List<E> list)
        Construct a new unconstrained ListQueue.
        Parameters:
        list - The list which will be used to store queued objects.
        Throws:
        java.lang.IllegalArgumentException - List is null
      • ListQueue

        public ListQueue()
        Construct a new unconstrained ListQueue using a LinkedList for a data-structure.
    • Method Detail

      • addLast

        protected boolean addLast​(E obj)
        Appends the given element to the end of this list.
        Specified by:
        addLast in class AbstractQueue<E>
        Parameters:
        obj - Object to append.
        Returns:
        Per Collection.add(), we return a boolean to indicate if the object modified the collection.
      • removeFirst

        protected E removeFirst()
        Remove the first object in the queue.
        Specified by:
        removeFirst in class AbstractQueue<E>
        Returns:
        First object in the queue.
      • size

        public int size()
        Get the size of the queue.
        Specified by:
        size in interface java.util.Collection<E>
        Specified by:
        size in class java.util.AbstractCollection<E>
        Returns:
        The number of elements in the queue.
      • iterator

        public java.util.Iterator<E> iterator()
        Returns an iterator over the elements in this list in proper sequence.
        Specified by:
        iterator in interface java.util.Collection<E>
        Specified by:
        iterator in interface java.lang.Iterable<E>
        Specified by:
        iterator in class java.util.AbstractCollection<E>
        Returns:
        An iterator over the elements in this list in proper sequence.
      • reverseIterator

        public java.util.Iterator<E> reverseIterator()
        Returns an iterator over the elements in this list in reverse sequence.
        Returns:
        An iterator over the elements in this list in reverse sequence.
      • toString

        public java.lang.String toString()
        Return a String representation of this queue.
        Overrides:
        toString in class java.util.AbstractCollection<E>
        Returns:
        String