Package dev.roanh.gmark.util
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>
A list implementation backed by a fixed size array.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
forEachNonNull
(Consumer<T> fun) Similar toIterable.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.Gets the element at the given index.iterator()
void
Sets the element at the given index to the given value.void
Sets the element at the given index to the given value.int
size()
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
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
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, possiblynull
.
-
-
Method Details
-
get
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
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
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
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
Similar toIterable.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
-