Class ArrayRingBuffer<T>

java.lang.Object
org.infinispan.commons.util.ArrayRingBuffer<T>

public final class ArrayRingBuffer<T> extends Object
It's a growable ring buffer that allows to move tail/head sequences, clear, append, set/replace at specific positions. This version requires headSequence to always be pointing at the first non null value if one is present.
Author:
Francesco Nigro
  • Constructor Details

    • ArrayRingBuffer

      public ArrayRingBuffer()
    • ArrayRingBuffer

      public ArrayRingBuffer(int initialSize)
    • ArrayRingBuffer

      public ArrayRingBuffer(int initialSize, long headSequence)
  • Method Details

    • size

      public int size()
    • size

      public int size(boolean count_null_elements)
    • getTailSequence

      public long getTailSequence()
    • getHeadSequence

      public long getHeadSequence()
    • forEach

      public void forEach(ObjLongConsumer<? super T> consumer)
    • availableCapacityWithoutResizing

      public int availableCapacityWithoutResizing()
    • contains

      public boolean contains(long index)
    • dropTailToHead

      public void dropTailToHead()
    • clear

      public void clear()
    • dropTailTo

      public int dropTailTo(long indexInclusive)
      Remove all elements from tailSequence back to indexInclusive.
      At the end of this operation tailSequence is equals to indexInclusive. Note there can be null values between tailSequence and headSequence as only headSequence is caught up to a non null value on modification.
       eg:
       elements = [A, B, C]
       tail = 3
       head = 0
      
       dropTailTo(1)
      
       elements = [A]
       tail = 1
       head = 0
       
    • dropHeadUntil

      public int dropHeadUntil(long indexExclusive)
      Remove all elements from headSequence to at least indexExclusive until a non null value is found if present.
      At the end of this operation headSequence will be greater than or equal indexExclusive. If there are no more values left then headSequence will equal tailSequence.
       eg:
       elements = [A, B, C]
       tail = 3
       head = 0
      
       dropHeadUntil(1)
      
       elements = [B, C]
       tail = 3
       head = 1
       
    • get

      public T get(long index)
    • set

      public T set(long index, T e)
    • add

      public void add(T e)
    • isEmpty

      public boolean isEmpty()
    • peek

      public T peek()
    • poll

      public T poll()
      Removes the element at head, does not catch up the headSequence but will increment
    • remove

      public T remove(long index)
      Removes an element at index
    • toString

      public String toString()
      Overrides:
      toString in class Object