Packagecom.bourre.collection
Classpublic class WeakCollection
ImplementsCollection

Player version: Flash Player 9.0
Language version: ActionScript 3.0

A weak collection stores element using weak references instead of the classical hard references. That mean that the integrity of the collection is never guarantee. An element which is in the weak collection could be removed as soon as the Garbage Collector has defined that this element is no longer used in the program.

Weak reference internally use a Dictionnary object instead of an Array. Elements are stored as keys in the dictionnary, resulting that there can be only one occurrence of an element in the collection.

In current state of the art the weak collection allow any types for its elements.

See also

Collection.html


Protected Properties
 PropertyDefined by
  _d : Dictionary
WeakCollection
Public Methods
 MethodDefined by
  
WeakCollection(a:Array = null)
Creates a new weak collection, which initially contains the data from the passed-in array (optional operation).
WeakCollection
  
add(o:Object):Boolean
Adds the passed-in object into this collection.
WeakCollection
  
addAll(c:Collection):Boolean
Adds all of the elements in the specified collection to this collection.
WeakCollection
  
clear():void
Removes all of the elements from this collection.
WeakCollection
  
contains(o:Object):Boolean
Returns true if this collection contains the specified element.
WeakCollection
  
Returns true if this collection contains all of the elements of the specified collection.
WeakCollection
  
isEmpty():Boolean
Returns true if this collection contains no elements.
WeakCollection
  
Returns an iterator over the elements in this collection.
WeakCollection
  
remove(o:Object):Boolean
Removes the specified element from this collection if it is present.
WeakCollection
  
removeAll(c:Collection):Boolean
Removes from this collection all of its elements that are contained in the specified collection.
WeakCollection
  
retainAll(c:Collection):Boolean
Retains only the elements in this collection that are contained in the specified collection.
WeakCollection
  
size():uint
Returns the number of elements in this collection (its cardinality).
WeakCollection
  
toArray():Array
Returns an array containing all the elements in this set.
WeakCollection
  
toString():String
Returns the String representation of this object.
WeakCollection
Property detail
_dproperty
protected var _d:Dictionary

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Constructor detail
WeakCollection()constructor
public function WeakCollection(a:Array = null)

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Creates a new weak collection, which initially contains the data from the passed-in array (optional operation).

Parameters
a:Array (default = null)Array initializer for the collection
Method detail
add()method
public function add(o:Object):Boolean

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Adds the passed-in object into this collection. Returns true if this collection changed as a result of the call. Returns false if this collection does not permit duplicates and already contains the specified element.

Parameters
o:Object — element to add to this collection

Returns
Booleantrue if the collection changed as a result of the call

Example
How to use the WeakCollection.add method
   var col : WeakCollection = new WeakCollection();
   
   col.add( "foo" );
   
   col.add( "foo" ); // return false, as 'foo' already exist in this set
   
In comparison with Java, where object which have all of their properties equals are considered as equals, AS3 doesn't allow that, except if objects provides an equals method which is used instead of the == or === operators. Nevertheless, the WeakCollection class use the native operator to perform comparison, thus two objects with equals properties are considered as differents.
   var col : WeakCollection = new WeakCollection();
   var o : Object = { x : 50, y : 100 };
   
   col.add( o ); 
   col.add( o ); // return false, as o' already exist in this set
   
   col.add( { x : 50, y : 100 } ); // return true, as the argument is not
              // the same object than o, even if all
              // their properties are equals
   

addAll()method 
public function addAll(c:Collection):Boolean

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Adds all of the elements in the specified collection to this collection. If the specified collection is also a weak collection, the addAll operation effectively modifies this set so that its value is the union of the two sets. The behavior of this operation is unspecified if the specified collection is modified while the operation is in progress.

Parameters
c:Collection — c elements to be inserted into this collection.

Returns
Booleantrue if this collection changed as a result of the call

See also

clear()method 
public function clear():void

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Removes all of the elements from this collection. This collection will be empty after this method returns unless it throws an exception.

contains()method 
public function contains(o:Object):Boolean

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Returns true if this collection contains the specified element. More formally, returns true if and only if this collection contains an element e such that o === e.

Parameters
o:ObjectObject whose presence in this set is to be tested.

Returns
Booleantrue if this set contains the specified element.
containsAll()method 
public function containsAll(c:Collection):Boolean

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Returns true if this collection contains all of the elements of the specified collection. If the specified collection is also a WeakCollection, this method returns true if it is a subset of this collection.

Parameters
c:CollectionCollection to be checked for containment in this collection.

Returns
Booleantrue if this collection contains all of the elements of the specified collection.

Throws
NullPointerException — if the specified collection is null.

See also

isEmpty()method 
public function isEmpty():Boolean

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Returns true if this collection contains no elements.

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

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Returns an iterator over the elements in this collection. The elements are returned in no particular order.

Returns
Iterator — an iterator over the elements in this set.
remove()method 
public function remove(o:Object):Boolean

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Removes the specified element from this collection if it is present. More formally, removes an element e such that o === e, if the collection contains such an element. Returns true if the collection contained the specified element (or equivalently, if the collection changed as a result of the call). (The collection will not contain the specified element once the call returns.)

Parameters
o:Objectobject to be removed from this collection, if present.

Returns
Booleantrue if the collection contained the specified element.

Example
Using the WeakCollection.remove() method :
   var set : Set = new Set();
   set.add ( "foo" );
   
   trace( set.size() ); // 1
   trace( set.remove( "foo" ) ); // true, the passed-in value have been removed
   
   trace( set.size() ); // 0
   trace( set.remove( "foo" ) ); // false, the passed-in value is no longer stored in this set
   

removeAll()method 
public function removeAll(c:Collection):Boolean

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Removes from this collection all of its elements that are contained in the specified collection. If the specified Collection is also a WeakCollection, this operation effectively modifies this collection so that its value is the asymmetric difference of the two collections.

Parameters
c:CollectionCollection that defines which elements will be removed from this collection.

Returns
Booleantrue if this collection changed as a result of the call.

Throws
NullPointerException — if the specified collection is null.

See also


Example
Using the WeakCollection.removeAll() method
   var col1 : WeakCollectio = new WeakCollectio();
   var col2 : WeakCollectio = new WeakCollectio();
   
   col1.add( 1 );
   col1.add( 2 );
   col1.add( 3 );
   col1.add( 4 );
   col1.add( "foo1" );
   col1.add( "foo2" );
   col1.add( "foo3" );
   col1.add( "foo4" );
   
   col2.add( 1 );
   col2.add( 3 );
   col2.add( "foo1" );
   col2.add( "foo3" );
   
   trace ( col1.removeAll ( col2 ) ) ;// true
   // col1 now contains :
   // 2, 4, 'foo2', 'foo4' 
   

retainAll()method 
public function retainAll(c:Collection):Boolean

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Retains only the elements in this collection that are contained in the specified collection. In other words, removes from this collection all of its elements that are not contained in the specified collection. If the specified collection is also a WeakCollection, this operation effectively modifies this set so that its value is the intersection of the two sets.

Parameters
c:CollectionCollection that defines which elements this collection will retain.

Returns
Booleantrue if this collection changed as a result of the call.

Throws
NullPointerException — if the specified collection is null.

See also


Example
Using the WeakCollection.retainAll() method
   var col1 : WeakCollection = new WeakCollection();
   var col2 : WeakCollection = new WeakCollection();
   
   col1.add( 1 );
   col1.add( 2 );
   col1.add( 3 );
   col1.add( 4 );
   col1.add( "foo1" );
   col1.add( "foo2" );
   col1.add( "foo3" );
   col1.add( "foo4" );
   
   col2.add( 1 );
   col2.add( 3 );
   col2.add( "foo1" );
   col2.add( "foo3" );
   
   trace ( col1.retainAll ( col2 ) ) ;// true
   // col1 now contains :
   // 1, 3, 'foo1', 'foo3' 
   

size()method 
public function size():uint

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Returns the number of elements in this collection (its cardinality).

Returns
uintNumber of elements in this collection (its cardinality).
toArray()method 
public function toArray():Array

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Returns an array containing all the elements in this set. Obeys the general contract of the Collection.toArray method.

Returns
ArrayArray containing all of the elements in this set.

See also

toString()method 
public function toString():String

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Returns the String representation of this object.

Returns
StringString representation of this object.