Package net.cscott.jutil
Class UniqueStack<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
net.cscott.jutil.UniqueVector<E>
net.cscott.jutil.UniqueStack<E>
- All Implemented Interfaces:
Cloneable,Iterable<E>,Collection<E>,List<E>,SequencedCollection<E>,Set<E>
The
UniqueStack class represents a last-in-first-out
stack of unique objects.
Conforms to the JDK 1.2 Collections API.
- Author:
- C. Scott Ananian <cananian@alumni.princeton.edu>
-
Field Summary
Fields inherited from class java.util.AbstractList
modCount -
Constructor Summary
ConstructorsConstructorDescriptionCreates aUniqueStack.UniqueStack(Collection<? extends E> c) Constructs aUniqueStackcontaining the elements of the specifiedCollection, in the order they are returned by the collection's iterator in LIFO order. -
Method Summary
Modifier and TypeMethodDescriptionbooleanempty()Tests if this stack is empty.peek()Looks at the object at the top of this stack without removing it from the stack.pop()Removes the object at the top of this stack and returns that object as the value of this function.voidPushes an item onto the top of this stack, if it is unique.intReturns where an object is on this stack.Methods inherited from class net.cscott.jutil.UniqueVector
add, add, addElement, capacity, clear, clone, contains, copyInto, elementAt, elements, ensureCapacity, equals, firstElement, get, hashCode, indexOf, indexOf, insertElementAt, isEmpty, lastElement, lastIndexOf, lastIndexOf, remove, removeAllElements, removeElement, removeElementAt, set, setElementAt, size, spliterator, toArray, toArray, toString, trimToSizeMethods inherited from class java.util.AbstractList
addAll, iterator, listIterator, listIterator, removeRange, subListMethods inherited from class java.util.AbstractCollection
addAll, containsAll, remove, removeAll, retainAllMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.List
addAll, addFirst, addLast, containsAll, getFirst, getLast, remove, removeAll, removeFirst, removeLast, replaceAll, retainAll, reversed, sort
-
Constructor Details
-
UniqueStack
public UniqueStack()Creates aUniqueStack. -
UniqueStack
Constructs aUniqueStackcontaining the elements of the specifiedCollection, in the order they are returned by the collection's iterator in LIFO order. That is, the first item returned by the collection iterator will be at the bottom of the stack, and thus last to be popped. Duplicate elements incare skipped.
-
-
Method Details
-
push
Pushes an item onto the top of this stack, if it is unique. Otherwise, does nothing.- Parameters:
item- the item to be pushed onto this stack.
-
pop
Removes the object at the top of this stack and returns that object as the value of this function.- Returns:
- The object at the top of this stack.
- Throws:
EmptyStackException- if this empty.
-
peek
Looks at the object at the top of this stack without removing it from the stack.- Returns:
- the object at the top of this stack.
- Throws:
EmptyStackException- if this stack is empty.
-
empty
public boolean empty()Tests if this stack is empty.- Returns:
trueif this stack is empty;falseotherwise.
-
search
Returns where an object is on this stack.- Parameters:
o- the desired object.- Returns:
- the distance from the top of the stack where the object is
located; the return value
-1indicates that the object is not on the stack.
-