A
- Class type for the first elementB
- Class type for the second elementpublic class Pair<A,B> extends Object implements Comparable<Object>
A tuple consisting of two elements. There is no restriction on the type of the objects that may be stored.
Example:
Map<String, Object> map = new LinkedHashMap<>();
map.put("parameter", "value");
Integer number = new Integer(3);
Pair<Map<String, Object>, Integer> data = new Pair<>(map, number);
Map<String, Object> myMap = data.getFirst();
Integer myNumber = data.getSecond();
Constructor and Description |
---|
Pair(A a,
B b,
boolean isModifiable)
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Object o) |
boolean |
equals(Object o)
Indicates whether some other object is "equal to" this one.
|
A |
getFirst()
Returns the first element from this pair.
|
B |
getSecond()
Returns the second element from this pair.
|
int |
hashCode()
Returns a hash code value for the object.
|
boolean |
isModifiable()
Indicates whether or not elements from the pair can be changed after initialization.
|
static <A,B> Pair<A,B> |
of(A a,
B b)
This factory allows a pair to be created using inference to obtain the generic types.
|
void |
setFirst(A a)
Sets the first element from this pair.
|
void |
setSecond(B b)
Sets the second element from this pair.
|
String |
toString()
Returns a
String representation of this pair using the format (first, second). |
static <A,B> Pair<A,B> |
unmodifiableOf(A a,
B b)
This factory allows an unmodifiable pair to be created using inference to obtain the generic types.
|
public int compareTo(Object o)
compareTo
in interface Comparable<Object>
public boolean equals(Object o)
public A getFirst()
public B getSecond()
public int hashCode()
HashMap
.public boolean isModifiable()
true
if the element can be changed. Otherwise, false
public static <A,B> Pair<A,B> of(A a, B b)
A
- Class type for the first elementB
- Class type for the second elementa
- The first element, may be null
b
- The second element, may be null
public void setFirst(A a)
a
- The first element, may be null
public void setSecond(B b)
b
- The second element, may be null
public String toString()
String
representation of this pair using the format (first, second).public static <A,B> Pair<A,B> unmodifiableOf(A a, B b)
A
- Class type for the first elementB
- Class type for the second elementa
- The first element, may be null
b
- The second element, may be null
Copyright © 2018. All rights reserved.