Class RingQueue<E>

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

    public class RingQueue<E>
    extends java.util.AbstractQueue<E>
    Simple Ring Queue implementation that has an enforced max size value.
    • Constructor Summary

      Constructors 
      Constructor Description
      RingQueue​(int queueSize)
      Creates a new RingQueue instance with the given fixed Queue size.
      RingQueue​(java.util.Collection<E> collection)
      Creates a new RingQueue instance with a size that matches the size of the given Collection and filled with the values from that Collection.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean addAll​(java.util.Collection<? extends E> c)  
      void clear()  
      boolean contains​(java.lang.Object value)  
      boolean isEmpty()  
      java.util.Iterator<E> iterator()  
      boolean offer​(E e)  
      E peek()  
      E poll()  
      E poll​(java.util.function.Supplier<E> createOnEmpty)
      Retrieves and removes the head of this ring queue, and if the queue is currently empty a new instance of the queue type is provided by invoking the given Supplier.
      boolean remove​(java.lang.Object o)  
      boolean removeAll​(java.util.Collection<?> c)  
      boolean retainAll​(java.util.Collection<?> c)  
      int size()  
      • Methods inherited from class java.util.AbstractQueue

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

        containsAll, 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

        containsAll, equals, hashCode, parallelStream, removeIf, spliterator, stream, toArray, toArray, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
    • Constructor Detail

      • RingQueue

        public RingQueue​(int queueSize)
        Creates a new RingQueue instance with the given fixed Queue size.
        Parameters:
        queueSize - The size to use for the ring queue.
      • RingQueue

        public RingQueue​(java.util.Collection<E> collection)
        Creates a new RingQueue instance with a size that matches the size of the given Collection and filled with the values from that Collection.
        Parameters:
        collection - the Collection whose values populates this RingQueue instance.
    • Method Detail

      • offer

        public boolean offer​(E e)
      • poll

        public E poll()
      • poll

        public E poll​(java.util.function.Supplier<E> createOnEmpty)
        Retrieves and removes the head of this ring queue, and if the queue is currently empty a new instance of the queue type is provided by invoking the given Supplier.
        Parameters:
        createOnEmpty - a Supplier which will return default values if the RingQueue is empty.
        Returns:
        the head element of this queue or a default instance created from the provided Supplier/
      • peek

        public E peek()
      • addAll

        public boolean addAll​(java.util.Collection<? extends E> c)
        Specified by:
        addAll in interface java.util.Collection<E>
        Overrides:
        addAll in class java.util.AbstractQueue<E>
      • remove

        public boolean remove​(java.lang.Object o)
        Specified by:
        remove in interface java.util.Collection<E>
        Overrides:
        remove in class java.util.AbstractCollection<E>
      • removeAll

        public boolean removeAll​(java.util.Collection<?> c)
        Specified by:
        removeAll in interface java.util.Collection<E>
        Overrides:
        removeAll in class java.util.AbstractCollection<E>
      • retainAll

        public boolean retainAll​(java.util.Collection<?> c)
        Specified by:
        retainAll in interface java.util.Collection<E>
        Overrides:
        retainAll in class java.util.AbstractCollection<E>
      • iterator

        public java.util.Iterator<E> iterator()
        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>
      • size

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

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Collection<E>
        Overrides:
        isEmpty in class java.util.AbstractCollection<E>
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Collection<E>
        Overrides:
        clear in class java.util.AbstractQueue<E>
      • contains

        public boolean contains​(java.lang.Object value)
        Specified by:
        contains in interface java.util.Collection<E>
        Overrides:
        contains in class java.util.AbstractCollection<E>