Package civitas.celestis.util.tuple
Interface Tuple<E>
- Type Parameters:
E- The type of element this tuple should hold
- All Superinterfaces:
BaseTuple<E>,Iterable<E>,Serializable
- All Known Subinterfaces:
BigVector<N,,D, V, DV, PV> DecimalVector<V,,PV> IntegerVector<V,DV, PV>
- All Known Implementing Classes:
ArrayTuple,Decimal2,Decimal3,Decimal4,DecimalQuaternion,Integer2,Integer3,Integer4,Object1,Object2,Object3,Object4
A shallowly immutable set of objects. Tuples cannot be resized after instantiation,
and support the usage of
null values. The shallow immutability of tuples makes
them fundamentally thread-safe, as long as the underlying elements are thread-safe.
Primitive types are supported by specialized tuple instances such as DoubleTuple
or FloatTuple. Primitive tuple instances can be obtained either though factory
methods such as DoubleTuple.of(double...) or primitive mapper methods such as
mapToDouble(ToDoubleFunction) or mapToFloat(ToFloatFunction).
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionE[]array()Returns an array containing the elements of this tuple in their proper order.booleanReturns whether this tuple contains the provided objectobj.booleancontainsAll(Iterable<?> i) Returns whether this tuple contains multiple objects.static <E> Tuple<E>copyOf(Collection<? extends E> c) Creates a new tuple from an existingcollection.booleanChecks for equality between this tuple and the provided objectobj.Tests each element of this tuple using the provided predicatef, collects all elements the predicate returnstrueto, then returns a new tuple containing only the filtered elements.voidforEach(BiConsumer<? super Integer, ? super E> a) Executes the provided actionaonce for each element of this tuple.voidExecutes the provided actionaonce for each element of this tuple.get(int i) Returns theith element of this tuple.iterator()Returns an iterator over every element of this tuple.list()Returns an unmodifiable list containing the elements of this tuple in their proper order.<F> Tuple<F>Applies the provided mapper functionfto each element of this tuple, then returns a new tuple containing the return values of the functionf.mapToDouble(ToDoubleFunction<? super E> f) Applies the provided mapper functionfto each element of this tuple, then returns a new tuple containing the return values of the functionf.mapToFloat(ToFloatFunction<? super E> f) Applies the provided mapper functionfto each element of this tuple, then returns a new tuple containing the return values of the functionf.mapToInt(ToIntFunction<? super E> f) Applies the provided mapper functionfto each element of this tuple, then returns a new tuple containing the return values of the functionf.mapToLong(ToLongFunction<? super E> f) Applies the provided mapper functionfto each element of this tuple, then returns a new tuple containing the return values of the functionf.<F,G> Tuple<G> merge(Tuple<F> t, BiFunction<? super E, ? super F, ? extends G> f) Between this tuple and the provided tuplet, this applies the merger functionfto each corresponding pair of elements, then returns a new tuple containing the return values of the merger functionf.static <E> Tuple<E>of(E... elements) Creates a new tuple from the provided array of elements.Returns a type-safe array containing the elements of this tuple in their proper order.intsize()Returns the size of this tuple.stream()Returns a stream whose source is the elements of this tuple.toString()Serializes this tuple into a string.Methods inherited from interface java.lang.Iterable
spliterator
-
Method Details
-
of
Creates a new tuple from the provided array of elements.- Type Parameters:
E- The type of element to contain- Parameters:
elements- The elements of which to construct the tuple from- Returns:
- A tuple constructed from the provided elements
-
copyOf
Creates a new tuple from an existingcollection.- Type Parameters:
E- The type of element to copy- Parameters:
c- The collection of which to copy elements from- Returns:
- A tuple constructed from the provided collection
-
size
int size()Returns the size of this tuple. (the number of components it has) -
contains
Returns whether this tuple contains the provided objectobj.- Parameters:
obj- The object of which to check for containment- Returns:
trueif at least one element of this tuple is equal to the provided objectobj
-
containsAll
Returns whether this tuple contains multiple objects.- Parameters:
i- The iterable object of which to check for containment- Returns:
trueif this tuple contains every element of the iterable object
-
get
Returns theith element of this tuple.- Parameters:
i- The index of the element to get- Returns:
- The
ith element of this tuple - Throws:
IndexOutOfBoundsException- When the indexiis out of bounds
-
map
Applies the provided mapper functionfto each element of this tuple, then returns a new tuple containing the return values of the functionf.- Type Parameters:
F- The type of component to map this tuple to- Parameters:
f- The function of which to apply to each element of this tuple- Returns:
- The resulting tuple
-
mapToDouble
Applies the provided mapper functionfto each element of this tuple, then returns a new tuple containing the return values of the functionf.- Parameters:
f- The function of which to apply to each element of this tuple- Returns:
- The resulting
doubletuple
-
mapToFloat
Applies the provided mapper functionfto each element of this tuple, then returns a new tuple containing the return values of the functionf.- Parameters:
f- The function of which to apply to each element of this tuple- Returns:
- The resulting
doubletuple
-
mapToLong
Applies the provided mapper functionfto each element of this tuple, then returns a new tuple containing the return values of the functionf.- Parameters:
f- The function of which to apply to each element of this tuple- Returns:
- The resulting
longtuple
-
mapToInt
Applies the provided mapper functionfto each element of this tuple, then returns a new tuple containing the return values of the functionf.- Parameters:
f- The function of which to apply to each element of this tuple- Returns:
- The resulting
inttuple
-
merge
@Nonnull <F,G> Tuple<G> merge(@Nonnull Tuple<F> t, @Nonnull BiFunction<? super E, ? super F, throws IllegalArgumentException? extends G> f) Between this tuple and the provided tuplet, this applies the merger functionfto each corresponding pair of elements, then returns a new tuple containing the return values of the merger functionf. In other words, this merges the two tuples into a new tuple using the provided merger functionf.- Type Parameters:
F- The type of element to merge this tuple withG- The type of element to merge the two tuples to- Parameters:
t- The tuple of which to merge this tuple withf- The merger function to handle the merging of the two tuples- Returns:
- The resulting tuple
- Throws:
IllegalArgumentException- When the provided tuplet's size is different from that of this tuple's size
-
filter
Tests each element of this tuple using the provided predicatef, collects all elements the predicate returnstrueto, then returns a new tuple containing only the filtered elements.- Parameters:
f- The predicate to use to filter this array- Returns:
- The filtered array
-
iterator
Returns an iterator over every element of this tuple. -
forEach
Executes the provided actionaonce for each element of this tuple. A reference to the element is provided as the first parameter of the action. -
forEach
Executes the provided actionaonce for each element of this tuple. 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.- Parameters:
a- The action to be performed for each element
-
array
Returns an array containing the elements of this tuple in their proper order.- Returns:
- The array representation of this tuple
-
safeArray
Returns a type-safe array containing the elements of this tuple in their proper order.- Returns:
- The array representation of this tuple
-
stream
Returns a stream whose source is the elements of this tuple.- Returns:
- A stream whose source is the elements of this tuple
-
list
Returns an unmodifiable list containing the elements of this tuple in their proper order.- Specified by:
listin interfaceBaseTuple<E>- Returns:
- The list representation of this tuple
- Throws:
NullPointerException- When this tuple contains at least one instance ofnull
-
equals
Checks for equality between this tuple and the provided objectobj. -
toString
Serializes this tuple into a string.
-