Top Description Fields Constructors Methods
org.apache.commons.lang3.tuple

public abstract Class Triple<L, M, R>

extends Object
implements Comparable<Triple<L, M, R>>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.lang.Comparable
Known Direct Subclasses
org.apache.commons.lang3.tuple.ImmutableTriple, org.apache.commons.lang3.tuple.MutableTriple
Type Parameters
<L>
the left element type.
<M>
the middle element type.
<R>
the right element type.
Imports
java.io.Serializable, java.util.Objects, org.apache.commons.lang3.builder.CompareToBuilder

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.

Since
3.2

Field Summary

Modifier and TypeField and Description
public static final Triple<?, ?, ?>[]
EMPTY_ARRAY

An empty array.

private static final long
serialVersionUID

Serialization version

Constructor Summary

AccessConstructor and Description
public
Triple()

Constructs a new instance.

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

negative if this is less, zero if equal, positive if greater.
compareTo
(final Triple<L, M, R>
the other triple, not null.
other
)

Implements java.lang.Comparable.compareTo.

Compares the triple based on the left element, followed by the middle element, finally the right element.

public static <
the left element type.
L
,
the middle element type.
M
,
the right element type.
R
>
Triple<L, M, R>[]

Returns:

the empty array singleton that can be assigned without compiler warning.
emptyArray
()

Returns the empty array singleton that can be assigned without compiler warning.

public boolean

Returns:

true if the elements of the triple are equal.
equals
(final Object
the object to compare to, null returns false.
obj
)

Overrides java.lang.Object.equals.

Compares this triple to another based on the three elements.

public abstract L

Returns:

the left element, may be null.
getLeft
()

Gets the left element from this triple.

public abstract M

Returns:

the middle element, may be null.
getMiddle
()

Gets the middle element from this triple.

public abstract R

Returns:

the right element, may be null.
getRight
()

Gets the right element from this triple.

public int

Returns:

the hash code.
hashCode
()

Overrides java.lang.Object.hashCode.

Returns a suitable hash code.

public static <
the left element type.
L
,
the middle element type.
M
,
the right element type.
R
>
Triple<L, M, R>

Returns:

an immutable triple formed from the three parameters, not null.
of
(final L
the left element, may be null.
left
,
final M
the middle element, may be null.
middle
,
final R
the right element, may be null.
right
)

Obtains an immutable triple of three objects inferring the generic types.

public static <
the left element type.
L
,
the middle element type.
M
,
the right element type.
R
>
Triple<L, M, R>

Returns:

an immutable triple formed from the three parameters, not null.
ofNonNull
(final L
the left element, may not be null.
left
,
final M
the middle element, may not be null.
middle
,
final R
the right element, may not be null.
right
)

Obtains an immutable triple of three non-null objects inferring the generic types.

public String

Returns:

a string describing this object, not null.
toString
()

Overrides java.lang.Object.toString.

Returns a String representation of this triple using the format (left,middle,right).

public String

Returns:

the formatted string, not null.
toString
(final String
the format string, optionally containing %1$s, %2$s and %3$s, not null.
format
)

Formats the receiver using the given format.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

EMPTY_ARRAYback to summary
public static final Triple<?, ?, ?>[] EMPTY_ARRAY

An empty array.

Consider using emptyArray() to avoid generics warnings.

Since
3.10
serialVersionUIDback to summary
private static final long serialVersionUID

Serialization version

Constructor Detail

Tripleback to summary
public Triple()

Constructs a new instance.

Method Detail

compareToback to summary
public int compareTo(final Triple<L, M, R> other)

Implements java.lang.Comparable.compareTo.

Compares the triple based on the left element, followed by the middle element, finally the right element. The types must be Comparable.

Parameters
other:Triple<L, M, R>

the other triple, not null.

Returns:int

negative if this is less, zero if equal, positive if greater.

Annotations
@Override
emptyArrayback to summary
public static <L, M, R> Triple<L, M, R>[] emptyArray()

Returns the empty array singleton that can be assigned without compiler warning.

Parameters
<L>
the left element type.
<M>
the middle element type.
<R>
the right element type.
Returns:Triple<L, M, R>[]

the empty array singleton that can be assigned without compiler warning.

Annotations
@SuppressWarnings:unchecked
Since
3.10
equalsback to summary
public boolean equals(final Object obj)

Overrides java.lang.Object.equals.

Compares this triple to another based on the three elements.

Parameters
obj:Object

the object to compare to, null returns false.

Returns:boolean

true if the elements of the triple are equal.

Annotations
@Override
getLeftback to summary
public abstract L getLeft()

Gets the left element from this triple.

Returns:L

the left element, may be null.

getMiddleback to summary
public abstract M getMiddle()

Gets the middle element from this triple.

Returns:M

the middle element, may be null.

getRightback to summary
public abstract R getRight()

Gets the right element from this triple.

Returns:R

the right element, may be null.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Returns a suitable hash code.

The hash code is adapted from the definition in Map.Entry.

Returns:int

the hash code.

Annotations
@Override
ofback to summary
public static <L, M, R> Triple<L, M, R> of(final L left, final M middle, final R right)

Obtains an immutable triple of three objects inferring the generic types.

Parameters
<L>
the left element type.
<M>
the middle element type.
<R>
the right element type.
left:L

the left element, may be null.

middle:M

the middle element, may be null.

right:R

the right element, may be null.

Returns:Triple<L, M, R>

an immutable triple formed from the three parameters, not null.

ofNonNullback to summary
public static <L, M, R> Triple<L, M, R> ofNonNull(final L left, final M middle, final R right)

Obtains an immutable triple of three non-null objects inferring the generic types.

Parameters
<L>
the left element type.
<M>
the middle element type.
<R>
the right element type.
left:L

the left element, may not be null.

middle:M

the middle element, may not be null.

right:R

the right element, may not be null.

Returns:Triple<L, M, R>

an immutable triple formed from the three parameters, not null.

Exceptions
NullPointerException:
if any input is null.
Since
3.13.0
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a String representation of this triple using the format (left,middle,right).

Returns:String

a string describing this object, not null.

Annotations
@Override
toStringback to summary
public String toString(final String format)

Formats the receiver using the given format.

This uses java.util.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).

Parameters
format:String

the format string, optionally containing %1$s, %2$s and %3$s, not null.

Returns:String

the formatted string, not null.