Packagesystem.data.stacks
Classpublic class TypedStack
InheritanceTypedStack Inheritance Object
Implements Stack, Typeable, Validator

TypedStack is a wrapper for Stack instances that ensures that only values of a specific type can be added to the wrapped stack.

Example :

     import system.data.stacks.ArrayStack ;
     import system.data.stacks.TypedStack ;
     
     var s:ArrayStack = new ArrayStack() ;
     var t:TypedStack = new TypedStack( String , s  ) ;
     
     t.push("item1") ;
     t.push("item2") ;
     
     trace( t ) ; // {item1,item2}
     
     try
     {
         t.push( 1 ) ;
     }
     catch( e:TypeError )
     {
         trace( e.message ) ; // TypedStack.validate(1) is mismatch.
     }
     



Public Properties
 PropertyDefined By
  type : *
Indicates the type of the Typeable object.
TypedStack
Public Methods
 MethodDefined By
  
TypedStack(type:*, stack:Stack)
Creates a new TypedStack instance.
TypedStack
  
clear():void
Removes all of the elements from this stack (optional operation).
TypedStack
  
clone():*
Creates and returns a shallow copy of the object.
TypedStack
  
isEmpty():Boolean
Returns true if this stack contains no elements.
TypedStack
  
Returns the iterator reference of the object.
TypedStack
  
peek():*
Returns the lastly pushed value without removing it.
TypedStack
  
pop():*
Removes and returns the lastly pushed value.
TypedStack
  
push(o:*):void
Pushes the passed-in value to this stack.
TypedStack
  
search(o:*):int
Search a value in the stack.
TypedStack
  
size():uint
Returns the number of elements in this collection.
TypedStack
  
supports(value:*):Boolean
Returns true if the specific value is valid.
TypedStack
  
toSource(indent:int = 0):String
Returns the source code string representation of the object.
TypedStack
  
toString():String
Returns the String representation of the object.
TypedStack
  
validate(value:*):void
Evaluates the specified value and throw a TypeError object if the value is not valid.
TypedStack
Property Detail
typeproperty
type:*

Indicates the type of the Typeable object.

If the type change the clear() method is invoked.


Implementation
    public function get type():*
    public function set type(value:any):void
Constructor Detail
TypedStack()Constructor
public function TypedStack(type:*, stack:Stack)

Creates a new TypedStack instance.

Parameters
type:* — the type of this Typeable object (a Class or a Function).
 
stack:Stack — The Stack reference of this wrapper.

Throws
ArgumentError — if the type is null or undefined.
 
TypeError — if a value in the passed-in Stack object isn't valid.
Method Detail
clear()method
public function clear():void

Removes all of the elements from this stack (optional operation).

clone()method 
public function clone():*

Creates and returns a shallow copy of the object.

Returns
* — A new object that is a shallow copy of this instance.
isEmpty()method 
public function isEmpty():Boolean

Returns true if this stack contains no elements.

Returns
Booleantrue if this stack is empty else false.
iterator()method 
public function iterator():Iterator

Returns the iterator reference of the object.

Returns
Iterator — the iterator reference of the object.
peek()method 
public function peek():*

Returns the lastly pushed value without removing it.

Returns
*

Throws
the — lastly pushed value.
pop()method 
public function pop():*

Removes and returns the lastly pushed value.

Returns
* — the lastly pushed value
push()method 
public function push(o:*):void

Pushes the passed-in value to this stack.

Parameters

o:*

search()method 
public function search(o:*):int

Search a value in the stack.

Parameters

o:*

Returns
int — the index position of a value in the stack.
size()method 
public function size():uint

Returns the number of elements in this collection.

Returns
uint — the number of elements in this collection.
supports()method 
public function supports(value:*):Boolean

Returns true if the specific value is valid.

Parameters

value:*

Returns
Booleantrue if the specific value is valid.
toSource()method 
public function toSource(indent:int = 0):String

Returns the source code string representation of the object.

Parameters

indent:int (default = 0)

Returns
String — the source code string representation of the object.
toString()method 
public function toString():String

Returns the String representation of the object.

Returns
String — the String representation of the object.
validate()method 
public function validate(value:*):void

Evaluates the specified value and throw a TypeError object if the value is not valid.

Parameters

value:*


Throws
TypeError — if the value is not valid.