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

public interface Tuple<E> extends Iterable<E>, BaseTuple<E>
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 Type
    Method
    Description
    E[]
    Returns an array containing the elements of this tuple in their proper order.
    boolean
    Returns whether this tuple contains the provided object obj.
    boolean
    Returns whether this tuple contains multiple objects.
    static <E> Tuple<E>
    copyOf(Collection<? extends E> c)
    Creates a new tuple from an existing collection.
    boolean
    Checks for equality between this tuple and the provided object obj.
    default Tuple<E>
    filter(Predicate<? super E> f)
    Tests each element of this tuple using the provided predicate f, collects all elements the predicate returns true to, then returns a new tuple containing only the filtered elements.
    void
    forEach(BiConsumer<? super Integer,? super E> a)
    Executes the provided action a once for each element of this tuple.
    void
    forEach(Consumer<? super E> a)
    Executes the provided action a once for each element of this tuple.
    get(int i)
    Returns the ith element of this tuple.
    Returns an iterator over every element of this tuple.
    Returns an unmodifiable list containing the elements of this tuple in their proper order.
    <F> Tuple<F>
    map(Function<? super E,? extends F> f)
    Applies the provided mapper function f to each element of this tuple, then returns a new tuple containing the return values of the function f.
    Applies the provided mapper function f to each element of this tuple, then returns a new tuple containing the return values of the function f.
    Applies the provided mapper function f to each element of this tuple, then returns a new tuple containing the return values of the function f.
    mapToInt(ToIntFunction<? super E> f)
    Applies the provided mapper function f to each element of this tuple, then returns a new tuple containing the return values of the function f.
    Applies the provided mapper function f to each element of this tuple, then returns a new tuple containing the return values of the function f.
    <F, G> Tuple<G>
    merge(Tuple<F> t, BiFunction<? super E,? super F,? extends G> f)
    Between this tuple and the provided tuple t, this applies the merger function f to each corresponding pair of elements, then returns a new tuple containing the return values of the merger function f.
    static <E> Tuple<E>
    of(E... elements)
    Creates a new tuple from the provided array of elements.
    default SafeArray<E>
    Returns a type-safe array containing the elements of this tuple in their proper order.
    int
    Returns the size of this tuple.
    Returns a stream whose source is the elements of this tuple.
    Serializes this tuple into a string.

    Methods inherited from interface java.lang.Iterable

    spliterator
  • Method Details

    • of

      @Nonnull @SafeVarargs static <E> Tuple<E> of(E... elements)
      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

      @Nonnull static <E> Tuple<E> copyOf(@Nonnull Collection<? extends E> c)
      Creates a new tuple from an existing collection.
      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)
      Specified by:
      size in interface BaseTuple<E>
      Returns:
      The number of components this tuple has
    • contains

      boolean contains(@Nullable Object obj)
      Returns whether this tuple contains the provided object obj.
      Parameters:
      obj - The object of which to check for containment
      Returns:
      true if at least one element of this tuple is equal to the provided object obj
    • containsAll

      boolean containsAll(@Nonnull Iterable<?> i)
      Returns whether this tuple contains multiple objects.
      Parameters:
      i - The iterable object of which to check for containment
      Returns:
      true if this tuple contains every element of the iterable object
    • get

      E get(int i) throws IndexOutOfBoundsException
      Returns the ith element of this tuple.
      Parameters:
      i - The index of the element to get
      Returns:
      The ith element of this tuple
      Throws:
      IndexOutOfBoundsException - When the index i is out of bounds
    • map

      @Nonnull <F> Tuple<F> map(@Nonnull Function<? super E,? extends F> f)
      Applies the provided mapper function f to each element of this tuple, then returns a new tuple containing the return values of the function f.
      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

      @Nonnull DoubleTuple mapToDouble(@Nonnull ToDoubleFunction<? super E> f)
      Applies the provided mapper function f to each element of this tuple, then returns a new tuple containing the return values of the function f.
      Parameters:
      f - The function of which to apply to each element of this tuple
      Returns:
      The resulting double tuple
    • mapToFloat

      @Nonnull FloatTuple mapToFloat(@Nonnull ToFloatFunction<? super E> f)
      Applies the provided mapper function f to each element of this tuple, then returns a new tuple containing the return values of the function f.
      Parameters:
      f - The function of which to apply to each element of this tuple
      Returns:
      The resulting double tuple
    • mapToLong

      @Nonnull LongTuple mapToLong(@Nonnull ToLongFunction<? super E> f)
      Applies the provided mapper function f to each element of this tuple, then returns a new tuple containing the return values of the function f.
      Parameters:
      f - The function of which to apply to each element of this tuple
      Returns:
      The resulting long tuple
    • mapToInt

      @Nonnull IntTuple mapToInt(@Nonnull ToIntFunction<? super E> f)
      Applies the provided mapper function f to each element of this tuple, then returns a new tuple containing the return values of the function f.
      Parameters:
      f - The function of which to apply to each element of this tuple
      Returns:
      The resulting int tuple
    • merge

      @Nonnull <F, G> Tuple<G> merge(@Nonnull Tuple<F> t, @Nonnull BiFunction<? super E,? super F,? extends G> f) throws IllegalArgumentException
      Between this tuple and the provided tuple t, this applies the merger function f to each corresponding pair of elements, then returns a new tuple containing the return values of the merger function f. In other words, this merges the two tuples into a new tuple using the provided merger function f.
      Type Parameters:
      F - The type of element to merge this tuple with
      G - The type of element to merge the two tuples to
      Parameters:
      t - The tuple of which to merge this tuple with
      f - The merger function to handle the merging of the two tuples
      Returns:
      The resulting tuple
      Throws:
      IllegalArgumentException - When the provided tuple t's size is different from that of this tuple's size
    • filter

      @Nonnull default Tuple<E> filter(@Nonnull Predicate<? super E> f)
      Tests each element of this tuple using the provided predicate f, collects all elements the predicate returns true to, 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

      @Nonnull Iterator<E> iterator()
      Returns an iterator over every element of this tuple.
      Specified by:
      iterator in interface Iterable<E>
      Returns:
      An iterator over every element of this tuple
    • forEach

      void forEach(@Nonnull Consumer<? super E> a)
      Executes the provided action a once for each element of this tuple. A reference to the element is provided as the first parameter of the action.
      Specified by:
      forEach in interface Iterable<E>
      Parameters:
      a - The action to be performed for each element
    • forEach

      void forEach(@Nonnull BiConsumer<? super Integer,? super E> a)
      Executes the provided action a once 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

      @Nonnull E[] array()
      Returns an array containing the elements of this tuple in their proper order.
      Returns:
      The array representation of this tuple
    • safeArray

      @Nonnull default SafeArray<E> safeArray()
      Returns a type-safe array containing the elements of this tuple in their proper order.
      Returns:
      The array representation of this tuple
    • stream

      @Nonnull Stream<E> stream()
      Returns a stream whose source is the elements of this tuple.
      Returns:
      A stream whose source is the elements of this tuple
    • list

      @Nonnull List<E> list()
      Returns an unmodifiable list containing the elements of this tuple in their proper order.
      Specified by:
      list in interface BaseTuple<E>
      Returns:
      The list representation of this tuple
      Throws:
      NullPointerException - When this tuple contains at least one instance of null
    • equals

      boolean equals(@Nullable Object obj)
      Checks for equality between this tuple and the provided object obj.
      Overrides:
      equals in class Object
      Parameters:
      obj - The object to compare to
      Returns:
      true if the other object is also a tuple, and the number of elements, the order of the elements, and the elements' values are all equal
    • toString

      @Nonnull String toString()
      Serializes this tuple into a string.
      Overrides:
      toString in class Object
      Returns:
      The string representation of this tuple