|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.commons.lang3.tuple.Pair<L,R>
L
- the left element typeR
- the right element typepublic abstract class Pair<L,R>
A pair consisting of two elements.
This class is an abstract implementation defining the basic API.
It refers to the elements as 'left' and 'right'. It also implements the
Map.Entry
interface where the key is 'left' and the value is '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 pair, then the pair itself effectively becomes mutable.
Constructor Summary | |
---|---|
Pair()
|
Method Summary | ||
---|---|---|
int |
compareTo(Pair<L,R> other)
Compares the pair based on the left element followed by the right element. |
|
boolean |
equals(Object obj)
Compares this pair to another based on the two elements. |
|
L |
getKey()
Gets the key from this pair. |
|
abstract L |
getLeft()
Gets the left element from this pair. |
|
abstract R |
getRight()
Gets the right element from this pair. |
|
R |
getValue()
Gets the value from this pair. |
|
int |
hashCode()
Returns a suitable hash code. |
|
static
|
of(L left,
R right)
Obtains an immutable pair of from two objects inferring the generic types. |
|
String |
toString()
Returns a String representation of this pair using the format ($left,$right) . |
|
String |
toString(String format)
Formats the receiver using the given format. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Map.Entry |
---|
setValue |
Constructor Detail |
---|
public Pair()
Method Detail |
---|
public static <L,R> Pair<L,R> of(L left, R right)
Obtains an immutable pair of from two objects inferring the generic types.
This factory allows the pair to be created using inference to obtain the generic types.
L
- the left element typeR
- the right element typeleft
- the left element, may be nullright
- the right element, may be null
public abstract L getLeft()
Gets the left element from this pair.
When treated as a key-value pair, this is the key.
public abstract R getRight()
Gets the right element from this pair.
When treated as a key-value pair, this is the value.
public final L getKey()
Gets the key from this pair.
This method implements the Map.Entry
interface returning the
left element as the key.
getKey
in interface Map.Entry<L,R>
public R getValue()
Gets the value from this pair.
This method implements the Map.Entry
interface returning the
right element as the value.
getValue
in interface Map.Entry<L,R>
public int compareTo(Pair<L,R> other)
Compares the pair based on the left element followed by the right element.
The types must be Comparable
.
compareTo
in interface Comparable<Pair<L,R>>
other
- the other pair, not null
public boolean equals(Object obj)
Compares this pair to another based on the two elements.
equals
in interface Map.Entry<L,R>
equals
in class Object
obj
- the object to compare to, null returns false
public int hashCode()
Returns a suitable hash code.
The hash code follows the definition in Map.Entry
.
hashCode
in interface Map.Entry<L,R>
hashCode
in class Object
public String toString()
Returns a String representation of this pair using the format ($left,$right)
.
toString
in class Object
public String toString(String format)
Formats the receiver using the given format.
This uses Formattable
to perform the formatting. Two variables may
be used to embed the left and right elements. Use %1$s
for the left
element (key) and %2$s
for the right element (value).
The default format used by toString()
is (%1$s,%2$s)
.
format
- the format string, optionally containing %1$s
and %2$s
, not null
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |