Class RangeList<T>

java.lang.Object
dev.roanh.gmark.util.RangeList<T>
Type Parameters:
T - The data type stored in this list.
All Implemented Interfaces:
Iterable<T>

public class RangeList<T> extends Object implements Iterable<T>
A list implementation backed by a fixed size array.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private T[]
    The data stored in this list.
  • Constructor Summary

    Constructors
    Constructor
    Description
    RangeList(int size)
    Constructs a new range list with the given size.
    RangeList(int size, Supplier<T> init)
    Constructs a new range list with the given size and initialising every list element with the given supplier.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Similar to Iterable.forEach(Consumer) this method will iterate over all elements in this list and pass them to the given consumer.
    get(int index)
    Gets the element at the given index.
    get(IDable index)
    Gets the element at the given index.
     
    void
    set(int index, T value)
    Sets the element at the given index to the given value.
    void
    set(IDable index, T value)
    Sets the element at the given index to the given value.
    int
    Gets the size of this list.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator
  • Field Details

    • data

      private T[] data
      The data stored in this list.
  • Constructor Details

    • RangeList

      public RangeList(int size)
      Constructs a new range list with the given size.
      Parameters:
      size - The size of the range list.
    • RangeList

      public RangeList(int size, Supplier<T> init)
      Constructs a new range list with the given size and initialising every list element with the given supplier.
      Parameters:
      size - The size of the range list.
      init - The supplier to initialise all list elements, possibly null.
  • Method Details

    • get

      public T get(IDable index)
      Gets the element at the given index.
      Parameters:
      index - The index to get.
      Returns:
      The element at the given index.
      Throws:
      ArrayIndexOutOfBoundsException - When the given index is out of bounds.
      See Also:
    • get

      public T get(int index)
      Gets the element at the given index.
      Parameters:
      index - The index to get.
      Returns:
      The element at the given index.
      Throws:
      ArrayIndexOutOfBoundsException - When the given index is out of bounds.
    • set

      public void set(int index, T value)
      Sets the element at the given index to the given value.
      Parameters:
      index - The index to set.
      value - The new data to store.
      Throws:
      ArrayIndexOutOfBoundsException - When the given index is out of bounds.
    • set

      public void set(IDable index, T value)
      Sets the element at the given index to the given value.
      Parameters:
      index - The index to set.
      value - The new data to store.
      Throws:
      ArrayIndexOutOfBoundsException - When the given index is out of bounds.
      See Also:
    • size

      public int size()
      Gets the size of this list.
      Returns:
      The size of this list.
    • forEachNonNull

      public void forEachNonNull(Consumer<T> fun)
      Similar to Iterable.forEach(Consumer) this method will iterate over all elements in this list and pass them to the given consumer. However, null elements will be skipped instead of forwarded.
      Parameters:
      fun - The consumer to pass elements to.
    • iterator

      public Iterator<T> iterator()
      Specified by:
      iterator in interface Iterable<T>