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.SerializableAn implementation ofCollectionthat stores exactly 2 non-null objects and is not mutable. They respectequalsand 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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classPair.PairIterator
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(T o)booleanaddAll(java.util.Collection<? extends T> c)voidclear()booleancontains(java.lang.Object o)booleancontainsAll(java.util.Collection<?> c)booleanequals(java.lang.Object o)TgetFirst()TgetSecond()inthashCode()booleanisEmpty()java.util.Iterator<T>iterator()booleanremove(java.lang.Object o)booleanremoveAll(java.util.Collection<?> c)booleanretainAll(java.util.Collection<?> c)intsize()java.lang.Object[]toArray()<S> S[]toArray(S[] a)java.lang.StringtoString()-
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 aPairfrom the specified elements.- Parameters:
value1- the first value in the newPairvalue2- 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 aPairfrom the passed array. The size of the array must be 2.- Parameters:
values- the values to be used to construct this Pair- 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:
equalsin interfacejava.util.Collection<T>- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Specified by:
hashCodein interfacejava.util.Collection<T>- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
addAll
public boolean addAll(java.util.Collection<? extends T> c)
- Specified by:
addAllin interfacejava.util.Collection<T>
-
clear
public void clear()
- Specified by:
clearin interfacejava.util.Collection<T>
-
contains
public boolean contains(java.lang.Object o)
- Specified by:
containsin interfacejava.util.Collection<T>
-
containsAll
public boolean containsAll(java.util.Collection<?> c)
- Specified by:
containsAllin interfacejava.util.Collection<T>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfacejava.util.Collection<T>
-
iterator
public java.util.Iterator<T> iterator()
-
remove
public boolean remove(java.lang.Object o)
- Specified by:
removein interfacejava.util.Collection<T>
-
removeAll
public boolean removeAll(java.util.Collection<?> c)
- Specified by:
removeAllin interfacejava.util.Collection<T>
-
retainAll
public boolean retainAll(java.util.Collection<?> c)
- Specified by:
retainAllin interfacejava.util.Collection<T>
-
size
public int size()
- Specified by:
sizein interfacejava.util.Collection<T>
-
toArray
public java.lang.Object[] toArray()
- Specified by:
toArrayin interfacejava.util.Collection<T>
-
toArray
public <S> S[] toArray(S[] a)
- Specified by:
toArrayin interfacejava.util.Collection<T>
-
-