T - type of stored elementspublic final class Tuple<T> extends Object implements Collection<T>, Serializable
Collection that stores
n non-null objects and is not mutable.
Tuples respect equals in the sense that two tuples are
equal if they contain equal objects.
Thus in partucular they may be used as indices or keys in maps.Note that they do not protect from malevolent behavior: if one or another object in the tuple is mutable, then it can be changed.
| Constructor and Description |
|---|
Tuple(Collection<? extends T> elements)
Creates a Tuple from the passed Collection.
|
Tuple(T[] elements)
Creates a
Tuple from the specified elements. |
Tuple(T first,
T second)
Creates a
Tuple from the specified elements. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(T o)
Since a tuple is not mutable, this method should not be invoked.
|
boolean |
addAll(Collection<? extends T> c)
Since a tuple is not mutable, this method should not be invoked.
|
void |
clear()
Since a tuple is not mutable, this method should not be invoked.
|
boolean |
contains(Object o) |
boolean |
containsAll(Collection<?> c) |
boolean |
equals(Object o) |
T |
getFirst()
Returns the first element of this tuple.
|
T |
getSecond()
Returns the second element of this tuple.
|
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 Tuple(T[] elements)
Tuple from the specified elements.elements - the elements in the TupleIllegalArgumentException - if either argument is null or there are less than two elementspublic Tuple(Collection<? extends T> elements)
elements - the elements of the new TupleIllegalArgumentException - if the input collection is null, contains
null values, or has < 2 elements.public Tuple(T first, T second)
Tuple from the specified elements.first - the first element in the Tuplesecond - the second element in the TupleIllegalArgumentException - if either argument is nullpublic 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>o - an objectUnsupportedOperationException - if this method is invokedpublic boolean addAll(Collection<? extends T> c)
addAll in interface Collection<T>c - an objectUnsupportedOperationException - if this method is invokedpublic void clear()
clear in interface Collection<T>UnsupportedOperationException - if this method is invokedpublic 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>