Class Triple<L,M,R>
- Type Parameters:
L- the left element typeM- the middle element typeR- the right element type
- All Implemented Interfaces:
Serializable,Comparable<Triple<L,,M, R>> NTuple
- Direct Known Subclasses:
ImmutableTriple,MutableTriple
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.
- Author:
- Chakib Daii
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintarity()Returns the number of elements contained in this tuple.intCompares the triple based on the left element, followed by the middle element, finally the right element.booleanChecks if the tuple contains the specified element.booleanCompares this triple to another based on the three elements.get(int index) Returns the element at the specified zero-based position.abstract LgetLeft()Gets the left element from this triple.abstract MGets the middle element from this triple.abstract RgetRight()Gets the right element from this triple.inthashCode()Returns a suitable hash code.static <L,M, R> Triple<L, M, R> of(L left, M middle, R right) Obtains an immutable triple of three objects inferring the generic types.static <L,M, R> Triple<L, M, R> ofNonNull(L left, M middle, R right) Obtains an immutable triple of three non-null objects inferring the generic types.Object[]toArray()Returns an array containing all elements of the tuple.toString()Returns a String representation of this triple using the format($left,$middle,$right).Formats the receiver using the given format.
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
-
Constructor Details
-
Triple
public Triple()Constructs a new instance.
-
-
Method Details
-
of
Obtains an immutable triple of three objects inferring the generic types.This factory allows the triple to be created using inference to obtain the generic types.
- Type Parameters:
L- the left element typeM- the middle element typeR- the right element type- Parameters:
left- the left element, may be nullmiddle- the middle element, may be nullright- the right element, may be null- Returns:
- a triple formed from the three parameters, not null
-
ofNonNull
Obtains an immutable triple of three non-null objects inferring the generic types.This factory allows the triple to be created using inference to obtain the generic types.
- Type Parameters:
L- the left element typeM- the middle element typeR- the right element type- Parameters:
left- the left element, may not be nullmiddle- the middle element, may not be nullright- the right element, may not be null- Returns:
- a triple formed from the three parameters, not null
- Throws:
NullPointerException- if any input is null
-
compareTo
Compares the triple based on the left element, followed by the middle element, finally the right element. The types must beComparable.- Specified by:
compareToin interfaceComparable<L>- Parameters:
other- the other triple, not null- Returns:
- negative if this is less, zero if equal, positive if greater
-
equals
Compares this triple to another based on the three elements. -
getLeft
Gets the left element from this triple.- Returns:
- the left element, may be null
-
getMiddle
Gets the middle element from this triple.- Returns:
- the middle element, may be null
-
getRight
Gets the right element from this triple.- Returns:
- the right element, may be null
-
hashCode
public int hashCode()Returns a suitable hash code. -
toString
Returns a String representation of this triple using the format($left,$middle,$right). -
toString
Formats the receiver using the given format.This uses
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
-
arity
public int arity()Returns the number of elements contained in this tuple. -
get
Returns the element at the specified zero-based position. -
toArray
Returns an array containing all elements of the tuple. -
contains
Checks if the tuple contains the specified element.
-