|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.util.AbstractCollection | +--java.util.AbstractList | +--gate.util.WeakBumpyStack
Weak stack that allow you to bump an element to the front. Objects that are only referenced by this stack will be candidates for garbage collection and wil be removed from the stack as soon as the garbage collector marks them for collection.
*** WARNING: *** the test for this class, TestBumpyStack.testSelfCleaning is not a proper test; it doesn't fail even when it should, and only prints a warning when DEBUG is true. This is because to test it properly you need to force garbage collection, and that isn't possible. So, if you work on this class you must turn DEBUG on on TestBumpyStack in order to run the tests in a meaningfull way.
Constructor Summary | |
WeakBumpyStack()
Creates a new empty stack. |
Method Summary | |
void |
add(int index,
Object element)
Inserts the specified element at the specified position in this list. |
boolean |
bump(Object item)
Bump an item to the front of the stack. |
boolean |
empty()
Tests if this stack is empty. |
Object |
get(int index)
Returns the element at the specified position in this list. |
Object |
peek()
Looks at the object at the top of this stack without removing it from the stack. |
Object |
pop()
Removes the object at the top of this stack and returns that object as the value of this function. |
Object |
push(Object item)
Pushes an item onto the top of this stack. |
Object |
remove(int index)
Removes the element at the specified position in this list. |
int |
search(Object o)
Returns the 1-based position where an object is on this stack. |
Object |
set(int index,
Object element)
Replaces the element at the specified position in this list with the specified element. |
int |
size()
Returns the number of elements in this list. |
Methods inherited from class java.util.AbstractList |
add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, subList |
Methods inherited from class java.util.AbstractCollection |
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString |
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 |
public WeakBumpyStack()
Method Detail |
public Object push(Object item)
addElement(item)
item
- the item to be pushed onto this stack.item
argument.public Object pop()
EmptyStackException
- if this stack is empty.public Object peek()
EmptyStackException
- if this stack is empty.public boolean empty()
true
if and only if this stack contains
no items; false
otherwise.public boolean bump(Object item)
item
- the item to bumppublic int search(Object o)
o
- the desired object.-1
indicates that the object is not on the stack.public Object get(int index)
get
in class AbstractList
index
- index of element to return.IndexOutOfBoundsException
- if index is out of range (index
< 0 || index >= size()).public int size()
size
in class AbstractCollection
public Object set(int index, Object element)
set
in class AbstractList
index
- index of element to replace.element
- element to be stored at the specified position.IndexOutOfBoundsException
- if index out of range
(index < 0 || index >= size()).public void add(int index, Object element)
add
in class AbstractList
index
- index at which the specified element is to be inserted.element
- element to be inserted.IndexOutOfBoundsException
- if index is out of range
(index < 0 || index > size()).public Object remove(int index)
remove
in class AbstractList
index
- the index of the element to removed.IndexOutOfBoundsException
- if index out of range (index
< 0 || index >= size()).
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |