edu.uci.ics.jung.graph.util
Class Pair<T>

java.lang.Object
  extended by edu.uci.ics.jung.graph.util.Pair<T>
All Implemented Interfaces:
Serializable, Iterable<T>, Collection<T>

public final class Pair<T>
extends Object
implements Collection<T>, Serializable

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:
Serialized Form

Constructor Summary
Pair(Collection<? extends T> values)
          Creates a Pair from the passed Collection.
Pair(T[] values)
          Creates a Pair from the passed array.
Pair(T value1, T value2)
          Creates a Pair from the specified elements.
 
Method Summary
 boolean add(T o)
           
 boolean addAll(Collection<? extends T> c)
           
 void clear()
           
 boolean contains(Object o)
           
 boolean containsAll(Collection<?> c)
           
 boolean equals(Object o)
           
 T getFirst()
          Returns the first element.
 T getSecond()
          Returns the second element.
 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()
           
 
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 a Pair from the specified elements.

Parameters:
value1 - the first value in the new Pair
value2 - the second value in the new Pair
Throws:
IllegalArgumentException - if either argument is null

Pair

public Pair(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 new Pair
Throws:
IllegalArgumentException - if the input collection is null, contains null values, or has != 2 elements.

Pair

public Pair(T[] values)
Creates a Pair from the passed array. The size of the array must be 2.

Throws:
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(Object o)
Specified by:
equals in interface Collection<T>
Overrides:
equals in class Object

hashCode

public int hashCode()
Specified by:
hashCode in interface Collection<T>
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object

add

public boolean add(T o)
Specified by:
add in interface Collection<T>

addAll

public boolean addAll(Collection<? extends T> c)
Specified by:
addAll in interface Collection<T>

clear

public void clear()
Specified by:
clear in interface Collection<T>

contains

public boolean contains(Object o)
Specified by:
contains in interface Collection<T>

containsAll

public boolean containsAll(Collection<?> c)
Specified by:
containsAll in interface Collection<T>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Collection<T>

iterator

public Iterator<T> iterator()
Specified by:
iterator in interface Iterable<T>
Specified by:
iterator in interface Collection<T>

remove

public boolean remove(Object o)
Specified by:
remove in interface Collection<T>

removeAll

public boolean removeAll(Collection<?> c)
Specified by:
removeAll in interface Collection<T>

retainAll

public boolean retainAll(Collection<?> c)
Specified by:
retainAll in interface Collection<T>

size

public int size()
Specified by:
size in interface Collection<T>

toArray

public Object[] toArray()
Specified by:
toArray in interface Collection<T>

toArray

public <S> S[] toArray(S[] a)
Specified by:
toArray in interface Collection<T>


Copyright © 2009. All Rights Reserved.