Class Triple<A,​B,​C>

  • Type Parameters:
    A - the first element type
    B - the second element type
    C - the third element type
    All Implemented Interfaces:
    Tuple, Serializable, Comparable<Triple<A,​B,​C>>, org.joda.beans.Bean, org.joda.beans.ImmutableBean

    public final class Triple<A,​B,​C>
    extends Object
    implements org.joda.beans.ImmutableBean, Tuple, Comparable<Triple<A,​B,​C>>, Serializable
    An immutable triple consisting of three elements.

    This implementation refers to the elements as 'first', 'second' and 'third'. The elements cannot be null.

    Although the implementation is immutable, there is no restriction on the objects that may be stored. If mutable objects are stored in the triple, then the triple itself effectively becomes mutable.

    This class is immutable and thread-safe if the stored objects are immutable.

    See Also:
    Serialized Form
    • Method Detail

      • of

        public static <A,​B,​C> Triple<A,​B,​C> of​(A first,
                                                                       B second,
                                                                       C third)
        Obtains a triple inferring the types.
        Type Parameters:
        A - the first element type
        B - the second element type
        C - the third element type
        Parameters:
        first - the first element
        second - the second element
        third - the third element
        Returns:
        a triple formed from the three parameters
      • combining

        public static <A,​B,​C> BinaryOperator<Triple<A,​B,​C>> combining​(BiFunction<? super A,​? super A,​? extends A> combinerFirst,
                                                                                              BiFunction<? super B,​? super B,​? extends B> combinerSecond,
                                                                                              BiFunction<? super C,​? super C,​? extends C> combinerThird)
        Returns a combiner of triple instances.

        This is useful if you have a stream of Triple<A, B, C> and would like to call reduce.

        e.g

        tripleList.stream()
             .reduce(Triple.combining(A::combinedWith, B::combinedWith, C::combinedWith))
         
        Type Parameters:
        A - the type of the first values
        B - the type of the second values
        C - the type of the third values
        Parameters:
        combinerFirst - the combiner of first values
        combinerSecond - the combiner of second values
        combinerThird - the combiner of third values
        Returns:
        the combiner of triple instances
      • combinedWith

        public <Q,​R,​S> Triple<A,​B,​C> combinedWith​(Triple<Q,​R,​S> other,
                                                                          BiFunction<? super A,​? super Q,​? extends A> combinerFirst,
                                                                          BiFunction<? super B,​? super R,​? extends B> combinerSecond,
                                                                          BiFunction<? super C,​? super S,​? extends C> combinerThird)
        Combines this instance with another.
        Type Parameters:
        Q - the type of the first value in the other instance
        R - the type of the second value in the other instance
        S - the type of the third value in the other instance
        Parameters:
        other - the other triple
        combinerFirst - the combiner of first values
        combinerSecond - the combiner of second values
        combinerThird - the combiner of third values
        Returns:
        the combined triple instance
      • size

        public int size()
        Gets the number of elements held by this triple.
        Specified by:
        size in interface Tuple
        Returns:
        size 3
      • elements

        public ImmutableList<Object> elements()
        Gets the elements from this triple as a list.

        The list returns each element in the triple in order.

        Specified by:
        elements in interface Tuple
        Returns:
        the elements as an immutable list
      • compareTo

        public int compareTo​(Triple<A,​B,​C> other)
        Compares the triple based on the first element followed by the second element followed by the third element.

        The element types must be Comparable.

        Specified by:
        compareTo in interface Comparable<A>
        Parameters:
        other - the other triple
        Returns:
        negative if this is less, zero if equal, positive if greater
        Throws:
        ClassCastException - if either object is not comparable
      • toString

        public String toString()
        Gets the triple using a standard string format.

        The standard format is '[$first, $second, $third]'. Spaces around the values are trimmed.

        Overrides:
        toString in class Object
        Returns:
        the triple as a string
      • meta

        public static Triple.Meta meta()
        The meta-bean for Triple.
        Returns:
        the meta-bean, not null
      • metaTriple

        public static <R,​S,​T> Triple.Meta<R,​S,​T> metaTriple​(Class<R> cls1,
                                                                                    Class<S> cls2,
                                                                                    Class<T> cls3)
        The meta-bean for Triple.
        Type Parameters:
        R - the first generic type
        S - the second generic type
        T - the second generic type
        Parameters:
        cls1 - the first generic type
        cls2 - the second generic type
        cls3 - the third generic type
        Returns:
        the meta-bean, not null
      • metaBean

        public Triple.Meta<A,​B,​C> metaBean()
        Specified by:
        metaBean in interface org.joda.beans.Bean
      • getFirst

        public A getFirst()
        Gets the first element in this triple.
        Returns:
        the value of the property, not null
      • getSecond

        public B getSecond()
        Gets the second element in this triple.
        Returns:
        the value of the property, not null
      • getThird

        public C getThird()
        Gets the third element in this triple.
        Returns:
        the value of the property, not null
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object