Packagesystem.data.bags
Classpublic class HashBag
InheritanceHashBag Inheritance CoreMapBag Inheritance Object

Implements Bag, using a HashMap to provide the data storage. This is the standard implementation of a bag.

Example :

     import system.data.Bag ;
     import system.data.bags.HashBag ;
     
     import system.data.Collection ;
     import system.data.collections.ArrayCollection ;
     import system.data.Set ;
     
     var c1:Collection = new ArrayCollection( ["item1", "item1", "item3"] ) ;
     var c2:Collection = new ArrayCollection( ["item1", "item2", "item3", "item4", "item5"] ) ;
     
     trace ("c1 collection : " + c1) ;
     trace ("c2 collection : " + c2) ;
     
     trace ("---- create a new HashBag") ;
     
     var bag:Bag = new HashBag() ;
     
     trace ("---- add") ;
     trace (" + bag addAll c1 : " + bag.addAll(c1)) ;
     trace (" + bag addAll c2 : " + bag.addAll(c2)) ;
     trace (" > bag : " + bag) ;
     trace (" > bag.toSource : " + bag.toSource()) ;
     
     trace ("---- contains") ;
     trace (" > bag containsAll c2 : " + bag.containsAll(c2)) ;
     
     trace ("---- add") ;
     trace (" + bag add item2 : " + bag.add("item2") ) ;
     trace (" > bag : " + bag ) ;
     trace (" + bag addCopies 2xitem2 : " + bag.addCopies("item2", 2)) ;
     trace (" > bag : " + bag) ;
     
     trace ("---- remove") ;
     trace (" > bag removeCopies 1 x item2 : " + bag.removeCopies("item2", 1)) ;
     
     trace ("---- size") ;
     trace (" - bag getCount item2 : " + bag.getCount("item2")) ;
     trace (" > bag size : " + bag.size()) ;
     
     trace ("---- retain") ;
     trace (" > bag : " + bag) ;
     trace (" > bag retainAll c1 : " + bag.retainAll(c1)) ;
     trace (" > bag : " + bag) ;
     
     trace ("----") ;
     
     var s:Set = bag.uniqueSet() ;
     trace("bag uniqueSet : " + s) ;
     



Public Properties
 PropertyDefined By
 InheritedmodCount : int
This property is a protector used in the BagIterator object of this bag.
CoreMapBag
Public Methods
 MethodDefined By
  
HashBag(co:Collection = null)
Creates a new HashBag instance.
HashBag
 Inherited
add(o:*):Boolean
Add one copy of the given object to the bag and keep a count.
CoreMapBag
 Inherited
addAll(c:Collection):Boolean
Insert all elements represented in the given collection.
CoreMapBag
 Inherited
addCopies(o:*, nCopies:uint):Boolean
Add n copies of the given object to the bag and keep a count.
CoreMapBag
 Inherited
clear():void
Removes all of the elements from this bag.
CoreMapBag
  
clone():*
[override] Returns the shallow copy of this bag.
HashBag
 Inherited
contains(o:*):Boolean
Returns true if this bag contains the object passed in argument.
CoreMapBag
 Inherited
Returns true if thie bag contains all object in the passed collection in argument.
CoreMapBag
 Inherited
Returns true if thie bag contains all object in the passed bag in argument.
CoreMapBag
 Inherited
equals(o:*):Boolean
Compares this Bag to another.
CoreMapBag
 Inherited
get(key:*):*
Unsupported by bag objects.
CoreMapBag
 Inherited
getCount(o:*):uint
Returns the count of the specified object passed in argument.
CoreMapBag
 Inherited
indexOf(o:*, fromIndex:uint = 0):int
Unsupported by bag objects.
CoreMapBag
 Inherited
isEmpty():Boolean
Returns true if the bag is empty.
CoreMapBag
 Inherited
Returns the Iterator representation of the Bag.
CoreMapBag
 Inherited
remove(o:*):*
Removes the object in argument in the bag.
CoreMapBag
 Inherited
Removes objects from the bag according to their count in the specified collection.
CoreMapBag
 Inherited
removeCopies(o:*, nCopies:uint):Boolean
Removes a specified number of copies of an object from the bag.
CoreMapBag
 Inherited
Removes any members of the bag that are not in the given collection, respecting cardinality.
CoreMapBag
 Inherited
retainAllInBag(b:Bag):Boolean
Removes any members of the bag that are not in the given bag, respecting cardinality.
CoreMapBag
 Inherited
size():uint
Returns the number of elements in this bag (its cardinality).
CoreMapBag
 Inherited
toArray():Array
Returns the array representation of the bag.
CoreMapBag
  
toSource(indent:int = 0):String
[override] Returns the source code string representation of the object.
HashBag
 Inherited
toString():String
Returns the string representation of this instance.
CoreMapBag
 Inherited
Returns the Set of unique members that represent all members in the bag.
CoreMapBag
Constructor Detail
HashBag()Constructor
public function HashBag(co:Collection = null)

Creates a new HashBag instance.

Parameters
co:Collection (default = null) — a Collection to constructs a bag containing all the members of the given collection.
Method Detail
clone()method
override public function clone():*

Returns the shallow copy of this bag.

Returns
* — the shallow copy of this bag.
toSource()method 
override 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.