• js创建javaMap


    /** 
    * 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<len;i++){ var k = this.keys[i]; fn(k,this.data[k],i); } }; /** * 获取键值数组(类似Java的entrySet()) * @return 键值对象{key,value}的数组 */ this.entrys = function() { var len = this.keys.length; var entrys = new Array(len); for (var i = 0; i < len; i++) { entrys[i] = { key : this.keys[i], value : this.data[i] }; } return entrys; }; /** * 判断Map是否为空 */ this.isEmpty = function() { return this.keys.length == 0; }; /** * 获取键值对数量 */ this.size = function(){ return this.keys.length; }; /** * 重写toString */ this.toString = function(){ var s = "{"; for(var i=0;i<this.keys.length;i++,s+=','){ var k = this.keys[i]; s += k+"="+this.data[k]; } s+="}"; return s; }; /** * 重写toString */ this.toMapString = function(){ var s = "java.util.Map map = new java.util.HashMap();"; for(var i=0;i<this.keys.length;i++){ var k = this.keys[i]; if(i != 0) s +=";"; s += "map.put(""+k+"",""+this.data[k]+"")"; } s+="; return map;"; return s; }; } }; if(typeof JBPM == "undefined") window.JBPM={}; JBPM.common = _common; })();





        @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;
        }
    
    
    


     
  • 相关阅读:
    iOS,Android,WP, .NET通用AES加密算法
    iOS开发笔记-图标和图片大小官方最新标准
    因为对 Docker 不熟悉建了 N 多个 Nginx
    Docker 学习笔记 2019-05-27
    Linux Mint 19.1 安装 Docker 过程笔记
    W600 一块新的 KiCad PCB
    KiCad Mark 点名称
    一次乙型流感记录(2019-05-24)
    为什么不喜欢在 QQ 群里回答问题?
    Git 的两种忽略文件方式 gitignore 和 exclude
  • 原文地址:https://www.cnblogs.com/yy123/p/4795171.html
Copyright © 2020-2023  润新知