kodkod.util.collections
Class ArrayStack<T>

java.lang.Object
  extended by kodkod.util.collections.Stack<T>
      extended by kodkod.util.collections.ArrayStack<T>
All Implemented Interfaces:
java.lang.Iterable<T>

public class ArrayStack<T>
extends Stack<T>

A Stack implementation based on an array.

Author:
Emina Torlak

Constructor Summary
ArrayStack()
          Constructs an empty stack with the inital capacity of 10.
ArrayStack(int initialCapacity)
           
 
Method Summary
 boolean empty()
          Returns true if the stack is empty; otherwise returns false.
 void ensureCapacity(int minCapacity)
          Increases the capacity of this ArrayStack, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.
 java.util.Iterator<T> iterator()
          Iterates over the items in this Stack, starting at the top of the stack and working its way down.
 T peek()
          Looks at the object at the top of this stack without removing it from the stack.
 T pop()
          Removes the object at the top of this stack and returns that object as the value of this function.
 T push(T item)
          Pushes an item onto the top of this stack and returns it.
 int search(java.lang.Object o)
          Returns the 1-based position where an object is on this stack.
 int size()
          Returns the size of this stack.
 void trimToSize()
          Trims the capacity of this ArrayStack to be the stack's current size.
 
Methods inherited from class kodkod.util.collections.Stack
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ArrayStack

public ArrayStack()
Constructs an empty stack with the inital capacity of 10.

effects:
no this.elems'

ArrayStack

public ArrayStack(int initialCapacity)
Method Detail

ensureCapacity

public void ensureCapacity(int minCapacity)
Increases the capacity of this ArrayStack, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.


trimToSize

public void trimToSize()
Trims the capacity of this ArrayStack to be the stack's current size. An application can use this operation to minimize the storage of an ArrayStack instance.


size

public int size()
Description copied from class: Stack
Returns the size of this stack.

Specified by:
size in class Stack<T>
Returns:
this.size
See Also:
Stack.size()

push

public T push(T item)
Pushes an item onto the top of this stack and returns it.

Specified by:
push in class Stack<T>
Returns:
item
See Also:
Stack.push(T)

pop

public T pop()
Description copied from class: Stack
Removes the object at the top of this stack and returns that object as the value of this function.

Specified by:
pop in class Stack<T>
Returns:
this.elems[0]
See Also:
Stack.pop()

peek

public T peek()
Description copied from class: Stack
Looks at the object at the top of this stack without removing it from the stack.

Specified by:
peek in class Stack<T>
Returns:
this.elems[0]
See Also:
Stack.peek()

search

public int search(java.lang.Object o)
Description copied from class: Stack
Returns the 1-based position where an object is on this stack. If the object o occurs as an item in this stack, this method returns the distance from the top of the stack of the occurrence nearest the top of the stack; the topmost item on the stack is considered to be at distance 1. The equals method is used to compare o to the items in this stack.

Specified by:
search in class Stack<T>
Returns:
o in this.elems[int] => min(this.elems.o) + 1, -1
See Also:
Stack.search(java.lang.Object)

empty

public boolean empty()
Description copied from class: Stack
Returns true if the stack is empty; otherwise returns false.

Specified by:
empty in class Stack<T>
Returns:
no this.elems
See Also:
Stack.empty()

iterator

public java.util.Iterator<T> iterator()
Iterates over the items in this Stack, starting at the top of the stack and working its way down.

Specified by:
iterator in interface java.lang.Iterable<T>
Specified by:
iterator in class Stack<T>
Returns:
iterator over the elements in this stack.
See Also:
Stack.iterator()