com.puppycrawl.tools.checkstyle.api
Class FastStack<E>

java.lang.Object
  extended by com.puppycrawl.tools.checkstyle.api.FastStack<E>
Type Parameters:
E - The type to hold.
All Implemented Interfaces:
Iterable<E>

public class FastStack<E>
extends Object
implements Iterable<E>

Simple implementation of a LIFO Stack that can be used instead of Vector which is synchronized.

Author:
oliverb

Constructor Summary
FastStack()
           
 
Method Summary
 void clear()
          Clears the stack.
 boolean contains(E aElement)
          Returns if the stack contains the specified element.
 boolean isEmpty()
          Returns whether the stack is empty.
 Iterator<E> iterator()
          Returns an iterator that goes from the oldest element to the newest.
static
<T> FastStack<T>
newInstance()
          Factory method to create a new instance.
 E peek()
          Returns the entry at the top of the stack without removing it.
 E peek(int aIndex)
          Return the element at the specified index.
 E pop()
          Returns the entry at the top of the stack by removing it.
 void push(E aElement)
          Pushes the supplied element onto the stack.
 int size()
          Returns the number of entries in the stack.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FastStack

public FastStack()
Method Detail

push

public void push(E aElement)
Pushes the supplied element onto the stack.

Parameters:
aElement - the element to push onto the stack.

isEmpty

public boolean isEmpty()
Returns whether the stack is empty.

Returns:
whether the stack is empty.

size

public int size()
Returns the number of entries in the stack.

Returns:
the number of entries in the stack.

peek

public E peek()
Returns the entry at the top of the stack without removing it.

Returns:
the top entry
Throws:
IllegalStateException - if the stack is empty.

pop

public E pop()
Returns the entry at the top of the stack by removing it.

Returns:
the top entry
Throws:
IllegalStateException - if the stack is empty.

peek

public E peek(int aIndex)
Return the element at the specified index. It does not remove the element from the stack.

Parameters:
aIndex - the index to return
Returns:
the element at the index
Throws:
IllegalArgumentException - if index out of range

contains

public boolean contains(E aElement)
Returns if the stack contains the specified element.

Parameters:
aElement - the element to find
Returns:
whether the stack contains the entry

clear

public void clear()
Clears the stack.


iterator

public Iterator<E> iterator()
Returns an iterator that goes from the oldest element to the newest.

Specified by:
iterator in interface Iterable<E>
Returns:
an iterator

newInstance

public static <T> FastStack<T> newInstance()
Factory method to create a new instance.

Type Parameters:
T - the type of elements to hold in the stack.
Returns:
a new instance of FastStack


Copyright © 2001-2011. All Rights Reserved.