Package edu.uci.ics.jung.graph.util
Class Pair<T>
- java.lang.Object
-
- edu.uci.ics.jung.graph.util.Pair<T>
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Iterable<T>
,java.util.Collection<T>
public final class Pair<T> extends java.lang.Object implements java.util.Collection<T>, java.io.Serializable
An implementation ofCollection
that stores exactly 2 non-null objects and is not mutable. They respectequals
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.
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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()
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
-
-
-
Constructor Detail
-
Pair
public Pair(T value1, T value2)
Creates aPair
from the specified elements.- Parameters:
value1
- the first value in the newPair
value2
- the second value in the newPair
- Throws:
java.lang.IllegalArgumentException
- if either argument is null
-
Pair
public Pair(java.util.Collection<? extends T> values)
Creates a Pair from the passed Collection. The size of the Collection must be 2.- Parameters:
values
- the elements of the newPair
- Throws:
java.lang.IllegalArgumentException
- if the input collection is null, contains null values, or has != 2 elements.
-
Pair
public Pair(T[] values)
Creates aPair
from the passed array. The size of the array must be 2.- Throws:
java.lang.IllegalArgumentException
- if the input array is null, contains null values, or has != 2 elements.
-
-
Method Detail
-
getFirst
public T getFirst()
Returns the first element.
-
getSecond
public T getSecond()
Returns the second element.
-
equals
public boolean equals(java.lang.Object o)
- Specified by:
equals
in interfacejava.util.Collection<T>
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Specified by:
hashCode
in interfacejava.util.Collection<T>
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
addAll
public boolean addAll(java.util.Collection<? extends T> c)
- Specified by:
addAll
in interfacejava.util.Collection<T>
-
clear
public void clear()
- Specified by:
clear
in interfacejava.util.Collection<T>
-
contains
public boolean contains(java.lang.Object o)
- Specified by:
contains
in interfacejava.util.Collection<T>
-
containsAll
public boolean containsAll(java.util.Collection<?> c)
- Specified by:
containsAll
in interfacejava.util.Collection<T>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interfacejava.util.Collection<T>
-
iterator
public java.util.Iterator<T> iterator()
-
remove
public boolean remove(java.lang.Object o)
- Specified by:
remove
in interfacejava.util.Collection<T>
-
removeAll
public boolean removeAll(java.util.Collection<?> c)
- Specified by:
removeAll
in interfacejava.util.Collection<T>
-
retainAll
public boolean retainAll(java.util.Collection<?> c)
- Specified by:
retainAll
in interfacejava.util.Collection<T>
-
size
public int size()
- Specified by:
size
in interfacejava.util.Collection<T>
-
toArray
public java.lang.Object[] toArray()
- Specified by:
toArray
in interfacejava.util.Collection<T>
-
toArray
public <S> S[] toArray(S[] a)
- Specified by:
toArray
in interfacejava.util.Collection<T>
-
-