Revision: 20800 http://sourceforge.net/p/jmol/code/20800 Author: hansonr Date: 2015-09-29 21:53:26 +0000 (Tue, 29 Sep 2015) Log Message: ----------- JmolVersion="14.3.16_2015.09.29"
note: I am using "map" for "associative array" now new feature: mapOfMaps.array(k) -- generates an array of maps from a map of maps by storing all map keys under key k -- reversed by another .array(k) -- causes a script exception if mapOfMaps is not a map of maps new feature: arrayOfMaps.array(k) -- generates a map of maps from an array of maps by retrieving each map's key k as the key for that map -- reversed by another .array(k) -- causes a script exception if arrayOfMaps is not an array of maps or key k is not present in all maps Modified Paths: -------------- trunk/Jmol/src/org/jmol/script/SV.java trunk/Jmol/src/org/jmol/script/ScriptExpr.java trunk/Jmol/src/org/jmol/scriptext/MathExt.java trunk/Jmol/src/org/jmol/viewer/Jmol.properties Modified: trunk/Jmol/src/org/jmol/script/SV.java =================================================================== --- trunk/Jmol/src/org/jmol/script/SV.java 2015-09-28 20:26:51 UTC (rev 20799) +++ trunk/Jmol/src/org/jmol/script/SV.java 2015-09-29 21:53:26 UTC (rev 20800) @@ -1707,21 +1707,26 @@ * * @param v hash or array * @param isHash + * @param isDeep TODO * @return deeply copied variable */ @SuppressWarnings("unchecked") - public static Object deepCopy(Object v, boolean isHash) { + public static Object deepCopy(Object v, boolean isHash, boolean isDeep) { if (isHash) { Map<String, SV> vold = (Map<String, SV>) v; Map<String, SV> vnew = new Hashtable<String, SV>(); - for (Entry<String, SV> e : vold.entrySet()) - vnew.put(e.getKey(), deepCopySV(e.getValue())); - return vnew; + for (Entry<String, SV> e : vold.entrySet()) { + SV v1 = e.getValue(); + vnew.put(e.getKey(), isDeep ? deepCopySV(v1) : v1); + } + return vnew; } Lst<SV> vold2 = (Lst<SV>) v; Lst<SV> vnew2 = new Lst<SV>(); - for (int i = 0, n = vold2.size(); i < n; i++) - vnew2.addLast(deepCopySV(vold2.get(i))); + for (int i = 0, n = vold2.size(); i < n; i++) { + SV vm = vold2.get(i); + vnew2.addLast(isDeep ? deepCopySV(vm) : vm); + } return vnew2; } @@ -1735,7 +1740,7 @@ } else { vm.myName = "recursing"; SV vm0 = vm; - vm = newV(vm.tok, deepCopy(vm.value, vm.tok == hash)); + vm = newV(vm.tok, deepCopy(vm.value, vm.tok == hash, true)); vm0.myName = null; } break; Modified: trunk/Jmol/src/org/jmol/script/ScriptExpr.java =================================================================== --- trunk/Jmol/src/org/jmol/script/ScriptExpr.java 2015-09-28 20:26:51 UTC (rev 20799) +++ trunk/Jmol/src/org/jmol/script/ScriptExpr.java 2015-09-29 21:53:26 UTC (rev 20800) @@ -2540,11 +2540,11 @@ } else if (v instanceof Map<?, ?> || v instanceof ScriptContext && (v = ((ScriptContext) v).getFullMap()) != null) { // x = @y -- do a deep copy -- Jmol 14.3.16 - fixed[j] = SV.newV(T.hash, (isExpression ? v : SV.deepCopy(v, true))); + fixed[j] = SV.newV(T.hash, (isExpression ? v : SV.deepCopy(v, true, true))); } else if (v instanceof Lst<?>) { if (!isExpression) { // do a deep copy -- Jmol 14.3.16 - fixed[j] = SV.newV(T.varray, SV.deepCopy(v, false)); + fixed[j] = SV.newV(T.varray, SV.deepCopy(v, false, true)); break; } // if v is a list, we check to to see if it is an array of Modified: trunk/Jmol/src/org/jmol/scriptext/MathExt.java =================================================================== --- trunk/Jmol/src/org/jmol/scriptext/MathExt.java 2015-09-28 20:26:51 UTC (rev 20799) +++ trunk/Jmol/src/org/jmol/scriptext/MathExt.java 2015-09-29 21:53:26 UTC (rev 20800) @@ -117,8 +117,9 @@ case T.leftsquare: if (args.length == 0) mp.wasX = false; + //$FALL-THROUGH$ case T.array: - return evaluateArray(mp, args); + return evaluateArray(mp, args, tok == T.array && op.tok == T.propselector); case T.axisangle: case T.quaternion: return evaluateQuaternion(mp, args, tok); @@ -214,7 +215,49 @@ return false; } - private boolean evaluateArray(ScriptMathProcessor mp, SV[] args) { + @SuppressWarnings("unchecked") + private boolean evaluateArray(ScriptMathProcessor mp, SV[] args, boolean isSelector) throws ScriptException { + if (isSelector) { + SV x1 = mp.getX(); + switch (args.length == 1 ? x1.tok : T.nada) { + case T.hash: + // map of maps to lst of maps + Lst<SV> lst = new Lst<SV>(); + String id = args[0].asString(); + Map<String, SV> map = x1.getMap(); + String[] keys = x1.getKeys(false); + // values must all be maps + for (int i = 0, n = keys.length; i < n; i++) + if (map.get(keys[i]).getMap() == null) + return false; + for (int i = 0, n = keys.length; i < n; i++) { + SV m = map.get(keys[i]); + Map<String, SV> m1 = m.getMap(); + Map<String, SV> m2 = (Map<String, SV>) SV.deepCopy(m1, true, false); + m2.put(id, SV.newS(keys[i])); + lst.addLast(SV.newV(T.hash, m2)); + } + return mp.addXList(lst); + case T.varray: + Map<String, SV> map1 = new Hashtable<String, SV>(); + Lst<SV> lst1 = x1.getList(); + String id1 = args[0].asString(); + // values must all be maps + for (int i = 0, n = lst1.size(); i < n; i++) { + Map<String, SV> m0 = lst1.get(i).getMap(); + if (m0 == null || m0.get(id1) == null) + return false; + } + for (int i = 0, n = lst1.size(); i < n; i++){ + SV m = lst1.get(i); + Map<String, SV> m1 = (Map<String, SV>) SV.deepCopy(m.getMap(), true, false); + SV mid = m1.remove(id1); + map1.put(mid.asString(), SV.newV(T.hash, m1)); + } + return mp.addXObj(map1); + } + return false; + } SV[] a = new SV[args.length]; for (int i = a.length; --i >= 0;) a[i] = SV.newT(args[i]); Modified: trunk/Jmol/src/org/jmol/viewer/Jmol.properties =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2015-09-28 20:26:51 UTC (rev 20799) +++ trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2015-09-29 21:53:26 UTC (rev 20800) @@ -66,6 +66,20 @@ bug fix: draw ramachandran broken +JmolVersion="14.3.16_2015.09.29" + +note: I am using "map" for "associative array" now + +new feature: mapOfMaps.array(k) + -- generates an array of maps from a map of maps by storing all map keys under key k + -- reversed by another .array(k) + -- causes a script exception if mapOfMaps is not a map of maps + +new feature: arrayOfMaps.array(k) + -- generates a map of maps from an array of maps by retrieving each map's key k as the key for that map + -- reversed by another .array(k) + -- causes a script exception if arrayOfMaps is not an array of maps or key k is not present in all maps + JmolVersion="14.3.16_2015.09.28" new feature: array.sort("key") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ _______________________________________________ Jmol-commits mailing list Jmol-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jmol-commits