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:
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
boolean
addAll
(Collection<? extends T> c) void
clear()
boolean
boolean
containsAll
(Collection<?> c) boolean
getFirst()
int
hashCode()
boolean
isEmpty()
iterator()
boolean
boolean
removeAll
(Collection<?> c) boolean
retainAll
(Collection<?> c) int
size()
Object[]
toArray()
<S> S[]
toArray
(S[] a) toString()
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, spliterator, stream, toArray
-
Field Details
-
first
-
second
-
-
Constructor Details
-
Pair
Creates aPair
from the specified elements.- Parameters:
value1
- the first value in the newPair
value2
- 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 aPair
from 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:
equals
in interfaceCollection<T>
- Overrides:
equals
in classObject
-
hashCode
public int hashCode()- Specified by:
hashCode
in interfaceCollection<T>
- Overrides:
hashCode
in classObject
-
toString
-
add
- Specified by:
add
in interfaceCollection<T>
-
addAll
- Specified by:
addAll
in interfaceCollection<T>
-
clear
public void clear()- Specified by:
clear
in interfaceCollection<T>
-
contains
- Specified by:
contains
in interfaceCollection<T>
-
containsAll
- Specified by:
containsAll
in interfaceCollection<T>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceCollection<T>
-
iterator
-
remove
- Specified by:
remove
in interfaceCollection<T>
-
removeAll
- Specified by:
removeAll
in interfaceCollection<T>
-
retainAll
- Specified by:
retainAll
in interfaceCollection<T>
-
size
public int size()- Specified by:
size
in interfaceCollection<T>
-
toArray
- Specified by:
toArray
in interfaceCollection<T>
-
toArray
public <S> S[] toArray(S[] a) - Specified by:
toArray
in interfaceCollection<T>
-