public final class Pair<T> extends Object implements Collection<T>, Serializable
Collection that stores exactly
2 non-null objects and is not mutable. They respect equals
and may be used as indices or map keys.Note that they do not protect from malevolent behavior: if one or another object in the tuple is mutable, then it can be changed with the usual bad effects.
| Constructor and Description |
|---|
Pair(Collection<? extends T> values)
Creates a Pair from the passed Collection.
|
Pair(T[] values)
Creates a
Pair from the passed array. |
Pair(T value1,
T value2)
Creates a
Pair from the specified elements. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(T o) |
boolean |
addAll(Collection<? extends T> c) |
void |
clear() |
boolean |
contains(Object o) |
boolean |
containsAll(Collection<?> c) |
boolean |
equals(Object o) |
T |
getFirst() |
T |
getSecond() |
int |
hashCode() |
boolean |
isEmpty() |
Iterator<T> |
iterator() |
boolean |
remove(Object o) |
boolean |
removeAll(Collection<?> c) |
boolean |
retainAll(Collection<?> c) |
int |
size() |
Object[] |
toArray() |
<S> S[] |
toArray(S[] a) |
String |
toString() |
clone, finalize, getClass, notify, notifyAll, wait, wait, waitparallelStream, removeIf, spliterator, streampublic Pair(T value1, T value2)
Pair from the specified elements.value1 - the first value in the new Pairvalue2 - the second value in the new PairIllegalArgumentException - if either argument is nullpublic Pair(Collection<? extends T> values)
values - the elements of the new PairIllegalArgumentException - if the input collection is null,
contains null values, or has != 2 elements.public Pair(T[] values)
Pair from the passed array.
The size of the array must be 2.values - the values to be used to construct this PairIllegalArgumentException - if the input array is null,
contains null values, or has != 2 elements.public T getFirst()
public T getSecond()
public boolean equals(Object o)
equals in interface Collection<T>equals in class Objectpublic int hashCode()
hashCode in interface Collection<T>hashCode in class Objectpublic boolean add(T o)
add in interface Collection<T>public boolean addAll(Collection<? extends T> c)
addAll in interface Collection<T>public void clear()
clear in interface Collection<T>public boolean contains(Object o)
contains in interface Collection<T>public boolean containsAll(Collection<?> c)
containsAll in interface Collection<T>public boolean isEmpty()
isEmpty in interface Collection<T>public boolean remove(Object o)
remove in interface Collection<T>public boolean removeAll(Collection<?> c)
removeAll in interface Collection<T>public boolean retainAll(Collection<?> c)
retainAll in interface Collection<T>public int size()
size in interface Collection<T>public Object[] toArray()
toArray in interface Collection<T>public <S> S[] toArray(S[] a)
toArray in interface Collection<T>Copyright © 2016. All rights reserved.