Package edu.uci.ics.jung.graph.util
Class Pair<T>
java.lang.Object
edu.uci.ics.jung.graph.util.Pair<T>
- All Implemented Interfaces:
Serializable,Iterable<T>,Collection<T>
An implementation of
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.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanaddAll(Collection<? extends T> c) voidclear()booleanbooleancontainsAll(Collection<?> c) booleangetFirst()inthashCode()booleanisEmpty()iterator()booleanbooleanremoveAll(Collection<?> c) booleanretainAll(Collection<?> c) intsize()Object[]toArray()<S> S[]toArray(S[] a) toString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, spliterator, stream, toArray
-
Constructor Details
-
Pair
Creates aPairfrom the specified elements.- Parameters:
value1- the first value in the newPairvalue2- the second value in the newPair- Throws:
IllegalArgumentException- if either argument is null
-
Pair
Creates a Pair from the passed Collection. The size of the Collection must be 2.- Parameters:
values- the elements of the newPair- Throws:
IllegalArgumentException- if the input collection is null, contains null values, or has != 2 elements.
-
Pair
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:
IllegalArgumentException- if the input array is null, contains null values, or has != 2 elements.
-
-
Method Details
-
getFirst
- Returns:
- the first element.
-
getSecond
- Returns:
- the second element.
-
equals
- Specified by:
equalsin interfaceCollection<T>- Overrides:
equalsin classObject
-
hashCode
public int hashCode()- Specified by:
hashCodein interfaceCollection<T>- Overrides:
hashCodein classObject
-
toString
-
add
- Specified by:
addin interfaceCollection<T>
-
addAll
- Specified by:
addAllin interfaceCollection<T>
-
clear
public void clear()- Specified by:
clearin interfaceCollection<T>
-
contains
- Specified by:
containsin interfaceCollection<T>
-
containsAll
- Specified by:
containsAllin interfaceCollection<T>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceCollection<T>
-
iterator
-
remove
- Specified by:
removein interfaceCollection<T>
-
removeAll
- Specified by:
removeAllin interfaceCollection<T>
-
retainAll
- Specified by:
retainAllin interfaceCollection<T>
-
size
public int size()- Specified by:
sizein interfaceCollection<T>
-
toArray
- Specified by:
toArrayin interfaceCollection<T>
-
toArray
public <S> S[] toArray(S[] a) - Specified by:
toArrayin interfaceCollection<T>
-