public final class Pair<T>
extends java.lang.Object
implements java.util.Collection<T>, java.io.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(java.util.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(java.util.Collection<? extends T> c) |
void |
clear() |
boolean |
contains(java.lang.Object o) |
boolean |
containsAll(java.util.Collection<?> c) |
boolean |
equals(java.lang.Object o) |
T |
getFirst()
Returns the first element.
|
T |
getSecond()
Returns the second element.
|
int |
hashCode() |
boolean |
isEmpty() |
java.util.Iterator<T> |
iterator() |
boolean |
remove(java.lang.Object o) |
boolean |
removeAll(java.util.Collection<?> c) |
boolean |
retainAll(java.util.Collection<?> c) |
int |
size() |
java.lang.Object[] |
toArray() |
<S> S[] |
toArray(S[] a) |
java.lang.String |
toString() |
public Pair(T value1, T value2)
Pair from the specified elements.value1 - the first value in the new Pairvalue2 - the second value in the new Pairjava.lang.IllegalArgumentException - if either argument is nullpublic Pair(java.util.Collection<? extends T> values)
values - the elements of the new Pairjava.lang.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.java.lang.IllegalArgumentException - if the input array is null,
contains null values, or has != 2 elements.public T getFirst()
public T getSecond()
public boolean equals(java.lang.Object o)
equals in interface java.util.Collection<T>equals in class java.lang.Objectpublic int hashCode()
hashCode in interface java.util.Collection<T>hashCode in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Objectpublic boolean addAll(java.util.Collection<? extends T> c)
addAll in interface java.util.Collection<T>public void clear()
clear in interface java.util.Collection<T>public boolean contains(java.lang.Object o)
contains in interface java.util.Collection<T>public boolean containsAll(java.util.Collection<?> c)
containsAll in interface java.util.Collection<T>public boolean isEmpty()
isEmpty in interface java.util.Collection<T>public java.util.Iterator<T> iterator()
public boolean remove(java.lang.Object o)
remove in interface java.util.Collection<T>public boolean removeAll(java.util.Collection<?> c)
removeAll in interface java.util.Collection<T>public boolean retainAll(java.util.Collection<?> c)
retainAll in interface java.util.Collection<T>public int size()
size in interface java.util.Collection<T>public java.lang.Object[] toArray()
toArray in interface java.util.Collection<T>public <S> S[] toArray(S[] a)
toArray in interface java.util.Collection<T>Copyright © 2021, 2022 Herve Girod. All Rights Reserved. Documentation and source under the BSD 3-Clause licence