Stack
TypedStack is a wrapper for Stack instances that ensures that
only values of a specific type can be added to the wrapped stack.
This class simply delegates all method invocations to the wrapped stack. If the specific method is responsible for adding values it first checks if the values to add are of the expected type. If they are the method invocation is forwarded, otherwise an IllegalArgumentException is thrown.
new TypedStack()public function TypedStack(type:Function, stack:Stack)
Constructs a new TypedStack instance.
If the passed-in stack does already contain values, these values do not get type-checked.
type | the type of values the stack can have |
stack | the stack to type-check |
| IllegalArgumentException | if the passed-in type is null
or undefined
|
| IllegalArgumentException | if stack is null or
undefined
|
public function getType(Void):FunctionReturns the type that all values in the wrapped stack have.
This is the type passed-in on construction.
the type that all values of the wrapped stack have
public function push(value):VoidPushes the passed-in value to this stack.
The value is only pushed if it is of the expected type.
value | the value to push to this stack |
| IllegalArgumentException | if the type of the passed-in value is
invalid
|
public function pop(Void)Removes and returns the lastly pushed value.
the lastly pushed value
| EmptyDataHolderException | if this stack is empty |
public function peek(Void)Returns the lastly pushed value without removing it.
the lastly pushed value
| EmptyDataHolderException | if this stack is empty |
public function iterator(Void):IteratorReturns an iterator to iterate over the values of this stack.
an iterator to iterate over this stack's values
iterator() in org.as2lib.data.holder.Stack
public function isEmpty(Void):BooleanReturns whether this stack is empty.
true if this stack is empty else false
public function size(Void):NumberReturns the number of pushed values.
the number of pushed values
size() in org.as2lib.data.holder.Stack
public function toArray(Void):ArrayReturns an array representation of this stack.
The elements are copied onto the array in a 'last-in, first-out' order, similar to the order of the elements returned by a succession of calls to the pop method.
the array representation of this stack
public function toString():StringReturns the string representation of the wrapped stack.
the string representation of the wrapped stack
toString() in org.as2lib.core.BasicInterface