Package civitas.celestis.util.array
Class FloatFastArray
java.lang.Object
civitas.celestis.util.array.FloatFastArray
- All Implemented Interfaces:
BaseArray<Float>,FloatArray,Serializable,Iterable<Float>
A basic float array with no built-in synchronization or thread-safety measures.
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedFloatFastArray(float[] array) Creates a new fast float array.FloatFastArray(int length) Creates a new fast float array.Creates a new fast float array.FloatFastArray(Float[] values) Creates a new fast float array. -
Method Summary
Modifier and TypeMethodDescriptionfloat[]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(float v) Returns whether this array contains the provided valuev.booleancontainsAll(Iterable<Float> i) Returns whether this array contains multiple objects.booleanChecks for equality between this array and the provided objectobj.voidfill(float v) Fills this array with the provided valuev.voidfillRange(int s, int e, float v) Fills every slot of this array between the range of[s, e)with the provided valuev.voidforEach(BiConsumer<? super Integer, ? super Float> a) Executes the provided actionaonce for each element of this array.voidExecutes the provided actionaonce for each element of this array.floatget(int i) Returns theith element of this array.inthashCode()Returns the hash code of this instance.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(FloatFunction<? 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.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.voidreplaceAll(float oldValue, float newValue) Replaces all instances of the old value to the new value.voidreplaceFirst(float oldValue, float newValue) Replaces only the first instance of the old value to the new value.voidreplaceLast(float oldValue, float 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, float e) Sets theith element of this array.voidsetRange(int s, int e, FloatArray a) Sets 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 Float> 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, FloatUnaryOperator f) Updates theith element of this array with the provided update functionf.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.voidupdate(BiFunction<? super Integer, ? super Float, Float> 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.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface civitas.celestis.util.array.FloatArray
append, filter, prependMethods inherited from interface java.lang.Iterable
spliterator
-
Field Details
-
values
@Nonnull protected final float[] valuesThe internal array of values.
-
-
Constructor Details
-
FloatFastArray
public FloatFastArray(int length) Creates a new fast float array.- Parameters:
length- The length to initialize this array to
-
FloatFastArray
Creates a new fast float array.- Parameters:
a- The array of which to copy elements from
-
FloatFastArray
Creates a new fast float array.- Parameters:
values- The value this array should contain
-
FloatFastArray
protected FloatFastArray(@Nonnull float[] array) Creates a new fast float array. This is a direct assignment constructor, and thus is hidden to ensure safe usage.- Parameters:
array- The array of which to directly assign as the internal array
-
-
Method Details
-
length
public int length()Returns the length of this array.- Specified by:
lengthin interfaceBaseArray<Float>- Specified by:
lengthin interfaceFloatArray- Returns:
- The number of elements this array contains
-
contains
public boolean contains(float v) Returns whether this array contains the provided valuev.- Specified by:
containsin interfaceFloatArray- 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.- Specified by:
containsAllin interfaceFloatArray- 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.- Specified by:
getin interfaceFloatArray- 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.- Specified by:
setin interfaceFloatArray- 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.- Specified by:
updatein interfaceFloatArray- 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
public void fill(float v) Fills this array with the provided valuev. Every element will be reassigned.- Specified by:
fillin interfaceFloatArray- Parameters:
v- The value to fill this array with
-
fillRange
public void fillRange(int s, int e, float v) Fills every slot of this array between the range of[s, e)with the provided valuev.- Specified by:
fillRangein interfaceFloatArray- 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
-
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.- Specified by:
updatein interfaceFloatArray- 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.- Specified by:
updatein interfaceFloatArray- Parameters:
f- The function of which to apply to each element of this array
-
replaceAll
public void replaceAll(float oldValue, float newValue) Replaces all instances of the old value to the new value.- Specified by:
replaceAllin interfaceFloatArray- Parameters:
oldValue- The old value to replacenewValue- The new value to replace to
-
replaceFirst
public void replaceFirst(float oldValue, float newValue) Replaces only the first instance of the old value to the new value. (starting from index0, and incrementing upwards)- Specified by:
replaceFirstin interfaceFloatArray- Parameters:
oldValue- The old value to replacenewValue- The new value to replace to
-
replaceLast
public void replaceLast(float oldValue, float newValue) Replaces only the last instance of the old value to the new value. (starting from the last index, and decrementing downwards)- Specified by:
replaceLastin interfaceFloatArray- 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.- Specified by:
subArrayin interfaceFloatArray- 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.- Specified by:
setRangein interfaceFloatArray- 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.- Specified by:
resizein interfaceFloatArray- Parameters:
size- The size to resize this array to- Returns:
- The resized array
-
shuffle
public void shuffle()Shuffles this array, randomizing its elements' order.- Specified by:
shufflein interfaceBaseArray<Float>- Specified by:
shufflein interfaceFloatArray
-
sort
public void sort()Sorts this array by its natural ascending order.- Specified by:
sortin interfaceBaseArray<Float>- Specified by:
sortin interfaceFloatArray
-
sort
Sorts this array using the provided comparator functionc.- Specified by:
sortin interfaceBaseArray<Float>- Specified by:
sortin interfaceFloatArray- Parameters:
c- The comparator function of which to sort this array with
-
map
Applies the provided mapper functionfto each element of this array, then returns a new array containing the return values of the functionf.- Specified by:
mapin interfaceFloatArray- 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.- Specified by:
mapToObjin interfaceFloatArray- 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 public FloatArray merge(@Nonnull FloatArray a, @Nonnull FloatBinaryOperator 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.- Specified by:
mergein interfaceFloatArray- 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
-
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.- Specified by:
forEachin interfaceBaseArray<Float>- Specified by:
forEachin interfaceFloatArray- Parameters:
a- The action to be performed for each element
-
array
@Nonnull public float[] array()Returns a primitive array containing the elements of this array in their proper order.- Specified by:
arrayin interfaceFloatArray- Returns:
- The primitive array representation of this array
-
stream
Returns a stream whose source is the elements of this array.- Specified by:
streamin interfaceFloatArray- 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<Float>- Specified by:
listin interfaceFloatArray- Returns:
- The list representation of this array
- See Also:
-
tuple
Returns a tuple containing the elements of this array in their proper order. UnlikeFloatArray.list(), this operation cannot fail as tuples inherently support the usage ofnullas their values.- Specified by:
tuplein interfaceFloatArray- Returns:
- The tuple representation of this array
- See Also:
-
boxed
Returns an array containing the elements of this array in their boxed form.- Specified by:
boxedin interfaceFloatArray- Returns:
- The boxed object representation of this array
- See Also:
-
equals
Checks for equality between this array and the provided objectobj.- Specified by:
equalsin interfaceFloatArray- Overrides:
equalsin classObject- Parameters:
obj- The object to compare to- Returns:
trueif the object is also a float array, and the number of elements, the order of the elements, and the elements' values are all equal
-
toString
Serializes this array into a string.- Specified by:
toStringin interfaceFloatArray- Overrides:
toStringin classObject- Returns:
- The string representation of this array
-
hashCode
public int hashCode()Returns the hash code of this instance.
-