Class BoundedQueue<T>

  • All Implemented Interfaces:
    java.lang.Iterable<T>, java.util.Collection<T>, java.util.Queue<T>

    final class BoundedQueue<T>
    extends java.util.AbstractQueue<T>
    A queue with a fixed maximum size. Once the queue is full, no more elements can be added until an element is removed.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int capacity
      The maximum number of elements that can be present.
      private java.util.Queue<T> data
      Queue that never holds more than capacity elements.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Iterator<T> iterator()  
      boolean offer​(T element)  
      T peek()  
      T poll()  
      int size()  
      • Methods inherited from class java.util.AbstractQueue

        add, addAll, clear, element, remove
      • Methods inherited from class java.util.AbstractCollection

        contains, containsAll, isEmpty, remove, removeAll, retainAll, 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

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

        forEach
    • Field Detail

      • data

        private final java.util.Queue<T> data
        Queue that never holds more than capacity elements.
      • capacity

        private final int capacity
        The maximum number of elements that can be present.
    • Constructor Detail

      • BoundedQueue

        BoundedQueue​(int capacity)
        Creates a new BoundedQueue.
        Parameters:
        capacity - the maximum number of elements the queue can hold
        Throws:
        java.lang.IllegalArgumentException - if the capacity is negative
    • Method Detail

      • iterator

        public java.util.Iterator<T> iterator()
        Specified by:
        iterator in interface java.util.Collection<T>
        Specified by:
        iterator in interface java.lang.Iterable<T>
        Specified by:
        iterator in class java.util.AbstractCollection<T>
      • size

        public int size()
        Specified by:
        size in interface java.util.Collection<T>
        Specified by:
        size in class java.util.AbstractCollection<T>
      • offer

        public boolean offer​(T element)
      • poll

        public T poll()
      • peek

        public T peek()