Class org.as2lib.data.holder.stack.TypedStack

Implemented Interfaces

Stack

Description

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.

Method Index

new TypedStack()
getType(), isEmpty(), iterator(), peek(), pop(), push(), size(), toArray(), toString()

Constructor Detail

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.

Parameters

typethe type of values the stack can have
stackthe stack to type-check

Throws

IllegalArgumentExceptionif the passed-in type is null or undefined
IllegalArgumentExceptionif stack is null or undefined

Method Detail

getType

public function getType(Void):Function

Returns the type that all values in the wrapped stack have.

This is the type passed-in on construction.

Return

the type that all values of the wrapped stack have

push

public function push(value):Void

Pushes the passed-in value to this stack.

The value is only pushed if it is of the expected type.

Parameters

valuethe value to push to this stack

Throws

IllegalArgumentExceptionif the type of the passed-in value is invalid

Specified By

push() in org.as2lib.data.holder.Stack

pop

public function pop(Void)

Removes and returns the lastly pushed value.

Return

the lastly pushed value

Throws

EmptyDataHolderExceptionif this stack is empty

Specified By

pop() in org.as2lib.data.holder.Stack

peek

public function peek(Void)

Returns the lastly pushed value without removing it.

Return

the lastly pushed value

Throws

EmptyDataHolderExceptionif this stack is empty

Specified By

peek() in org.as2lib.data.holder.Stack

iterator

public function iterator(Void):Iterator

Returns an iterator to iterate over the values of this stack.

Return

an iterator to iterate over this stack's values

Specified By

iterator() in org.as2lib.data.holder.Stack

See Also

isEmpty

public function isEmpty(Void):Boolean

Returns whether this stack is empty.

Return

true if this stack is empty else false

Specified By

isEmpty() in org.as2lib.data.holder.Stack

size

public function size(Void):Number

Returns the number of pushed values.

Return

the number of pushed values

Specified By

size() in org.as2lib.data.holder.Stack

See Also

toArray

public function toArray(Void):Array

Returns 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.

Return

the array representation of this stack

Specified By

toArray() in org.as2lib.data.holder.Stack

toString

public function toString():String

Returns the string representation of the wrapped stack.

Return

the string representation of the wrapped stack

Specified By

toString() in org.as2lib.core.BasicInterface

Overrides

toString() in org.as2lib.core.BasicClass