|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.util.AbstractCollection<E>
java.util.AbstractList<E>
java.util.Vector<E>
java.util.Stack
org.ceryle.util.StackSet
public class StackSet
StackSet extends java.util.Stack (a class that represents a
last-in-first-out (LIFO) stack of objects, but in this case
also includes methods making it addressable at any level)
to implement the java.util.Set interface, guaranteeing that
all elements in the Stack are unique. Because it is ultimately
backed by a Vector, iterator order follows the element order.
This provides the missing cross between the List
and Set interfaces.
Additionally, this class has a number of important features:
This class had evolved to a point where its proper name would have been AddressableSortedQueueStackSet, but this was such a mouthful that the name was in the end just shortened to StackSet.
AddressableStack,
Stack,
Serialized Form| Field Summary | |
|---|---|
static int |
BOTTOM
An indicator of the maximum depth or bottom of the stack. |
| Fields inherited from class java.util.Vector |
|---|
capacityIncrement, elementCount, elementData |
| Fields inherited from class java.util.AbstractList |
|---|
modCount |
| Constructor Summary | |
|---|---|
StackSet()
Creates an empty StackSet. |
|
StackSet(Collection c)
Creates an StackSet containing the unique members of the Collection c, in the reverse of the order that the Collection's iterator provides them since they're being pushed onto a stack). |
|
| Method Summary | |
|---|---|
void |
add(int index,
Object element)
If the specified object does not already exist in the stack, inserts the specified element at the specified position in this stack. |
boolean |
add(Object o)
If the specified object does not already exist in the stack, appends the specified element to the end of this Vector. |
boolean |
addAll(Collection c)
Appends all of the elements in the specified Collection that are not already part of this StackSet to the end of the stack, in the order that they are returned by the specified Collection's Iterator. |
boolean |
addAll(int index,
Collection c)
This method would have inserted all of the elements in the specified Collection not already in this stack into this StackSet at the specified position. |
void |
addElement(Object obj)
If the specified object does not already exist in the stack, adds the specified component to the end of this stack, increasing its size by one. |
void |
insertElementAt(Object obj,
int index)
If the specified object does not already exist in the stack, inserts it as a component in this stack at the specified index. |
boolean |
moveToBeginning(Object o)
Moves the Object o to the first element position in the model. |
Object |
peek(int depth)
Looks at the object at the specific depth in this stack without removing it from the stack. |
Object |
pop(int depth)
Pops the object at the specific depth from the stack. |
Object |
push(Object item)
If the specified item does not already exist in the stack, pushes the item onto the top of this stack. |
void |
removeBottom()
Removes the first element of this StackSet. |
void |
rotateDown()
Rotates the stack by removing the first (ie., bottom) element and pushing it onto the end (ie., top) of the stack. |
void |
rotateDown(int count)
Rotates the stack count times by repeatedly removing the first (ie., bottom) element and pushing it onto the end (ie., top) of the stack. |
void |
rotateToTop(Object o)
Rotates the stack as necessary to move the Object o to the top of the stack. |
void |
rotateUp()
Rotates the stack by popping the last (ie., top) element and inserting it at the beginning (ie., bottom) of the stack. |
void |
rotateUp(int count)
Rotates the stack count times by repeatedly popping the last (ie., top) element and inserting it at the beginning (ie., bottom) of the stack. |
Object |
set(int index,
Object element)
If the specified object does not already exist in the stack, replaces the element at the specified position in this StackSet with the specified element. |
void |
setElementAt(Object obj,
int index)
If the specified object does not yet exist in the Set, sets the component at the specified index of this stack to be
the specified object. |
void |
sort()
Sorts the stack's objects into ascending order, according to the natural ordering of its elements. |
| Methods inherited from class java.util.Stack |
|---|
empty, peek, pop, search |
| Methods inherited from class java.util.Vector |
|---|
capacity, clear, clone, contains, containsAll, copyInto, elementAt, elements, ensureCapacity, equals, firstElement, get, hashCode, indexOf, indexOf, isEmpty, lastElement, lastIndexOf, lastIndexOf, remove, remove, removeAll, removeAllElements, removeElement, removeElementAt, removeRange, retainAll, setSize, size, subList, toArray, toArray, toString, trimToSize |
| Methods inherited from class java.util.AbstractList |
|---|
iterator, listIterator, listIterator |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.List |
|---|
clear, contains, containsAll, equals, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, retainAll, size, subList, toArray, toArray |
| Methods inherited from interface java.util.Set |
|---|
clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray |
| Field Detail |
|---|
public static final int BOTTOM
| Constructor Detail |
|---|
public StackSet()
public StackSet(Collection c)
| Method Detail |
|---|
public Object peek(int depth)
depth - an int indicating the peeking depth (zero indicates the top, BOTTOM the bottom)
EmptyStackException - if this stack is emptypublic Object pop(int depth)
depth - an int indicating the peeking depth (zero indicates the top, BOTTOM the bottom)
depth from the top of this stack
EmptyStackException - if this stack is empty
public void setElementAt(Object obj,
int index)
index of this stack to be
the specified object. The previous component at that position is
discarded.
The index must be a value greater than or equal to 0
and less than the current size of the stack.
setElementAt in class Vectorobj - what the component is to be set to.index - the specified index.
ArrayIndexOutOfBoundsException - if the index was invalid.
public void insertElementAt(Object obj,
int index)
index.
Each component in this stack with an index greater or equal to the
specified index is shifted upward to have an index one
greater than the value it had previously (this method is really with
regard to the stack's underlying Vector).
The index must be a value greater than or equal to 0
and less than or equal to the current size of the stack. (If the
index is equal to the current size of the stack, the new element
is pushed onto the stack.)
insertElementAt in class Vectorobj - the component to insert.index - where to insert the new component.
ArrayIndexOutOfBoundsException - if the index was invalid.public void addElement(Object obj)
Note: null parameters are ignored.
addElement in class Vectorobj - the component to be added.
public Object set(int index,
Object element)
set in interface Listset in class Vectorindex - index of element to replace.element - element to be stored at the specified position.
ArrayIndexOutOfBoundsException - index out of range
(index < 0 || index >= size()).
IllegalArgumentException - fromIndex > toIndex.public boolean add(Object o)
Note: null parameters are ignored.
add in interface Collectionadd in interface Listadd in interface Setadd in class Vectoro - element to be appended to this Vector.
public void add(int index,
Object element)
Note: null parameters are ignored.
add in interface Listadd in class Vectorindex - index at which the specified element is to be inserted.element - element to be inserted.
ArrayIndexOutOfBoundsException - index is out of range
(index < 0 || index > size()).public boolean addAll(Collection c)
addAll in interface CollectionaddAll in interface ListaddAll in interface SetaddAll in class Vectorc - elements to be inserted into this StackSet.
ArrayIndexOutOfBoundsException - index out of range (index
< 0 || index > size()).
public boolean addAll(int index,
Collection c)
addAll in interface ListaddAll in class VectorArrayIndexOutOfBoundsException - index out of range (indexpublic Object push(Object item)
addElement(item)
push in class Stackitem - the item to be pushed onto this stack.
item argument.Vector.addElement(Object)public void sort()
This sort is guaranteed to be stable: equal elements will not be reordered as a result of the sort.
For very large sets this may not be the most efficient way to perform a sort, as this method offloads its contents into an array, sorts, then reloads from the array. But given that sorting in a Collection would likely be slow and that array processing in Java is very fast, it's not likely there's a much better way.
PLEASE NOTE: As of 2005-01-04 it is noted that the sorting facility for StackSet seems to not work under all circumstances. The bug is noted.
Arrays.sort(Object[])public boolean moveToBeginning(Object o)
public void rotateToTop(Object o)
throws NoSuchElementException
NoSuchElementExceptionpublic void rotateUp(int count)
public void rotateUp()
public void rotateDown(int count)
public void rotateDown()
public void removeBottom()
throws EmptyStackException
EmptyStackException
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||