/** * Simple Map * var m = new Map(); * m.put('key','value'); * var v_otherMap = v_m.toMapString();* * alert(v_otherMap ); */ (function(){ var _common = { Map :function () { Array.prototype.remove = function(val) { var index = this.indexOf(val); if (index > -1) { this.splice(index, 1); } }; this.keys = new Array(); /** 存放键的数组(遍历用到) */ this.data = new Object();/** 存放数据 */ /** * 放入一个键值对 * @param {String} key * @param {Object} value */ this.put = function(key, value) { if(this.data[key] == null){ this.keys.push(key); } this.data[key] = value; }; /** * 获取某键对应的值 * @param {String} key * @return {Object} value */ this.get = function(key) { return this.data[key]; }; /** * 删除一个键值对 * @param {String} key */ this.remove = function(k) { this.keys.remove(k); //delete this.keys[k]; this.data[k] = null; }; /** * 遍历Map,执行处理函数 * * @param {Function} 回调函数 function(key,value,index){..} */ this.each = function(fn){ if(typeof fn != 'function'){ return; } var len = this.keys.length; for(var i=0;i
@SuppressWarnings("rawtypes") public static void main(String[] args) throws EvalError { StringBuffer sb = new StringBuffer(); String tt ="201503"; Map map = makeupDynamicMap("java.util.Map map = new java.util.HashMap();map.put(\"result\",\"to\");map.put(\"result1\",\"to111\"); return map;"); System.out.println(map.get("result1")); } @SuppressWarnings("rawtypes") public static Map makeupDynamicMap(String otherParam) throws EvalError { Map variables = new HashMap(); if(StringUtils.isEmpty(otherParam)) return variables; if(StringUtils.isNotEmpty(otherParam)) { Interpreter it = new Interpreter(); Object obj = null; obj = it.eval(otherParam); variables.putAll((Map)obj); } return variables; }