edu.cmu.cs.pattis.cs151xx.orderedCollections
Class AbstractStack<E>

java.lang.Object
  extended by edu.cmu.cs.pattis.cs151xx.orderedCollections.AbstractOrderedCollection<E>
      extended by edu.cmu.cs.pattis.cs151xx.orderedCollections.AbstractStack<E>
All Implemented Interfaces:
OrderedCollection<E>, java.lang.Iterable<E>
Direct Known Subclasses:
ArrayStack, LinkedStack

public abstract class AbstractStack<E>
extends AbstractOrderedCollection<E>

This class extends a skeletal implementation of AbstractOrderedCollection with the equals method.


Method Summary
 boolean equals(java.lang.Object o)
          Compares the specified object with this stack for equality.
 
Methods inherited from class edu.cmu.cs.pattis.cs151xx.orderedCollections.AbstractOrderedCollection
add, addAll, clear, hashCode, isEmpty, iterator, peek, remove, size, toArray, toArray, toCollection, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

equals

public boolean equals(java.lang.Object o)
Compares the specified object with this stack for equality. Returns true if and only if the specified object is also a stack, both stacks have the same size, and all corresponding pairs of elements in the two stacks are equal. (Two elements e1 and e2 are equal if
  (e1==null ? e2==null : e1.equals(e2))
In other words, two stacks 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 stack. If so, it returns true; if not, it checks if the specified object is a stack. If not, it returns false; if so, it iterates over both stacks, comparing corresponding pairs of elements. If any comparison returns false, this method returns false. Ootherwise it returns true when the iterations complete.

Specified by:
equals in interface OrderedCollection<E>
Overrides:
equals in class java.lang.Object
Parameters:
o - - Object to be compared for equality with this collection.
Returns:
true if the specified object is equal to this stack.
See Also:
Object.equals(Object)