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()
Returns the first element.
|
T |
getSecond()
Returns the second element.
|
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, wait
parallelStream, removeIf, spliterator, stream
public Pair(T value1, T value2)
Pair
from the specified elements.value1
- the first value in the new Pair
value2
- the second value in the new Pair
IllegalArgumentException
- if either argument is nullpublic Pair(Collection<? extends T> values)
values
- the elements of the new Pair
IllegalArgumentException
- 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.IllegalArgumentException
- 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 Object
public int hashCode()
hashCode
in interface Collection<T>
hashCode
in class Object
public 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 © 2015. All rights reserved.