com.google.clearsilver.jsilver.data
Class UniqueStack<T>

java.lang.Object
  extended by com.google.clearsilver.jsilver.data.UniqueStack<T>
All Implemented Interfaces:
Iterable<T>

public class UniqueStack<T>
extends Object
implements Iterable<T>

The ResourceStack represents a LIFO stack of unique objects (resources).

An attempt to insert on a stack an object that is already there will fail and result with a method push(Object) returning false.

All provided operations (pop() and push(Object)) are done in average constant time.

This class is iterable


Constructor Summary
UniqueStack()
           
 
Method Summary
 boolean isEmpty()
          Returns true if this stack contains no elements.
 Iterator<T> iterator()
           
 T pop()
          Removes last added object from the stack.
 boolean push(T object)
          Add an object to a stack.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UniqueStack

public UniqueStack()
Method Detail

push

public boolean push(T object)
Add an object to a stack. Object will be added only if it is not already on the stack.

Parameters:
object - to be added. If it is null a NullPointerException will be thrown.
Returns:
true if the object was added successfully

pop

public T pop()
Removes last added object from the stack.

Returns:
last added object
Throws:
NoSuchElementException - - if the stack is empty

isEmpty

public boolean isEmpty()
Returns true if this stack contains no elements.

Returns:
true if this stack contains no elements.

iterator

public Iterator<T> iterator()
Specified by:
iterator in interface Iterable<T>


Copyright © 2010-2012 Google. All Rights Reserved.