Packagesystem.data.collections
Classpublic class TypedCollection
InheritanceTypedCollection Inheritance Object
Implements Collection, Typeable, Validator
Subclasses TypedSet

TypedCollection is a wrapper for Collection instances that ensures that only values of a specific type can be added to the wrapped collection.

Example :

     import system.data.collections.ArrayCollection ;
     import system.data.collections.TypedCollection ;
     
     var co:ArrayCollection = new ArrayCollection(["item1", "item2"]) ;
     var tc:TypedCollection = new TypedCollection( String , co ) ;
     
     tc.add( "item3" ) ;
     trace( tc ) ; // {item1,item2,item3}
     
     try
     {
         tc.add( 10 ) ;
     }
     catch( e:Error )
     {
         trace( e.message ) ; // TypedCollection.validate(10) is mismatch.
     }
     



Public Properties
 PropertyDefined By
  type : *
Indicates the type of the Typeable object.
TypedCollection
Public Methods
 MethodDefined By
  
TypedCollection(type:*, collection:Collection)
Creates a new TypedCollection instance.
TypedCollection
  
add(o:*):Boolean
Inserts an element in the collection.
TypedCollection
  
clear():void
Removes all elements in the collection.
TypedCollection
  
clone():*
Returns a shallow copy of this collection.
TypedCollection
  
contains(o:*):Boolean
Returns true if this collection contains the specified element.
TypedCollection
  
get(key:*):*
Returns the element from this collection at the passed key index.
TypedCollection
  
indexOf(o:*, fromIndex:uint = 0):int
Returns the index of an element in the collection.
TypedCollection
  
isEmpty():Boolean
Returns true if this collection contains no elements.
TypedCollection
  
Returns an iterator over the elements in this collection.
TypedCollection
  
remove(o:*):*
Removes a single instance of the specified element from this collection, if it is present (optional operation).
TypedCollection
  
size():uint
Returns the number of elements in this collection.
TypedCollection
  
supports(value:*):Boolean
Returns true if the specific value is valid.
TypedCollection
  
toArray():Array
Returns an array containing all of the elements in this collection.
TypedCollection
  
toSource(indent:int = 0):String
Returns the source code string representation of the object.
TypedCollection
  
toString():String
Returns the String representation of the object.
TypedCollection
  
validate(value:*):void
Evaluates the specified value and throw a TypeError object if the value is not valid.
TypedCollection
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
TypedCollection()Constructor
public function TypedCollection(type:*, collection:Collection)

Creates a new TypedCollection instance.

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

Throws
ArgumentError — if the type is null or undefined.
 
TypeError — if a value in the passed-in Collection object isn't valid.
Method Detail
add()method
public function add(o:*):Boolean

Inserts an element in the collection.

Parameters

o:*

Returns
Boolean
clear()method 
public function clear():void

Removes all elements in the collection.

clone()method 
public function clone():*

Returns a shallow copy of this collection.

Returns
* — a shallow copy of this collection.
contains()method 
public function contains(o:*):Boolean

Returns true if this collection contains the specified element.

Parameters

o:*

Returns
Booleantrue if this collection contains the specified element.
get()method 
public function get(key:*):*

Returns the element from this collection at the passed key index.

Parameters

key:*

Returns
* — the element from this collection at the passed key index.
indexOf()method 
public function indexOf(o:*, fromIndex:uint = 0):int

Returns the index of an element in the collection.

Parameters

o:*
 
fromIndex:uint (default = 0)

Returns
int — the index of an element in the collection.
isEmpty()method 
public function isEmpty():Boolean

Returns true if this collection contains no elements.

Returns
Booleantrue if this collection contains no elements.
iterator()method 
public function iterator():Iterator

Returns an iterator over the elements in this collection.

Returns
Iterator — an iterator over the elements in this collection.
remove()method 
public function remove(o:*):*

Removes a single instance of the specified element from this collection, if it is present (optional operation).

Parameters

o:*

Returns
*
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.
toArray()method 
public function toArray():Array

Returns an array containing all of the elements in this collection.

Note: The returned Array is a reference of the internal Array used in the Collection to store the items. It's not a shallow copy of it.

Returns
Array — an array containing all of the elements in this collection.
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.