Triple¶
- public abstract class org.apache.commons.lang3.tuple.Triple<L, M, R> implements Comparable<Triple<L, M, R>>, Serializable[source]¶
A triple consisting of three elements.
This class is an abstract implementation defining the basic API. It refers to the elements as ‘left’, ‘middle’ and ‘right’.
Subclass implementations may be mutable or immutable. However, there is no restriction on the type of the stored objects that may be stored. If mutable objects are stored in the triple, then the triple itself effectively becomes mutable.
- Parameters:
<L> – The left element type.
<M> – The middle element type.
<R> – The right element type.
- Since:
3.2
Constructors¶
Constructs a new instance. |
Fields and constants¶
An empty array. |
- public static final Triple<?, ?, ?>[] EMPTY_ARRAY[source]¶
An empty array.
Consider using
#emptyArray()to avoid generics warnings.- Since:
3.10
Methods¶
Compares the triple based on the left element, followed by the middle element, finally the right element. |
|
Returns the empty array singleton that can be assigned without compiler warning. |
|
Compares this triple to another based on the three elements. |
|
Gets the left element from this triple. |
|
Gets the middle element from this triple. |
|
Gets the right element from this triple. |
|
Returns a suitable hash code. |
|
Obtains an immutable triple of three objects inferring the generic types. |
|
Obtains an immutable triple of three non-null objects inferring the generic types. |
|
Returns a String representation of this triple using the format |
|
Formats the receiver using the given format. |
- @Override public int compareTo(Triple<L, M, R> other)[source]¶
Compares the triple based on the left element, followed by the middle element, finally the right element. The types must be
Comparable.- Parameters:
other – The other triple, not null.
- Returns:
negative if this is less, zero if equal, positive if greater.
- @SuppressWarnings({"unchecked"}) public static <L, M, R> Triple<L, M, R>[] emptyArray()[source]¶
Returns the empty array singleton that can be assigned without compiler warning.
- Type parameters:
<L> – The left element type.
<M> – The middle element type.
<R> – The right element type.
- Returns:
The empty array singleton that can be assigned without compiler warning.
- Since:
3.10
- @Override public boolean equals(Object obj)[source]¶
Compares this triple to another based on the three elements.
- Parameters:
obj – The object to compare to, null returns false.
- Returns:
true if the elements of the triple are equal.
- public abstract L getLeft()[source]¶
Gets the left element from this triple.
- Returns:
The left element, may be null.
- public abstract M getMiddle()[source]¶
Gets the middle element from this triple.
- Returns:
The middle element, may be null.
- public abstract R getRight()[source]¶
Gets the right element from this triple.
- Returns:
The right element, may be null.
- @Override public int hashCode()[source]¶
Returns a suitable hash code.
The hash code is adapted from the definition in
Map.Entry.- Returns:
The hash code.
- public static <L, M, R> Triple<L, M, R> of(L left, M middle, R right)[source]¶
Obtains an immutable triple of three objects inferring the generic types.
- Type parameters:
<L> – The left element type.
<M> – The middle element type.
<R> – The right element type.
- Parameters:
left – The left element, may be null.
middle – The middle element, may be null.
right – The right element, may be null.
- Returns:
An immutable triple formed from the three parameters, not null.
- public static <L, M, R> Triple<L, M, R> ofNonNull(L left, M middle, R right)[source]¶
Obtains an immutable triple of three non-null objects inferring the generic types.
- Type parameters:
<L> – The left element type.
<M> – The middle element type.
<R> – The right element type.
- Parameters:
left – The left element, may not be null.
middle – The middle element, may not be null.
right – The right element, may not be null.
- Returns:
An immutable triple formed from the three parameters, not null.
- Throws:
java.lang.NullPointerException – Thrown if any input is null.
- Since:
3.13.0
- @Override public String toString()[source]¶
Returns a String representation of this triple using the format
(left,middle,right).- Returns:
A string describing this object, not null.
- public String toString(String format)[source]¶
Formats the receiver using the given format.
This uses
java.util.Formattableto perform the formatting. Three variables may be used to embed the left and right elements. Use%1$sfor the left element,%2$sfor the middle and%3$sfor the right element. The default format used bytoString()is(%1$s,%2$s,%3$s).- Parameters:
format – The format string, optionally containing
%1$s,%2$sand%3$s, not null.- Returns:
The formatted string, not null.