PIP.Collections
Class SymmetricPair<E>

java.lang.Object
  extended by PIP.Collections.Persistent.AbstractCollection<E>
      extended by PIP.Collections.Persistent.AbstractList
          extended by PIP.Collections.Pair<E>
              extended by PIP.Collections.SymmetricPair<E>
All Implemented Interfaces:
java.lang.Iterable, java.util.Collection, java.util.List

public class SymmetricPair<E>
extends Pair<E>

This class treats pairs symmetrically so that a:b is the same a b:a and it does not matter the order of the input into a new pair


Field Summary
 
Fields inherited from class PIP.Collections.Pair
o1, o2
 
Constructor Summary
SymmetricPair(E o1, E o2)
           
 
Method Summary
 boolean equals(java.lang.Object o)
          Compares the specified object with this list for equality.
 int hashCode()
          Returns the hash code value for this list.
 
Methods inherited from class PIP.Collections.Pair
areValuesEqual, get, getFirst, getSecond, reversed, setFirst, setSecond, size, swap, toString
 
Methods inherited from class PIP.Collections.Persistent.AbstractList
add, add, addAll, clear, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, set, subList
 
Methods inherited from class PIP.Collections.Persistent.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
 

Constructor Detail

SymmetricPair

public SymmetricPair(E o1,
                     E o2)
Method Detail

equals

public boolean equals(java.lang.Object o)
Description copied from class: AbstractList
Compares the specified object with this list for equality. Returns true if and only if the specified object is also a list, both lists have the same size, and all corresponding pairs of elements in the two lists are equal. (Two elements e1 and e2 are equal if (e1==null ? e2==null : e1.equals(e2)).) In other words, two lists are defined to be equal if they contain the same elements in the same order.

This implementation first checks if the specified object is this list. If so, it returns true; if not, it checks if the specified object is a list. If not, it returns false; if so, it iterates over both lists, comparing corresponding pairs of elements. If any comparison returns false, this method returns false. If either iterator runs out of elements before the other it returns false (as the lists are of unequal length); otherwise it returns true when the iterations complete.

Specified by:
equals in interface java.util.Collection
Specified by:
equals in interface java.util.List
Overrides:
equals in class Pair<E>
Parameters:
o - the object to be compared for equality with this list.
Returns:
true if the specified object is equal to this list.

hashCode

public int hashCode()
Description copied from class: AbstractList
Returns the hash code value for this list.

This implementation uses exactly the code that is used to define the list hash stampFilter in the documentation for the List.hashCode method.

Specified by:
hashCode in interface java.util.Collection
Specified by:
hashCode in interface java.util.List
Overrides:
hashCode in class Pair<E>
Returns:
the hash code value for this list.