Class AbstractQueue<E>

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

    public abstract class AbstractQueue<E>
    extends java.util.AbstractCollection<E>
    implements Queue<E>
    An abstract implementation of a Queue. Sub-classes must provide methods for addLast(Object) and removeFirst().
    Version:
    $Revision$
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected AbstractQueue()
      Initializes the AbstractQueue.
      protected AbstractQueue​(int maxSize)
      Initializes the AbstractQueue.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(E obj)
      Append and object to the underling list.
      protected abstract boolean addLast​(E obj)
      Appends the given element to the end of the queue
      void clear()
      Removes all of the elements from this queue
      int getMaximumSize()
      Get the maximum size of the queue.
      boolean isEmpty()
      Check if the queue is empty.
      boolean isFull()
      Check if the queue is full.
      E remove()
      Remove and return the first object in the queue.
      protected abstract E removeFirst()
      Remove the first object in the queue
      void setMaximumSize​(int size)
      Set the maximum size of the queue
      • Methods inherited from class java.util.AbstractCollection

        addAll, contains, containsAll, iterator, remove, removeAll, retainAll, size, toArray, toArray, toString
      • 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, iterator, parallelStream, remove, removeAll, removeIf, retainAll, size, spliterator, stream, toArray, toArray, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
    • Field Detail

      • DEFAULT_MAXIMUM_SIZE

        public static int DEFAULT_MAXIMUM_SIZE
        Default maximum queue size
      • maximumSize

        protected int maximumSize
        Maximum queue size
    • Constructor Detail

      • AbstractQueue

        protected AbstractQueue()
        Initializes the AbstractQueue.
      • AbstractQueue

        protected AbstractQueue​(int maxSize)
        Initializes the AbstractQueue.
        Parameters:
        maxSize - Maximum queue size.
        Throws:
        java.lang.IllegalArgumentException - Illegal size.
    • Method Detail

      • setMaximumSize

        public void setMaximumSize​(int size)
        Set the maximum size of the queue
        Specified by:
        setMaximumSize in interface Queue<E>
        Parameters:
        size - New maximim queue size or Queue.UNLIMITED_MAXIMUM_SIZE.
        Throws:
        java.lang.IllegalArgumentException - Illegal size.
      • isFull

        public boolean isFull()
        Check if the queue is full.
        Specified by:
        isFull in interface Queue<E>
        Returns:
        True if the queue is full.
      • isEmpty

        public boolean isEmpty()
        Check if the queue is empty.
        Specified by:
        isEmpty in interface java.util.Collection<E>
        Specified by:
        isEmpty in interface Queue<E>
        Overrides:
        isEmpty in class java.util.AbstractCollection<E>
        Returns:
        True if the queue is empty.
      • add

        public boolean add​(E obj)
                    throws FullCollectionException
        Append and object to the underling list.
        Specified by:
        add in interface java.util.Collection<E>
        Specified by:
        add in interface Queue<E>
        Overrides:
        add in class java.util.AbstractCollection<E>
        Parameters:
        obj - Object to enqueue.
        Returns:
        True if collection was modified.
        Throws:
        FullCollectionException - The queue is full.
      • clear

        public void clear()
        Removes all of the elements from this queue
        Specified by:
        clear in interface java.util.Collection<E>
        Overrides:
        clear in class java.util.AbstractCollection<E>
      • addLast

        protected abstract boolean addLast​(E obj)
        Appends the given element to the end of the queue
        Parameters:
        obj - Object to append
        Returns:
        Per Collection.add(), we return a boolean to indicate if the object modified the collection.
      • removeFirst

        protected abstract E removeFirst()
        Remove the first object in the queue
        Returns:
        First object in the queue