Share 'Examples' on Delicious Share 'Examples' on Facebook Share 'Examples' on Google Bookmarks Share 'Examples' on Twitter

  1. Create a nested collection
  2. Fast populate a collection
  3. Copy a list
  4. Clone a list
  5. Fast populate a list
  6. Copy a set
  7. Clone a set
  8. Fast populate a set
  9. Copy a map
  10. Clone a map
  11. Fast populate a map
  12. Dump a Collection
  13. All Examples
    1. Collections
    2. Iterators
    3. Bindable Collections
    4. Collection Events
    5. Special Iterators
    6. Sorted Collections
    7. Tools and Utils
  14. Comments (2)
  15. Leave a Comment

Examples

Categories: Collection (10), Bindable Collection (11), List (7), Set (9), Map (9), Iterator (9), ArrayList (2), SortedList (2), LinkedSet (2), SortedSet (2), LinkedMap (2), SortedMap (2), Collection Event (3), Tools and Utils (12), Special Iterators (4), Sorted Collections (8)

Create a nested collection

Creating a nested collection is easy using the util classes.

Category: Tools and Utils
NestedCollectionsExample.as: Source raw, Source highlighted
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package {
  import org.as3commons.collections.ArrayList;
  import org.as3commons.collections.LinkedSet;
  import org.as3commons.collections.framework.IComparator;
  import org.as3commons.collections.utils.*;
  import flash.display.Sprite;

  public class NestedCollectionsExample extends Sprite {

    public function NestedCollectionsExample() {
      // nested array list
      var list : ArrayList = Lists.newArrayList(
        Lists.newArrayList(1, 2),
        Lists.newArrayList(
          Lists.newArrayList(3, 4),
          Lists.newArrayList(5, 6)
        ),
        Lists.newArrayList(7, 8),
        Lists.newArrayList(
          Lists.newArrayList(9, 10),
          Lists.newArrayList(11, 12)
        )
      );
      trace (CollectionUtils.dumpAsString(list));
      //  [object ArrayList]
      //  .......[object ArrayList]
      //  ..............1
      //  ..............2
      //  .......[object ArrayList]
      //  ..............[object ArrayList]
      //  .....................3
      //  .....................4
      //  ..............[object ArrayList]
      //  .....................5
      //  .....................6
      //  .......[object ArrayList]
      //  ..............7
      //  ..............8
      //  .......[object ArrayList]
      //  ..............[object ArrayList]
      //  .....................9
      //  .....................10
      //  ..............[object ArrayList]
      //  .....................11
      //  .....................12    
     
      // nested mixed collection
      var c : IComparator = new NumericComparator();
      var theSet : LinkedSet = Sets.newLinkedSet(
        Maps.newLinkedMap("one", 1, "two", 2),
        Lists.newArrayList(
          Sets.newSortedSet(c, 4, 3),
          LinkedLists.newLinkedList(5, 6)
        ),
        Lists.newSortedList(c, 8, 7),
        Lists.newArrayList(
          Maps.newLinkedMap("nine", 9, "ten", 10),
          Maps.newSortedMap(c, "twelve", 12, "eleven", 11)
        )
      );
      trace (CollectionUtils.dumpAsString(theSet));
      //  [object LinkedSet]
      //  .......[object LinkedMap]
      //  ..............1
      //  ..............2
      //  .......[object ArrayList]
      //  ..............[object SortedSet]
      //  .....................3
      //  .....................4
      //  ..............[object LinkedList]
      //  .....................5
      //  .....................6
      //  .......[object SortedList]
      //  ..............7
      //  ..............8
      //  .......[object ArrayList]
      //  ..............[object LinkedMap]
      //  .....................9
      //  .....................10
      //  ..............[object SortedMap]
      //  .....................11
      //  .....................12    
    }
  }
}

Fast populate a collection

You may use variable argument lists to add multiple items at once.

Category: Tools and Utils
AddFromArgsExample.as: Source raw, Source highlighted
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package {
  import org.as3commons.collections.framework.*;
  import org.as3commons.collections.utils.*;
  import flash.display.Sprite;

  public class AddFromArgsExample extends Sprite {

    public function AddFromArgsExample() {
      // ArrayList
      var list : IList = Lists.newArrayList(
        1, 2, 3, 4, 5, 6, 7, 8
      );
      trace (list.toArray() + "\n");
      // 1, 2, 3, 4, 5, 6, 7, 8
     
      // ArrayList
      list = Lists.newSortedList(
        new NumericComparator(),
        6, 3, 1, 5, 8, 2, 7, 4
      );
      trace (list.toArray() + "\n");
      // 1, 2, 3, 4, 5, 6, 7, 8
     
      // Set
      var theSet : ISet = Sets.newSet(
        1, 2, 3, 4, 5, 6, 7, 8
      );
      trace (theSet.toArray() + "\n");
      // 1, 2, 3, 4, 5, 6, 7, 8
     
      // LinkedSet
      theSet = Sets.newLinkedSet(
        1, 2, 3, 4, 5, 6, 7, 8
      );
      trace (theSet.toArray() + "\n");
      // 1, 2, 3, 4, 5, 6, 7, 8
     
      // SortedSet
      theSet = Sets.newSortedSet(
        new NumericComparator(),
        6, 3, 1, 5, 8, 2, 7, 4
      );
      trace (theSet.toArray() + "\n");
      // 1, 2, 3, 4, 5, 6, 7, 8
     
      // Map
      var map : IMap = Maps.newMap(
        "one", 1, "two", 2, "three", 3, "four", 4
      );
      trace (map.toArray() + "\n");
      // 1, 4, 2, 3
     
      // LinkedMap
      map = Maps.newLinkedMap(
        "one", 1, "two", 2, "three", 3, "four", 4
      );
      trace (map.toArray() + "\n");
      // 1, 2, 3, 4
     
      // SortedMap
      map = Maps.newSortedMap(
        new NumericComparator(),
        "one", 1, "two", 2, "three", 3, "four", 4
      );
      trace (map.toArray() + "\n");
      // 1, 2, 3, 4
     
      // LinkedList
      var linkedList : ILinkedList = LinkedLists.newLinkedList(
        1, 2, 3, 4, 5, 6, 7, 8
      );
      trace (linkedList.toArray() + "\n");
      // 1, 2, 3, 4, 5, 6, 7, 8
    }

  }
}

Copy a list

Copy items from a list to another. It is possible to customize the copy process using filters.

ListsCopyExample.as: Source raw, Source highlighted
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package {
  import org.as3commons.collections.framework.IList;
  import org.as3commons.collections.utils.Lists;
  import org.as3commons.collections.utils.NumericComparator;
  import flash.display.Sprite;

  public class ListsCopyExample extends Sprite {
    public function ListsCopyExample() {
      // source
      var source : IList = Lists.newArrayList(1, 2, 3, 4);
      trace (source.toArray() + "\n");
      //  1, 2, 3, 4
     
      // copy all
      var list : IList = Lists.newSortedList(
        new NumericComparator(),
        5, 6, 7, 8
      );
      trace (list.toArray() + "\n");
      //  5, 6, 7, 8
      Lists.copy(source, list);
      trace (list.toArray() + "\n");
      //  1, 2, 3, 4, 5, 6, 7, 8

      // copy only even items
      list = Lists.newSortedList(
        new NumericComparator(),
        6, 8
      );
      trace (list.toArray() + "\n");
      //  6, 8
      Lists.copy(source, list, evenFilter);
      trace (list.toArray() + "\n");
      //  2, 4, 6, 8
    }
   
    private function evenFilter(item : *) : Boolean {
      return item % 2 == 0;
    }

  }
}

Clone a list

Clone an entire list. It is possible to customize the clone process using filters.

ListsCopyExample.as: Source raw, Source highlighted
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package {
  import org.as3commons.collections.framework.IList;
  import org.as3commons.collections.utils.Lists;
  import org.as3commons.collections.utils.NumericComparator;
  import flash.display.Sprite;

  public class ListsCopyExample extends Sprite {
    public function ListsCopyExample() {
      // source
      var source : IList = Lists.newArrayList(1, 2, 3, 4);
      trace (source.toArray() + "\n");
      //  1, 2, 3, 4
     
      // copy all
      var list : IList = Lists.newSortedList(
        new NumericComparator(),
        5, 6, 7, 8
      );
      trace (list.toArray() + "\n");
      //  5, 6, 7, 8
      Lists.copy(source, list);
      trace (list.toArray() + "\n");
      //  1, 2, 3, 4, 5, 6, 7, 8

      // copy only even items
      list = Lists.newSortedList(
        new NumericComparator(),
        6, 8
      );
      trace (list.toArray() + "\n");
      //  6, 8
      Lists.copy(source, list, evenFilter);
      trace (list.toArray() + "\n");
      //  2, 4, 6, 8
    }
   
    private function evenFilter(item : *) : Boolean {
      return item % 2 == 0;
    }

  }
}

Fast populate a list

Use the Lists.addFrom…() methods to easily set up a list collection.

ListsAddFromExample.as: Source raw, Source highlighted
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package {
  import org.as3commons.collections.ArrayList;
  import org.as3commons.collections.LinkedList;
  import org.as3commons.collections.Map;
  import org.as3commons.collections.utils.Lists;
  import flash.display.Sprite;

  public class ListsAddFromExample extends Sprite {

    public function ListsAddFromExample() {
      // list to populate
      var list : ArrayList = new ArrayList();

      // from array (ordered)
      var a : Array = [1, "2", "2"];
      Lists.addFromArray(list, a);

      // from linked list (ordered)
      var l : LinkedList = new LinkedList();
      l.add("2");
      l.add(3);
      l.add("4");
      l.add(3);
      Lists.addFromCollection(list, l);

      // from map (no order)
      var m : Map = new Map();
      m.add("five", 5);
      m.add("six", "6");
      m.add("four", "4");
      Lists.addFromCollection(list, m);

      // from args (ordered)
      Lists.addFromArgs(list,
        7, "8", "8", 5
      );

      // test
      trace (list.toArray().join("\n"));
     
      //  1     // from array
      //  2
      //  2
      //  2     // from linked list
      //  3
      //  4
      //  3
      //  4     // from map
      //  6
      //  5
      //  7     // from args
      //  8
      //  8
      //  5
    }

  }
}

Copy a set

Copy items from a set to another. It is possible to customize the copy process using filters.

Category: Tools and Utils, Set
SetsCopyExample.as: Source raw, Source highlighted
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package {
  import org.as3commons.collections.framework.ISet;
  import org.as3commons.collections.utils.Sets;
  import org.as3commons.collections.utils.NumericComparator;
  import flash.display.Sprite;

  public class SetsCopyExample extends Sprite {
    public function SetsCopyExample() {
      // source
      var source : ISet = Sets.newLinkedSet(1, 2, 3, 4);
      trace (source.toArray() + "\n");
      //  1, 2, 3, 4
     
      // copy all
      var theSet : ISet = Sets.newSortedSet(
        new NumericComparator(),
        5, 6, 7, 8
      );
      trace (theSet.toArray() + "\n");
      //  5, 6, 7, 8
      Sets.copy(source, theSet);
      trace (theSet.toArray() + "\n");
      //  1, 2, 3, 4, 5, 6, 7, 8

      // copy only even items
      theSet = Sets.newSortedSet(
        new NumericComparator(),
        6, 8
      );
      trace (theSet.toArray() + "\n");
      //  6, 8
      Sets.copy(source, theSet, evenFilter);
      trace (theSet.toArray() + "\n");
      //  2, 4, 6, 8
    }
   
    private function evenFilter(item : *) : Boolean {
      return item % 2 == 0;
    }

  }
}

Clone a set

Clone an entire set. It is possible to customize the clone process using filters.

Category: Tools and Utils, Set
SetsCloneExample.as: Source raw, Source highlighted
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package {
  import org.as3commons.collections.utils.NumericComparator;
  import flash.utils.getQualifiedClassName;
  import org.as3commons.collections.framework.ISet;
  import org.as3commons.collections.utils.Sets;
  import flash.display.Sprite;

  public class SetsCloneExample extends Sprite {

    public function SetsCloneExample() {
      // clone simple set
      var theSet : ISet = Sets.newSet(2, 4, 1, 3);
      var clone : ISet = Sets.clone(theSet);
      trace (theSet.toArray().join("\n"));
      trace (getQualifiedClassName(clone));
      //  1
      //  2
      //  3
      //  4
      //  org.as3commons.collections::Set
     
      // clone linked theSet
      theSet = Sets.newLinkedSet(2, 4, 1, 3);
      clone = Sets.clone(theSet);
      trace (theSet.toArray().join("\n"));
      trace (getQualifiedClassName(clone));
      //  2
      //  4
      //  1
      //  3
      //  org.as3commons.collections::LinkedSet

      // clone sorted set
      theSet = Sets.newSortedSet(
        new NumericComparator(),
        2, 4, 1, 3
      );
      clone = Sets.clone(theSet);
      trace (theSet.toArray().join("\n"));
      trace (getQualifiedClassName(clone));
      //  1
      //  2
      //  3
      //  4
      //  org.as3commons.collections::SortedSet
    }
   
  }
}

Fast populate a set

Use the Sets.addFrom…() methods to easily set up a set collection.

Category: Tools and Utils, Set
SetsAddFromExample.as: Source raw, Source highlighted
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package {
  import org.as3commons.collections.LinkedList;
  import org.as3commons.collections.LinkedSet;
  import org.as3commons.collections.Map;
  import org.as3commons.collections.utils.Sets;
  import flash.display.Sprite;

  public class SetsAddFromExample extends Sprite {

    public function SetsAddFromExample() {
      // set to populate
      var theSet : LinkedSet = new LinkedSet();

      // from array (ordered)
      var a : Array = [1, "2", "2"]; // second "2" ignored by set
      Sets.addFromArray(theSet, a);

      // from linked list (ordered)
      var l : LinkedList = new LinkedList();
      l.add("2"); // ignored by set
      l.add(3);
      l.add("4");
      l.add(3); // ignored by set
      Sets.addFromCollection(theSet, l);

      // from map (no order)
      var m : Map = new Map();
      m.add("five", 5);
      m.add("six", "6");
      m.add("four", "4"); // ignored by set
      Sets.addFromCollection(theSet, m);

      // from args (ordered)
      Sets.addFromArgs(theSet,
        7, "8", "6" // "6" ignored by set
      );

      // test
      trace (theSet.toArray().join("\n"));
     
      //  1     // from array
      //  2
      //  3     // from linked list
      //  4
      //  6     // from map
      //  5
      //  7     // from args
      //  8
    }

  }
}

Copy a map

Copy items from a map to another. It is possible to customize the copy process using filters.

Category: Tools and Utils, Map
MapsCopyExample.as: Source raw, Source highlighted
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package {
  import org.as3commons.collections.framework.IMap;
  import org.as3commons.collections.framework.IMapIterator;
  import org.as3commons.collections.utils.Maps;
  import org.as3commons.collections.utils.NumericComparator;
  import flash.display.Sprite;

  public class MapsCopyExample extends Sprite {
    public function MapsCopyExample() {
      // source
      var source : IMap = Maps.newLinkedMap(
        1, 1, 2, 1,
        3, 2, 4, 2
      );
      dumpMap(source);
      //  1 => 1
      //  2 => 1
      //  3 => 2
      //  4 => 2
     
      // copy all
      var map : IMap = Maps.newSortedMap(
        new NumericComparator(),
        5, 3, 6, 3,
        7, 4, 8, 4
      );
      dumpMap(map);
      //  5 => 3
      //  6 => 3
      //  7 => 4
      //  8 => 4
      Maps.copy(source, map);
      dumpMap(map);
      //  1 => 1
      //  2 => 1
      //  3 => 2
      //  4 => 2
      //  5 => 3
      //  6 => 3
      //  7 => 4
      //  8 => 4

      // copy only even keys
      map = Maps.newSortedMap(
        new NumericComparator(),
        6, 3,
        8, 4
      );
      dumpMap(map);
      //  6 => 3
      //  8 => 4
      Maps.copy(source, map, evenFilter);
      dumpMap(map);
      //  2 => 1
      //  4 => 2
      //  6 => 3
      //  8 => 4

      // copy only even items
      map = Maps.newSortedMap(
        new NumericComparator(),
        7, 4, 8, 4
      );
      dumpMap(map);
      //  7 => 4
      //  8 => 4
      Maps.copy(source, map, null, evenFilter);
      dumpMap(map);
      //  3 => 2
      //  4 => 2
      //  7 => 4
      //  8 => 4

      // copy only even keys with even items
      map = Maps.newSortedMap(
        new NumericComparator(),
        8, 4
      );
      dumpMap(map);
      //  8 => 4
      Maps.copy(source, map, evenFilter, evenFilter);
      dumpMap(map);
      //  4 => 2
      //  8 => 4
    }
   
    private function evenFilter(item : *) : Boolean {
      return item % 2 == 0;
    }

    private function dumpMap(map : IMap) : void {
      var i : IMapIterator = map.iterator() as IMapIterator;
      while (i.next()) trace (i.key, "=>", i.current);
      trace();
    }

  }
}

Clone a map

Clone an entire map. It is possible to customize the clone process using filters.

Category: Tools and Utils, Map
MapsCloneExample.as: Source raw, Source highlighted
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package {
  import org.as3commons.collections.utils.NumericComparator;
  import flash.utils.getQualifiedClassName;
  import org.as3commons.collections.framework.IMap;
  import org.as3commons.collections.framework.IMapIterator;
  import org.as3commons.collections.utils.Maps;
  import flash.display.Sprite;

  public class MapsCloneExample extends Sprite {

    public function MapsCloneExample() {
      // clone simple map
      var map : IMap = Maps.newMap(
        "two", 2, "four", 4, "one", 1, "three", 3
      );
      var clone : IMap = Maps.clone(map);
      dumpMap(clone);
      trace (getQualifiedClassName(clone));
      //  three => 3
      //  four => 4
      //  one => 1
      //  two => 2
      //  org.as3commons.collections::Map
     
      // clone linked map
      map = Maps.newLinkedMap(
        "two", 2, "four", 4, "one", 1, "three", 3
      );
      clone = Maps.clone(map);
      dumpMap(clone);
      trace (getQualifiedClassName(clone));
      //  two => 2
      //  four => 4
      //  one => 1
      //  three => 3
      //  org.as3commons.collections::LinkedMap

      // clone sorted map
      map = Maps.newSortedMap(
        new NumericComparator(),
        "two", 2, "four", 4, "one", 1, "three", 3
      );
      clone = Maps.clone(map);
      dumpMap(clone);
      trace (getQualifiedClassName(clone));
      //  one => 1
      //  two => 2
      //  three => 3
      //  four => 4
      //  org.as3commons.collections::SortedMap
    }
   
    private function dumpMap(map : IMap) : void {
      var i : IMapIterator = map.iterator() as IMapIterator;
      while (i.next()) trace (i.key, "=>", i.current);
    }
  }
}

Fast populate a map

Use the Maps.addFrom…() methods to easily set up a map collection.

Category: Tools and Utils, Map
MapsAddFromExample.as: Source raw, Source highlighted
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package {
  import org.as3commons.collections.LinkedMap;
  import org.as3commons.collections.framework.IMapIterator;
  import org.as3commons.collections.utils.Maps;
  import flash.display.Sprite;
  import flash.utils.Dictionary;

  public class MapsAddFromExample extends Sprite {

    public function MapsAddFromExample() {
      // map to populate
      var map : LinkedMap = new LinkedMap();

      // from object (no order)
      var o : Object = {
        1: "1",
        "2": "two"
      };
      Maps.addFromObject(map, o);

      // from dictionary (no order)
      var d : Dictionary = new Dictionary();
      d["2"] = "two (2)"; // ignored by map
      d[3] = "3";
      d["4"] = "four";
      Maps.addFromObject(map, d);

      // from array (ordered)
      var a : Array = [
        3, "3 (2)", // ignored by map
        5, "5",
        "6", "six"
      ];
      Maps.addFromArray(map, a);

      // from map (ordered)
      var m : LinkedMap = new LinkedMap();
      m.add("6", "six (2)"); // ignored by map
      m.add(7, "7");
      m.add("8", "eight");
      Maps.addFromMap(map, m);

      // from args (ordered)
      Maps.addFromArgs(map,
        "8", "eight (2)", // ignored by map
        9, "9",
        "10", "ten"
      );

      // test
      var i : IMapIterator = map.iterator() as IMapIterator;
      while (i.next()) trace (i.key, "=>", i.current);
     
      //  1 => 1      // from object
      //  2 => two
      //  4 => four   // from dictionary
      //  3 => 3
      //  5 => 5      // from array
      //  6 => six
      //  7 => 7      // from linked map
      //  8 => eight
      //  9 => 9      // from args
      //  10 => ten
    }

  }
}

Dump a Collection

The example show the basic setup of a complex data structure and the application of the dumpAsString() method.

Category: Tools and Utils
DumpAsStringExample.as: Source raw, Source highlighted
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package {
  import org.as3commons.collections.utils.CollectionUtils;
  import flash.display.Sprite;

  public class DumpAsStringExample extends Sprite {

    public function DumpAsStringExample() {
      var root : Node = new Node(0);
      var child1 : Node = new Node(1);
      child1.children = [new Node(2), new Node(3)];
      var child2 : Node = new Node(4);
      child2.children = [new Node(5), new Node(6)];
      var child3 : Node = new Node(7);
      var child4 : Node = new Node(8);
      child4.children = [new Node(9), new Node(10)];
      child3.children = [child4, new Node(11)];
      root.children = [child1, child2, child3];
     
      trace (CollectionUtils.dumpAsString(root));

      // Node 0
      // .......Node 1
      // ..............Node 2
      // ..............Node 3
      // .......Node 4
      // ..............Node 5
      // ..............Node 6
      // .......Node 7
      // ..............Node 8
      // .....................Node 9
      // .....................Node 10
      // ..............Node 11
    }
  }
}

import org.as3commons.collections.framework.IIterable;
import org.as3commons.collections.framework.IIterator;
import org.as3commons.collections.iterators.ArrayIterator;

internal class Node implements IIterable {
  public var number : uint;
  public var children : Array;
  public function Node(theNumber : uint) {
    number = theNumber;
    children = new Array();
  }
  public function iterator(cursor : * = undefined) : IIterator {
    return new ArrayIterator(children);
  }
  public function toString() : String {
    return "Node " + number.toString();
  }
}

All Examples

Collections

ArrayList – Usage

The example shows the usage of the methods of the ArrayList collection.

SortedList – Usage

This example shows the specific behaviour of a SortedList. The general work with collections and iterators is more detailed illustrated in the related ArrayList and ArrayListIterator examples.

Set – Usage

This example shows the specific behaviour of a Set. The general work with collections and iterators is more detailed illustrated in the related ArrayList and ArrayListIterator examples.

Category: Set, Collection

LinkedSet – Usage

This example shows the specific behaviour of a LinkedSet. The general work with a set is more detailed illustrated in the related Set example. The general work with collections and iterators is more detailed illustrated in the related ArrayList and ArrayListIterator examples.

SortedSet – Usage

This example shows the specific behaviour of a SortedSet. The general work with a set is more detailed illustrated in the related Set example. The general work with collections and iterators is more detailed illustrated in the related ArrayList and ArrayListIterator examples.

Map – Usage

This example shows the specific behaviour of a Map. The general work with collections and iterators is more detailed illustrated in the related ArrayList and ArrayListIterator examples.

Category: Map, Collection

LinkedMap – Usage

This example shows the specific behaviour of a LinkedMap. The general work with a map is more detailed illustrated in the related Map example. The general work with collections and iterators is more detailed illustrated in the related ArrayList and ArrayListIterator examples.

SortedMap – Usage

This example shows the specific behaviour of a SortedMap. The general work with a map is more detailed illustrated in the related Map example. The general work with collections and iterators is more detailed illustrated in the related ArrayList and ArrayListIterator examples.

LinkedList – Usage

This example shows the specific behaviour of a LinkedList. The general work with collections and iterators is more detailed illustrated in the related ArrayList and ArrayListIterator examples.

Category: Collection

Treap – Usage

This example shows the specific behaviour of a Treap. The general work with collections and iterators is more detailed illustrated in the related ArrayList and ArrayListIterator examples.

Iterators

CollectionIterator – Traversing and Modifying a Collection

Each collection is equipped with an iterator of type ICollectionIterator that offers rich navigation (start, end, previous) and modification (remove) possibilities. The example shows the usage of the methods of a CollectionIterator.

Category: Iterator

Iterator Polymorphy – Type Casting

The iterator returned by the iterator() method of a collection is always an instance of ICollectionIterator which extends the IIterator interface. Depending on the actual collections, the returned iterator may be even more specific. This example shows how an iterator may be downcasted to offer more specific functionality.

Category: Iterator

ArrayListIterator – Usage

The example shows the usage of the methods of an ArrayListIterator which extends the ICollectionIterator interface with index based navigation and modification operations.

Category: Iterator

Bindable Collections

ArrayListFx – Bindable ArrayList

This example shows the way events dispatched by the ArrayListFx can be listened and evaluated. The ArrayListFx behaviour is identical to that of the ArrayList which is illustrated in the related example.

Related: ArrayList

SortedListFx – Bindable SortedList

This example shows the way events dispatched by the SortedListFx can be listened and evaluated. The SortedListFx behaviour is identical to that of the SortedList which is illustrated in the related example.

Related: SortedList

SetFx – Bindable Set

This example shows the way events dispatched by the SetFx can be listened and evaluated. The SetFx behaviour is identical to that of the Set which is illustrated in the related example.

Related: Set

LinkedSetFx – Bindable LinkedSet

This example shows the way events dispatched by the LinkedSetFx can be listened and evaluated. The LinkedSetFx behaviour is identical to that of the LinkedSet which is illustrated in the related example.

Related: LinkedSet

SortedSetFx – Bindable SortedSet

This example shows the way events dispatched by the SortedSetFx can be listened and evaluated. The SortedSetFx behaviour is identical to that of the SortedSet which is illustrated in the related example.

Related: SortedSet

MapFx – Bindable Map

This example shows the way events dispatched by the MapFx can be listened and evaluated. The MapFx behaviour is identical to that of the Map which is illustrated in the related example.

Related: Map

LinkedMapFx – Bindable LinkedMap

This example shows the way events dispatched by the LinkedMapFx can be listened and evaluated. The LinkedMapFx behaviour is identical to that of the LinkedMap which is illustrated in the related example.

Related: LinkedMap

SortedMapFx – Bindable SortedMap

This example shows the way events dispatched by the SortedMapFx can be listened and evaluated. The SortedMapFx behaviour is identical to that of the SortedMap which is illustrated in the related example.

Related: SortedMap

Collection Events

CollectionEvent Polymorphy – Type Casting

The event dispatched by a bindable collection is basically of type CollectionEvent and should be downcasted in order to provide the collection specific functionality. This example gives two examples how such events may be downcasted.

CollectionEvent Iterator – Locating changes

The iterator returned by the iterator() method of each CollectionEvent points always to the position where the change has been occurred and thus enables a valid tracking of the state of a collection. The example shows this iterator in action.

CollectionEvent Iterator Polymorphy – Type Casting

The iterator returned by the iterator() method of a CollectionEvent is basically of type ICollectionIterator. Depending on the source collection, this iterator may be downcasted to a more specific type which provides more functionality. The example shows how such an iterator may be downcasted.

Special Iterators

FilterIterator – Filtering a Collection

The FilterIterator class is useful to filter the contents of any iterable data container. This example shows the setup of a simple filter function.

CollectionFilterIterator – Filtering a Collection deluxe

This is a filter iterator with extended navigation (start, end, previous) and modification (remove) possibilities. This example shows the setup of a simple filter function and the usage of the CollectionFilterIterator.

RecursiveIterator – Traversing a complex structure

The RecursiveIterator traverses any complex structure when the items (or nodes) in this structure are again iterable data container. The example shows the basic setup a complex data structure and the usage of the RecursiveIterator class.

RecursiveFilterIterator – Traversing and filtering a complex structure

This is a recursive iterator that enables filtering of parent or child nodes. The example shows the basic setup a complex data structure and illustrates how children or parent nodes can be filtered.

Sorted Collections

Implementing a Comparator

A comparator must be specified to setup a sorted collection or a sort operation. This example shows a comparator that sorts numbers after their parity and then their value.

Tools and Utils

Create a nested collection

Creating a nested collection is easy using the util classes.

Category: Tools and Utils

Fast populate a collection

You may use variable argument lists to add multiple items at once.

Category: Tools and Utils

Copy a list

Copy items from a list to another. It is possible to customize the copy process using filters.

Clone a list

Clone an entire list. It is possible to customize the clone process using filters.

Fast populate a list

Use the Lists.addFrom…() methods to easily set up a list collection.

Copy a set

Copy items from a set to another. It is possible to customize the copy process using filters.

Category: Tools and Utils, Set

Clone a set

Clone an entire set. It is possible to customize the clone process using filters.

Category: Tools and Utils, Set

Fast populate a set

Use the Sets.addFrom…() methods to easily set up a set collection.

Category: Tools and Utils, Set

Copy a map

Copy items from a map to another. It is possible to customize the copy process using filters.

Category: Tools and Utils, Map

Clone a map

Clone an entire map. It is possible to customize the clone process using filters.

Category: Tools and Utils, Map

Fast populate a map

Use the Maps.addFrom…() methods to easily set up a map collection.

Category: Tools and Utils, Map

Dump a Collection

The example show the basic setup of a complex data structure and the application of the dumpAsString() method.

Category: Tools and Utils


2 Comments

  1. Janek

    13. August 2012

    Mislead by the bindable word i see i cannot use for example ArrayListFx to fetch spark List dataProvider ? What’s the point of having them versus your regular ArrayList ? eventually one would want to display something in components. Should i use mx.collections.ArrayList instead, and if so, what is the purpose of ArrayListFx and the rest of bindable collections?

    Please explain, thanks in advance

  2. Paolo

    30. September 2013

    I’ve same question of Janek? What does it means “bindable”? it’s about the collection events only?

Leave a Comment

You have a question or have experienced an issue? Please post it in the forum: http://sibirjak.tenderapp.com/ in order to make the discussion available at a more central place.