L
- the left element typeM
- the middle element typeR
- the right element typepublic abstract class Triple<L,M,R> extends java.lang.Object implements java.lang.Comparable<Triple<L,M,R>>, java.io.Serializable
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.
Modifier and Type | Field and Description |
---|---|
static Triple<?,?,?>[] |
EMPTY_ARRAY
An empty array.
|
Constructor and Description |
---|
Triple() |
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Triple<L,M,R> other)
Compares the triple based on the left element, followed by the middle element,
finally the right element.
|
static <L,M,R> Triple<L,M,R>[] |
emptyArray()
Returns the empty array singleton that can be assigned without compiler warning.
|
boolean |
equals(java.lang.Object obj)
Compares this triple to another based on the three elements.
|
abstract L |
getLeft()
Gets the left element from this triple.
|
abstract M |
getMiddle()
Gets the middle element from this triple.
|
abstract R |
getRight()
Gets the right element from this triple.
|
int |
hashCode()
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.
|
java.lang.String |
toString()
Returns a String representation of this triple using the format
($left,$middle,$right) . |
java.lang.String |
toString(java.lang.String format)
Formats the receiver using the given format.
|
public static final Triple<?,?,?>[] EMPTY_ARRAY
Consider using emptyArray()
to avoid generics warnings.
public static <L,M,R> Triple<L,M,R>[] emptyArray()
L
- the left element typeM
- the middle element typeR
- the right element typepublic static <L,M,R> Triple<L,M,R> of(L left, M middle, R right)
This factory allows the triple to be created using inference to obtain the generic types.
L
- the left element typeM
- the middle element typeR
- the right element typeleft
- the left element, may be nullmiddle
- the middle element, may be nullright
- the right element, may be nullpublic static <L,M,R> Triple<L,M,R> ofNonNull(L left, M middle, R right)
This factory allows the triple to be created using inference to obtain the generic types.
L
- the left element typeM
- the middle element typeR
- the right element typeleft
- the left element, may not be nullmiddle
- the middle element, may not be nullright
- the right element, may not be nulljava.lang.NullPointerException
- if any input is nullpublic int compareTo(Triple<L,M,R> other)
Comparable
.public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
obj
- the object to compare to, null returns falsepublic abstract L getLeft()
public abstract M getMiddle()
public abstract R getRight()
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
($left,$middle,$right)
.toString
in class java.lang.Object
public java.lang.String toString(java.lang.String format)
This uses Formattable
to perform the formatting. Three variables may
be used to embed the left and right elements. Use %1$s
for the left
element, %2$s
for the middle and %3$s
for the right element.
The default format used by toString()
is (%1$s,%2$s,%3$s)
.
format
- the format string, optionally containing %1$s
, %2$s
and %3$s
, not nullCopyright © 2010 - 2023 Adobe. All Rights Reserved