Class AtomicReferenceArray<E>

java.lang.Object
dev.gmitch215.bytebox.locks.AtomicReferenceArray<E>
Type Parameters:
E - the element type

public class AtomicReferenceArray<E> extends Object
java.util.concurrent.atomic.AtomicReferenceArray, which the class library does not carry even though it carries AtomicReference.

One fiber runs at a time and none of these operations suspends, so each is already indivisible and no lock is needed to make it so.

Since:
1.0.2
  • Constructor Details

    • AtomicReferenceArray

      public AtomicReferenceArray(int length)
      Parameters:
      length - how many elements, each starting null
    • AtomicReferenceArray

      public AtomicReferenceArray(E[] array)
      Parameters:
      array - the elements to copy
  • Method Details

    • length

      public final int length()
      Returns how many elements.
      Returns:
      how many elements
    • get

      public final E get(int i)
      Parameters:
      i - the index
      Returns:
      the element
    • set

      public final void set(int i, E newValue)
      Parameters:
      i - the index
      newValue - the element to store
    • lazySet

      public final void lazySet(int i, E newValue)
      Parameters:
      i - the index
      newValue - the element to store
    • getAndSet

      public final E getAndSet(int i, E newValue)
      Parameters:
      i - the index
      newValue - the element to store
      Returns:
      the element that was there
    • compareAndSet

      public final boolean compareAndSet(int i, E expect, E update)
      Parameters:
      i - the index
      expect - the element that must be there
      update - the element to store
      Returns:
      whether it was stored
    • weakCompareAndSet

      public final boolean weakCompareAndSet(int i, E expect, E update)
      Parameters:
      i - the index
      expect - the element that must be there
      update - the element to store
      Returns:
      whether it was stored
    • toString

      public String toString()
      Overrides:
      toString in class Object