diff --git a/APIJSONORM/src/main/java/apijson/StringUtil.java b/APIJSONORM/src/main/java/apijson/StringUtil.java index efe5bee20..fc9552de4 100755 --- a/APIJSONORM/src/main/java/apijson/StringUtil.java +++ b/APIJSONORM/src/main/java/apijson/StringUtil.java @@ -111,11 +111,13 @@ public static String getString(Object[] array, boolean ignoreEmptyItem) { public static String getString(Object[] array, String split) { return getString(array, split, false); } + //CS304 Issue link: https://github.com/Tencent/APIJSON/issues/182 /**获取string,为null则返回"" - * @param array - * @param split - * @param ignoreEmptyItem - * @return + * @param array -the str array given + * @param split -the token used to split + * @param ignoreEmptyItem -whether to ignore empty item or not + * @return {@link #getString(Object[], String, boolean)} + *

Here we replace the simple "+" way of concatenating with Stringbuilder 's append

*/ public static String getString(Object[] array, String split, boolean ignoreEmptyItem) { StringBuilder s = new StringBuilder(""); @@ -537,10 +539,13 @@ public static String getNumber(CharSequence cs) { public static String getNumber(String s) { return getNumber(s, false); } + + //CS304 Issue link: https://github.com/Tencent/APIJSON/issues/182 /**去掉string内所有非数字类型字符 - * @param s + * @param s -string passed in * @param onlyStart 中间有非数字时只获取前面的数字 - * @return + * @return limit String + *

Here we replace the simple "+" way of concatenating with Stringbuilder 's append

*/ public static String getNumber(String s, boolean onlyStart) { if (isNotEmpty(s, true) == false) { @@ -638,10 +643,12 @@ public static String getCorrectEmail(String email) { public static String getPrice(String price) { return getPrice(price, PRICE_FORMAT_DEFAULT); } + //CS304 Issue link: https://github.com/Tencent/APIJSON/issues/182 /**获取价格,保留两位小数 - * @param price + * @param price -price passed in * @param formatType 添加单位(元) - * @return + * @return limit String + *

Here we replace the simple "+" way of concatenating with Stringbuilder 's append

*/ public static String getPrice(String price, int formatType) { if (isNotEmpty(price, true) == false) { diff --git a/APIJSONORM/src/main/java/apijson/orm/AbstractParser.java b/APIJSONORM/src/main/java/apijson/orm/AbstractParser.java index 697c145b7..e109b5a04 100755 --- a/APIJSONORM/src/main/java/apijson/orm/AbstractParser.java +++ b/APIJSONORM/src/main/java/apijson/orm/AbstractParser.java @@ -1428,9 +1428,11 @@ public synchronized void putQueryResult(String path, Object result) { queryResultMap.put(path, result); // } } + //CS304 Issue link: https://github.com/Tencent/APIJSON/issues/48 /**根据路径获取值 - * @param valuePath + * @param valuePath -the path need to get value * @return parent == null ? valuePath : parent.get(keys[keys.length - 1]) + *

use entrySet+getValue() to replace keySet+get() to enhance efficiency

*/ @Override public Object getValueByPath(String valuePath) { @@ -1445,13 +1447,13 @@ public Object getValueByPath(String valuePath) { } //取出key被valuePath包含的result,再从里面获取key对应的value - Set set = queryResultMap.keySet(); JSONObject parent = null; String[] keys = null; - for (String path : set) { + for (Map.Entry entry : queryResultMap.entrySet()){ + String path = entry.getKey(); if (valuePath.startsWith(path + "/")) { try { - parent = (JSONObject) queryResultMap.get(path); + parent = (JSONObject) entry.getValue(); } catch (Exception e) { Log.e(TAG, "getValueByPath try { parent = (JSONObject) queryResultMap.get(path); } catch { " + "\n parent not instanceof JSONObject!"); diff --git a/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java b/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java index 4f036900e..efedbe3e8 100755 --- a/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java +++ b/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java @@ -1527,10 +1527,12 @@ public AbstractSQLConfig setCombine(Map> combine) { public Object getWhere(String key) { return getWhere(key, false); } + //CS304 Issue link: https://github.com/Tencent/APIJSON/issues/48 /** - * @param key - * @param exactMatch + * @param key - the key passed in + * @param exactMatch - whether it is exact match * @return + *

use entrySet+getValue() to replace keySet+get() to enhance efficiency

*/ @JSONField(serialize = false) @Override @@ -1539,16 +1541,17 @@ public Object getWhere(String key, boolean exactMatch) { return where == null ? null : where.get(key); } - Set set = key == null || where == null ? null : where.keySet(); - if (set != null) { - synchronized (where) { - if (where != null) { - int index; - for (String k : set) { - index = k.indexOf(key); - if (index >= 0 && StringUtil.isName(k.substring(index)) == false) { - return where.get(k); - } + if (key == null || where == null){ + return null; + } + synchronized (where) { + if (where != null) { + int index; + for (Map.Entry entry : where.entrySet()) { + String k = entry.getKey(); + index = k.indexOf(key); + if (index >= 0 && StringUtil.isName(k.substring(index)) == false) { + return entry.getValue(); } } } @@ -2480,11 +2483,13 @@ public static JSONArray newJSONArray(Object obj) { public String getSetString() throws Exception { return getSetString(getMethod(), getContent(), ! isTest()); } + //CS304 Issue link: https://github.com/Tencent/APIJSON/issues/48 /**获取SET - * @param method - * @param content + * @param method -the method used + * @param content -the content map * @return - * @throws Exception + * @throws Exception + *

use entrySet+getValue() to replace keySet+get() to enhance efficiency

*/ @JSONField(serialize = false) public String getSetString(RequestMethod method, Map content, boolean verifyName) throws Exception { @@ -2497,7 +2502,8 @@ public String getSetString(RequestMethod method, Map content, bo Object value; String idKey = getIdKey(); - for (String key : set) { + for (Map.Entry entry : content.entrySet()) { + String key = entry.getKey(); //避免筛选到全部 value = key == null ? null : content.get(key); if (key == null || idKey.equals(key)) { continue; @@ -2510,7 +2516,7 @@ public String getSetString(RequestMethod method, Map content, bo } else { keyType = 0; //注意重置类型,不然不该加减的字段会跟着加减 } - value = content.get(key); + value = entry.getValue(); key = getRealKey(method, key, false, true, verifyName); setString += (isFirst ? "" : ", ") + (getKey(key) + " = " + (keyType == 1 ? getAddString(key, value) : (keyType == 2