Package civitas.celestis.util.array
Interface IntArray
- All Superinterfaces:
BaseArray<Integer>,Iterable<Integer>,Serializable
- All Known Implementing Classes:
IntFastArray
A type-safe array of primitive
ints.- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault IntArrayAppend the provided arrayato the end of this array, then returns the resulting array.int[]array()Returns a primitive array containing the elements of this array in their proper order.boxed()Returns an array containing the elements of this array in their boxed form.booleancontains(int v) Returns whether this array contains the provided valuev.booleanReturns whether this array contains multiple objects.booleanChecks for equality between this array and the provided objectobj.voidfill(int v) Fills this array with the provided valuev.voidfillRange(int s, int e, int v) Fills every slot of this array between the range of[s, e)with the provided valuev.default IntArrayTests each element of this array using the provided predicatef, collects all elements the predicate returnstrueto, then returns a new array containing only the filtered elements.voidforEach(BiConsumer<? super Integer, ? super Integer> a) Executes the provided actionaonce for each element of this array.voidExecutes the provided actionaonce for each element of this array.static IntArrayCreates a new type-safe array from the provided stream of values.intget(int i) Returns theith element of this array.iterator()Returns an iterator over every element of this array.intlength()Returns the length of this array.list()Returns an unmodifiable list containing the elements of this array in their proper order.Applies the provided mapper functionfto each element of this array, then returns a new array containing the return values of the functionf.<F> SafeArray<F>mapToObj(IntFunction<? extends F> f) Applies the provided mapper functionfto each element of this array, then returns a new array containing the return values of the functionf.merge(IntArray a, IntBinaryOperator f) Between this array and the provided arraya, this applies the merger functionfto each corresponding pair of elements, then returns a new array containing the return values of the merger functionf.static IntArrayof(int... values) Creates a new type-safe array from the provided array of values.default IntArrayPrepends the provided arrayato the front of this array, then returns the resulting array.static IntArrayreferenceOf(int... values) Creates a new type-safe reference array from the provided array of values.voidreplaceAll(int oldValue, int newValue) Replaces all instances of the old value to the new value.voidreplaceFirst(int oldValue, int newValue) Replaces only the first instance of the old value to the new value.voidreplaceLast(int oldValue, int newValue) Replaces only the last instance of the old value to the new value.resize(int size) Returns a resized array whose elements are mapped from that of this array's elements.voidset(int i, int e) Sets theith element of this array.voidSets a sub-array of this array to the values of the provided sub-arraya.voidshuffle()Shuffles this array, randomizing its elements' order.voidsort()Sorts this array by its natural ascending order.voidsort(Comparator<? super Integer> c) Sorts this array using the provided comparator functionc.stream()Returns a stream whose source is the elements of this array.subArray(int s, int e) Returns a sub-array of this array which represents a portion of this array between the range of[s, e).toString()Serializes this array into a string.tuple()Returns a tuple containing the elements of this array in their proper order.voidupdate(int i, IntUnaryOperator f) Updates theith element of this array with the provided update functionf.voidupdate(BiFunction<? super Integer, ? super Integer, Integer> f) Applies the provided update functionfto each element of this array, then assigns the return value of the function to the corresponding index of this array.voidApplies the provided update functionfto each element of this array, then assigns the return value of the function to the corresponding index of this array.Methods inherited from interface java.lang.Iterable
spliterator
-
Method Details
-
of
Creates a new type-safe array from the provided array of values.- Parameters:
values- The values to contain in the array- Returns:
- A new type-safe array containing the provided values
-
referenceOf
Creates a new type-safe reference array from the provided array of values. Changes in the type-safe array will be reflected to the original array, as well as from the original array to the type-safe array.- Parameters:
values- The values the array should reference- Returns:
- A new type-safe reference array referencing the provided values
-
from
Creates a new type-safe array from the provided stream of values.- Parameters:
s- The stream of which to use as the source of the array- Returns:
- A new type-safe array containing the provided stream's values
-
length
int length()Returns the length of this array. -
contains
boolean contains(int v) Returns whether this array contains the provided valuev.- Parameters:
v- The value to check for containment- Returns:
trueif at least one element of this array is equal to the provided valuev
-
containsAll
Returns whether this array contains multiple objects.- Parameters:
i- The iterable object of which to check for containment- Returns:
trueif this array contains every element of the iterable object
-
get
Returns theith element of this array.- Parameters:
i- The index of the element to get- Returns:
- The
ith element of this array - Throws:
IndexOutOfBoundsException- When the indexiis out of bounds
-
set
Sets theith element of this array.- Parameters:
i- The index of the element to sete- The element of which to set to- Throws:
IndexOutOfBoundsException- When the indexiis out of bounds
-
update
Updates theith element of this array with the provided update functionf.- Parameters:
i- The index of the element to updatef- The update function of which to apply to the element- Throws:
IndexOutOfBoundsException- When the indexiis out of bounds
-
fill
void fill(int v) Fills this array with the provided valuev. Every element will be reassigned.- Parameters:
v- The value to fill this array with
-
fillRange
void fillRange(int s, int e, int v) Fills every slot of this array between the range of[s, e)with the provided valuev.- Parameters:
s- The starting index at which to start assigning values frome- The ending index at which to stop assigning values atv- The value of which to assign to every slot within the specified range- Throws:
IndexOutOfBoundsException- When the indices are out of bounds
-
update
Applies the provided update functionfto each element of this array, then assigns the return value of the function to the corresponding index of this array.- Parameters:
f- The function of which to apply to each element of this array
-
update
Applies the provided update functionfto each element of this array, then assigns the return value of the function to the corresponding index of this array. The first parameter is the index of the value which was provided.- Parameters:
f- The function of which to apply to each element of this array
-
replaceAll
void replaceAll(int oldValue, int newValue) Replaces all instances of the old value to the new value.- Parameters:
oldValue- The old value to replacenewValue- The new value to replace to
-
replaceFirst
void replaceFirst(int oldValue, int newValue) Replaces only the first instance of the old value to the new value. (starting from index0, and incrementing upwards)- Parameters:
oldValue- The old value to replacenewValue- The new value to replace to
-
replaceLast
void replaceLast(int oldValue, int newValue) Replaces only the last instance of the old value to the new value. (starting from the last index, and decrementing downwards)- Parameters:
oldValue- The old value to replacenewValue- The new value to replace to
-
subArray
Returns a sub-array of this array which represents a portion of this array between the range of[s, e). Changes in the sub-array will be reflected to this array. For example, callinga.subArray(1, 3).fill(null);will have the same effect as setting the values of indices1, 2of the original array tonull.- Parameters:
s- The starting index at which to start creating the sub-array (inclusive)e- The ending index at which to stop creating the sub-array (exclusive)- Returns:
- The sub-array representing the index range of
[s, e) - Throws:
IndexOutOfBoundsException- When the range is invalid, or is out of bounds
-
setRange
Sets a sub-array of this array to the values of the provided sub-arraya.- Parameters:
s- The starting index at which to start copying values from (inclusive)e- The ending index at which to stop copying values from (exclusive)a- The sub-array containing the values to assign to this array- Throws:
IndexOutOfBoundsException- When the range is invalid, or is out of bounds
-
resize
Returns a resized array whose elements are mapped from that of this array's elements. If the new array is larger than this array, the unmappable part will not be populated, leaving it uninitialized asnull.- Parameters:
size- The size to resize this array to- Returns:
- The resized array
-
shuffle
void shuffle()Shuffles this array, randomizing its elements' order. -
sort
void sort()Sorts this array by its natural ascending order. -
sort
Sorts this array using the provided comparator functionc. -
filter
Tests each element of this array using the provided predicatef, collects all elements the predicate returnstrueto, then returns a new array containing only the filtered elements.- Parameters:
f- The predicate to use to filter this array- Returns:
- The filtered array
-
map
Applies the provided mapper functionfto each element of this array, then returns a new array containing the return values of the functionf.- Parameters:
f- The function of which to apply to each element of this array- Returns:
- The resulting array
-
mapToObj
Applies the provided mapper functionfto each element of this array, then returns a new array containing the return values of the functionf.- Type Parameters:
F- The type of element to map this array to- Parameters:
f- The function of which to apply to each element of this array- Returns:
- The resulting array
-
merge
@Nonnull IntArray merge(@Nonnull IntArray a, @Nonnull IntBinaryOperator f) throws IllegalArgumentException Between this array and the provided arraya, this applies the merger functionfto each corresponding pair of elements, then returns a new array containing the return values of the merger functionf. In other words, this merges the two arrays into a new array using the provided merger functionf.- Parameters:
a- The array of which to merge this array withf- The merger function to handle the merging of the two arrays- Returns:
- The resulting array
- Throws:
IllegalArgumentException- When the provided arraya's length is different from that of this array's length
-
append
Append the provided arrayato the end of this array, then returns the resulting array.- Parameters:
a- The array of which to append to the end of this array- Returns:
- The appended array
-
prepend
Prepends the provided arrayato the front of this array, then returns the resulting array.- Parameters:
a- The array of which to prepend to the front of this array- Returns:
- The prepended array
-
iterator
Returns an iterator over every element of this array. -
forEach
Executes the provided actionaonce for each element of this array. A reference to the element is provided as the first parameter of the action. -
forEach
Executes the provided actionaonce for each element of this array. The index of the element is provided as the first parameter of the action, and a reference to the element is provided as the second parameter of the action. -
array
@Nonnull int[] array()Returns a primitive array containing the elements of this array in their proper order.- Returns:
- The primitive array representation of this array
-
stream
Returns a stream whose source is the elements of this array.- Returns:
- A stream whose source is the elements of this array
- See Also:
-
list
Returns an unmodifiable list containing the elements of this array in their proper order.- Specified by:
listin interfaceBaseArray<Integer>- Returns:
- The list representation of this array
- Throws:
NullPointerException- When this array contains at least one instance ofnull- See Also:
-
tuple
Returns a tuple containing the elements of this array in their proper order. Unlikelist(), this operation cannot fail as tuples inherently support the usage ofnullas their values.- Returns:
- The tuple representation of this array
- See Also:
-
boxed
Returns an array containing the elements of this array in their boxed form.- Returns:
- The boxed object representation of this array
- See Also:
-
equals
Checks for equality between this array and the provided objectobj. -
toString
Serializes this array into a string.
-