|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectpt.ua.base.Listable<T>
pt.ua.base.Indexable<T>
pt.ua.base.Stack<T>
pt.ua.base.LinkedStack<T>
public class LinkedStack<T>
Stack module implemented with a linked list.
invariant: Stack
This class follows DbC(tm) methodology. Where possible, contracts are implement with JML and native's Java assert.
Constructor Summary | |
---|---|
LinkedStack()
Creates an unbounded stack. |
|
LinkedStack(int maxSize)
Creates an bounded stack limited to maxSize elements. |
Method Summary | |
---|---|
void |
clear()
Empties the stack. |
Stack<T> |
deepClone()
Clones current list. |
boolean |
isFull()
Queries the list fullness. |
boolean |
isLimited()
Checks if list is unbounded. |
T |
itemAt(int idx)
Returns the element of the list at the idx position. |
int |
maxSize()
The list maximum number of elements. |
void |
pop()
Removes the top element from the stack. |
void |
push(T e)
Adds an element to the top of the stack. |
int |
size()
The list total number of elements. |
Methods inherited from class pt.ua.base.Stack |
---|
copy, top |
Methods inherited from class pt.ua.base.Indexable |
---|
headList, subList, tailList, toArray, toList, toString |
Methods inherited from class pt.ua.base.Listable |
---|
isEmpty |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public LinkedStack()
public LinkedStack(int maxSize)
maxSize
elements.
requires: maxSize >= 0
Method Detail |
---|
public boolean isLimited()
Listable
isLimited
in class Listable<T>
true
if list is unbounded, false
otherwisepublic int maxSize()
Listable
requires: isLimited()
maxSize
in class Listable<T>
public Stack<T> deepClone()
Listable
ensures: \result.size() == size()
deepClone
in class Stack<T>
public void push(T e)
Stack
requires: !isFull()
ensures: !isEmpty() && top() == e
ensures: size() == \old(size()) + 1
ensures: tailList(1).equals(\old(tailList(0)))
push
in class Stack<T>
e
- the element to pushpublic void pop()
Stack
requires: !isEmpty()
ensures: !isFull()
ensures: size() == \old(size()) - 1
ensures: tailList(0).equals(\old(tailList(1)))
pop
in class Stack<T>
public int size()
Listable
size
in class Listable<T>
public boolean isFull()
Listable
isFull
in class Listable<T>
true
if list is full, false
otherwisepublic T itemAt(int idx)
Indexable
idx
position.
requires: idx >= 0 && idx < size()
itemAt
in class Indexable<T>
idx
- the index
public void clear()
Stack
ensures: isEmpty()
clear
in class Stack<T>
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |