标签:
主类:
package { //import com.ericfeminella.collections.Map; import com.xing.Maps; import com.xing.ValuesTypeCmd; import flash.display.Sprite; import flash.text.TextField; public class AS1te extends Sprite { private var map:Maps; public function AS1te() { var textField:TextField = new TextField(); textField.text = "Hello, World"; addChild(textField); this.init(); } private function init():void { var obj1:Object; var obj2:Object; var obj3:Object; map = new Maps(); obj1 = {"type":"12","num":123}; obj2 = {"type":"13","num":123}; obj3 = {"type":"14","num":123}; map.put(ValuesTypeCmd.VALUES_A,1); map.put(ValuesTypeCmd.VALUES_B,2); map.put(ValuesTypeCmd.VALUES_C,3); map.put(ValuesTypeCmd.VALUES_D,obj1); map.put(ValuesTypeCmd.VALUES_E,obj2); map.put(ValuesTypeCmd.VALUES_F,obj3); trace(map.getValue(ValuesTypeCmd.VALUES_A)); trace(map.getValue(ValuesTypeCmd.VALUES_B)); trace(map.getValue(ValuesTypeCmd.VALUES_C)); trace(map.getValue(ValuesTypeCmd.VALUES_D)); trace(map.getValue(ValuesTypeCmd.VALUES_E)); trace(map.getValue(ValuesTypeCmd.VALUES_F)); } } }
hashMap类:
//Map package com.xing { import flash.utils.*; public class Maps extends Object { private var length:int; public var content:Dictionary; public function Maps() { super(); this.length = 0; this.content = new Dictionary(); } public function size():int { return this.length; } public function isEmpty():Boolean { return this.length == 0; } public function keys():Array { var loc1:*=undefined; var loc3:*=0; var loc2:*=new Array(this.length); var loc4:*=0; var loc5:*=this.content; for (loc1 in loc5) { loc2[loc3] = loc1; ++loc3; } return loc2; } public function eachKey(arg1:Function):void { var loc1:*=undefined; var loc2:*=0; var loc3:*=this.content; for (loc1 in loc3) { arg1(loc1); } return; } public function eachValue(arg1:Function):void { var loc1:*=undefined; var loc2:*=0; var loc3:*=this.content; for each (loc1 in loc3) { arg1(loc1); } return; } public function values():Array { var loc1:*=undefined; var loc3:*=0; var loc2:*=new Array(this.length); var loc4:*=0; var loc5:*=this.content; for each (loc1 in loc5) { loc2[loc3] = loc1; ++loc3; } return loc2; } public function containsValue(arg1:*):Boolean { var loc1:*=undefined; var loc2:*=0; var loc3:*=this.content; for each (loc1 in loc3) { if (loc1 !== arg1) { continue; } return true; } return false; } public function containsKey(arg1:*):Boolean { if (this.content[arg1] != undefined) { return true; } return false; } public function get(arg1:*):* { var loc1:*=this.content[arg1]; if (loc1 !== undefined) { return loc1; } return null; } public function getValue(arg1:*):* { return this.get(arg1); } public function put(arg1:*, arg2:*):* { var loc1:*=false; var loc2:*=undefined; if (arg1 == null) { throw new ArgumentError("cannot put a value with undefined or null key!"); } if (arg2 == null) { return this.remove(arg1); } loc1 = this.containsKey(arg1); if (!loc1) { var loc3:*; var loc4:*=((loc3 = this).length + 1); loc3.length = loc4; } loc2 = this.get(arg1); this.content[arg1] = arg2; return loc2; } public function remove(arg1:*):* { var loc1:*=this.containsKey(arg1); if (!loc1) { return null; } var loc2:*=this.content[arg1]; delete this.content[arg1]; var loc3:*; var loc4:*=((loc3 = this).length - 1); loc3.length = loc4; return loc2; } public function clear():void { this.length = 0; this.content = new Dictionary(); return; } public function clone():Maps { var loc1:*=undefined; var loc2:*=new Maps(); var loc3:*=0; var loc4:*=this.content; for (loc1 in loc4) { loc2.put(loc1, this.content[loc1]); } return loc2; } public function toString():String { var loc4:*=0; var loc1:*=this.keys(); var loc2:*=this.values(); var loc3:*="Map Content:\n"; while (loc4 < loc1.length) { loc3 = loc3 + (loc1[loc4] + " -> " + loc2[loc4] + "\n"); ++loc4; } return loc3; } } }
map的主键类:
/** * Created with IntelliJ IDEA. * User: Administrator * Date: 15-4-2 * Time: 下午4:09 * To change this template use File | Settings | File Templates. */ package com.xing { public class ValuesTypeCmd { public static const VALUES_A:String = "VALUES_A"; public static const VALUES_B:String = "VALUES_B"; public static const VALUES_C:String = "VALUES_C"; public static const VALUES_D:String = "VALUES_D"; public static const VALUES_E:String = "VALUES_E"; public static const VALUES_F:String = "VALUES_F"; public static const VALUES_G:String = "VALUES_G"; public static const VALUES_H:String = "VALUES_H"; public static const VALUES_I:String = "VALUES_I"; public static const VALUES_J:String = "VALUES_J"; public function ValuesTypeCmd() { } } }
标签:
原文地址:http://www.cnblogs.com/duhuo/p/4387345.html