| 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.
protected var _d:Dictionary
| Player version: | Flash Player 9.0 |
| Language version: | ActionScript 3.0 |
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
|
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
| Boolean — true 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
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
| Boolean — true if this collection changed as a result of the
call
|
See also
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.
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:Object — Object whose presence in this set
is to be tested.
|
Returns
| Boolean — true if this set contains the specified
element.
|
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:Collection — Collection to be checked for containment
in this collection.
|
Returns
| Boolean — true if this collection contains all of the
elements of the specified collection.
|
Throws
| — NullPointerException — if the specified collection is
null.
|
See also
public function isEmpty():Boolean
| Player version: | Flash Player 9.0 |
| Language version: | ActionScript 3.0 |
Returns true if this collection contains no elements.
Returns
| Boolean — true if this collection contains no elements
|
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.
|
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:Object — object to be removed from this collection,
if present.
|
Returns
| Boolean — true 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
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:Collection — Collection that defines which elements will be
removed from this collection.
|
Returns
| Boolean — true 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'
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:Collection — Collection that defines which elements this
collection will retain.
|
Returns
| Boolean — true 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'
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
| uint — Number of elements in this collection (its cardinality).
|
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
| Array — Array containing all of the elements in this set.
|
See also
public function toString():String
| Player version: | Flash Player 9.0 |
| Language version: | ActionScript 3.0 |
Returns the String representation of
this object.
Returns
| String — String representation of
this object.
|
LowRA API documentation 2008- 2009
Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1
mer. févr. 25 2009, 9:22 AM GMT+01:00