topical media & game development

talk show tell print

professional-flex-code-17-SortedMap.ax

professional-flex-code-17-SortedMap.ax [swf] flex


  package
  {
  import flash.utils.Dictionary;
    
  public class @ax-professional-flex-code-17-SortedMap
  {
    private var map:Dictionary;
    private var keys:Array;
    
    public function @ax-professional-flex-code-17-SortedMap()
    {
      map = new Dictionary();
      keys = new Array();
    }
    
    // add values by key
    public function addItem( key:Object, value:Object ):void
    {
      map[ key ] = value;
      keys.push( key );
    }
  
    // get values by key
    public function getItem( key:Object ):Object
    {
      return map[ key ];
    } 
    
    // return keys array, used to iterator over values
    public function keySet():Array
    {
      // sort keys, use toString() on key
      keys.sort();
      return keys;
    }
  
    // return keys array, used to iterator over values
    public function values():Array
    {
      var values:Array = new Array();
      for each( var val:Object in map )
        values.push( val );
      return values;
    } 
  }
  }


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.