Class SizeCachingConcurrentQueue<E>

  • Type Parameters:
    E -
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Iterable<E>, java.util.Collection<E>, java.util.Queue<E>

    public class SizeCachingConcurrentQueue<E>
    extends java.util.concurrent.ConcurrentLinkedQueue<E>
    A ConcurrentLinkedQueue wrapper which supports null values using a constant wrapper in place of null elements. This implementation caches the size and updates it when structurally modified to avoid the issue outlined in Java Specialists Issue 261.
    Since:
    1.6
    Author:
    Sina Madani
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static java.lang.Object NULL  
      protected java.util.function.Consumer<? extends E> offerSuper  
      protected java.util.concurrent.atomic.AtomicInteger size  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean addAll​(java.util.Collection<? extends E> c)  
      boolean contains​(java.lang.Object o)  
      static <T> T convertToNull​(java.lang.Object o)  
      boolean equals​(java.lang.Object o)  
      int hashCode()  
      java.util.Iterator<E> iterator()  
      boolean offer​(E e)  
      E peek()  
      E poll()  
      boolean remove​(java.lang.Object o)  
      protected static java.lang.Object replaceWithNull​(java.lang.Object o)  
      int size()  
      • Methods inherited from class java.util.concurrent.ConcurrentLinkedQueue

        add, clear, forEach, isEmpty, removeAll, removeIf, retainAll, spliterator, toArray, toArray, toString
      • Methods inherited from class java.util.AbstractQueue

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

        containsAll
      • Methods inherited from class java.lang.Object

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

        containsAll, parallelStream, stream, toArray
      • Methods inherited from interface java.util.Queue

        element, remove
    • Field Detail

      • NULL

        protected static final java.lang.Object NULL
      • size

        protected final java.util.concurrent.atomic.AtomicInteger size
      • offerSuper

        protected final java.util.function.Consumer<? extends E> offerSuper
    • Constructor Detail

      • SizeCachingConcurrentQueue

        public SizeCachingConcurrentQueue()
      • SizeCachingConcurrentQueue

        public SizeCachingConcurrentQueue​(java.util.Collection<? extends E> initial)
    • Method Detail

      • replaceWithNull

        protected static final java.lang.Object replaceWithNull​(java.lang.Object o)
      • convertToNull

        public static final <T> T convertToNull​(java.lang.Object o)
      • peek

        public E peek()
        Specified by:
        peek in interface java.util.Queue<E>
        Overrides:
        peek in class java.util.concurrent.ConcurrentLinkedQueue<E>
      • poll

        public E poll()
        Specified by:
        poll in interface java.util.Queue<E>
        Overrides:
        poll in class java.util.concurrent.ConcurrentLinkedQueue<E>
      • offer

        public boolean offer​(E e)
        Specified by:
        offer in interface java.util.Queue<E>
        Overrides:
        offer in class java.util.concurrent.ConcurrentLinkedQueue<E>
      • 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.concurrent.ConcurrentLinkedQueue<E>
      • remove

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

        public int size()
        Specified by:
        size in interface java.util.Collection<E>
        Overrides:
        size in class java.util.concurrent.ConcurrentLinkedQueue<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>
        Overrides:
        iterator in class java.util.concurrent.ConcurrentLinkedQueue<E>
      • contains

        public boolean contains​(java.lang.Object o)
        Specified by:
        contains in interface java.util.Collection<E>
        Overrides:
        contains in class java.util.concurrent.ConcurrentLinkedQueue<E>
      • equals

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

        public int hashCode()
        Specified by:
        hashCode in interface java.util.Collection<E>
        Overrides:
        hashCode in class java.lang.Object