Package com.ibm.wala.util.collections
Class ImmutableStack<T>
- java.lang.Object
-
- com.ibm.wala.util.collections.ImmutableStack<T>
-
- All Implemented Interfaces:
java.lang.Iterable<T>
public class ImmutableStack<T> extends java.lang.Object implements java.lang.Iterable<T>An immutable stack of objects. Thepush(Object)andpop()operations create new stacks.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedImmutableStack(T[] entries)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontains(T entry)static <T> ImmutableStack<T>emptyStack()booleanequals(java.lang.Object o)Tget(int i)static intgetMaxSize()inthashCode()booleanisEmpty()java.util.Iterator<T>iterator()protected T[]makeInternalArray(int size)protected ImmutableStack<T>makeStack(T[] tmpEntries)Tpeek()ImmutableStack<T>pop()ImmutableStack<T>popAll(ImmutableStack<T> other)ImmutableStack<T>push(T entry)ImmutableStack<T>pushAll(ImmutableStack<T> other)ImmutableStack<T>replaceTop(T t)return a new stack with the top replaced with tImmutableStack<T>reverse()intsize()booleantopMatches(ImmutableStack<T> other)java.lang.StringtoString()
-
-
-
Constructor Detail
-
ImmutableStack
protected ImmutableStack(T[] entries)
-
-
Method Detail
-
getMaxSize
public static int getMaxSize()
-
emptyStack
public static final <T> ImmutableStack<T> emptyStack()
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
push
public ImmutableStack<T> push(T entry)
-
makeInternalArray
protected T[] makeInternalArray(int size)
-
makeStack
protected ImmutableStack<T> makeStack(T[] tmpEntries)
-
peek
public T peek()
- Returns:
- the element on the top of the stack
- Throws:
java.util.EmptyStackException- if stack is empty
-
pop
public ImmutableStack<T> pop()
- Throws:
java.util.EmptyStackException- if stack is empty
-
isEmpty
public boolean isEmpty()
-
size
public int size()
-
get
public T get(int i)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
contains
public boolean contains(T entry)
-
topMatches
public boolean topMatches(ImmutableStack<T> other) throws java.lang.IllegalArgumentException
- Returns:
trueiffother.size() = k,k <= this.size(), and the top k elements of this equal other- Throws:
java.lang.IllegalArgumentException- if other == null
-
reverse
public ImmutableStack<T> reverse()
-
popAll
public ImmutableStack<T> popAll(ImmutableStack<T> other)
-
pushAll
public ImmutableStack<T> pushAll(ImmutableStack<T> other)
-
iterator
public java.util.Iterator<T> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<T>
-
replaceTop
public ImmutableStack<T> replaceTop(T t)
return a new stack with the top replaced with t
-
-