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.
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 | package { import org.as3commons.collections.Map; import org.as3commons.collections.framework.ICollectionIterator; import org.as3commons.collections.framework.IIterator; import org.as3commons.collections.framework.IMapIterator; import flash.display.Sprite; public class MapExample extends Sprite { public function MapExample() { var map : Map = new Map(); // Add map.add(1, "one"); map.add(2, "two"); map.add(3, "three"); map.add("4a", "four"); map.add("4b", "four"); map.add("4c", "four"); map.add("4c", "fourC"); // no effect (key already contained) trace (map.toArray()); // four,four,four,one,two,three // Replace map.replaceFor(3, "three3"); map.replaceFor("4a", "fourA"); map.replaceFor(1, "one"); // no effect ("one" === "one") map.replaceFor(4, "four"); // no effect (key not contained) trace (map.toArray()); // fourA,four,four,one,two,three3 // Inspection trace (map.size); // 6 trace (map.hasKey(3)); // true trace (map.hasKey(4)); // false trace (map.itemFor(3)); // three3 trace (map.itemFor(4)); // undefined trace (map.keysToArray()); // 4a,4b,4c,1,2,3 // Iterator var iterator : IIterator = map.iterator(); trace (iterator is IIterator); // true trace (iterator is ICollectionIterator); // true trace (iterator is IMapIterator); // true while (iterator.hasNext()) { trace (iterator.next()); // fourA,four,four,one,two,three3 } // Map iterator var mi : IMapIterator = map.iterator() as IMapIterator; trace (mi.previousKey + " [" + mi.key + "=" + mi.current + "] " + mi.nextKey); while (mi.hasNext()) { mi.next(); trace (mi.previousKey + " [" + mi.key + "=" + mi.current + "] " + mi.nextKey); } // undefined [undefined=undefined] 4a // 4a [4a=fourA] 4b // 4b [4b=four] 4c // 4c [4c=four] 1 // 1 [1=one] 2 // 2 [2=two] 3 // 3 [3=three3] undefined // Remove map.removeKey(2); map.removeKey("4a"); map.removeKey(4); // no effect (key not contained) trace (map.toArray()); // four,four,one,three3 map.remove("one"); map.remove("fourC"); // no effect (item not contained) trace (map.toArray()); // four,four,three3 map.removeAll("four"); trace (map.toArray()); // three3 } } } |
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
Fast populate a collection
You may use variable argument lists to add multiple items at once.
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.
Clone a set
Clone an entire set. It is possible to customize the clone process using filters.
Fast populate a set
Use the Sets.addFrom…() methods to easily set up a set collection.
Copy a map
Copy items from a map to another. It is possible to customize the copy process using filters.
Clone a map
Clone an entire map. It is possible to customize the clone process using filters.
Fast populate a map
Use the Maps.addFrom…() methods to easily set up a map collection.
Dump a Collection
The example show the basic setup of a complex data structure and the application of the dumpAsString() method.

RSS




1 Comment
Janek
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