The release 1.3.0 of the collections framework contains several utilities and convenience methods. There are four new util classes and four new builder classes. Checkout the Git commit log for a detailed list of changes. The APIDoc is updated as well.
Get: Downloads
Follow: GitHub
Read: APIDoc
Test: Examples
New features
The main features added are:
- Copy items from one collection to another
- Clone collections
- Populate a collection from native Flash objects
- Fast populate a collection using variable argument lists
Examples
Copy items from one collection to another
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 collections
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); } } } |
Populate a collection from native Flash objects
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 } } } |
Fast populate a collection using variable argument lists
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 } } } |

RSS



