Class AtomicIntegerArray

java.lang.Object
dev.gmitch215.bytebox.locks.AtomicIntegerArray

public class AtomicIntegerArray extends Object
java.util.concurrent.atomic.AtomicIntegerArray, which the class library does not carry even though it carries AtomicInteger.

Indivisible for the same reason as AtomicReferenceArray: one fiber runs at a time and none of these operations suspends, so no two of them interleave.

Since:
1.0.2
  • Constructor Details

    • AtomicIntegerArray

      public AtomicIntegerArray(int length)
      Parameters:
      length - how many elements, each starting zero
    • AtomicIntegerArray

      public AtomicIntegerArray(int[] 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 int get(int i)
      Parameters:
      i - the index
      Returns:
      the element
    • set

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

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

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

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

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

      public final int getAndAdd(int i, int delta)
      Parameters:
      i - the index
      delta - how much to add
      Returns:
      the value before adding
    • addAndGet

      public final int addAndGet(int i, int delta)
      Parameters:
      i - the index
      delta - how much to add
      Returns:
      the value after adding
    • getAndIncrement

      public final int getAndIncrement(int i)
      Parameters:
      i - the index
      Returns:
      the value before incrementing
    • getAndDecrement

      public final int getAndDecrement(int i)
      Parameters:
      i - the index
      Returns:
      the value before decrementing
    • incrementAndGet

      public final int incrementAndGet(int i)
      Parameters:
      i - the index
      Returns:
      the value after incrementing
    • decrementAndGet

      public final int decrementAndGet(int i)
      Parameters:
      i - the index
      Returns:
      the value after decrementing
    • toString

      public String toString()
      Overrides:
      toString in class Object