Browse Source

1:删除测试代码。

yujia 8 years ago
parent
commit
2ea10f37c4
2 changed files with 0 additions and 161 deletions
  1. 0 72
      src/main/java/JSON.java
  2. 0 89
      src/main/java/JsonPrice.java

+ 0 - 72
src/main/java/JSON.java

@@ -1,72 +0,0 @@
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public class JSON {
-
-    private static String[] getKeyValue(String str) {
-        String field = str.substring(0, str.indexOf(":"));
-        if (field != null) {
-            if (field.startsWith("\"")) {
-                field = field.substring(1, field.length());
-            }
-            if (field.endsWith("\"")) {
-                field = field.substring(0, field.lastIndexOf("\""));
-            }
-        }
-        String value = str.substring(str.indexOf(":") + 1);
-        if (value != null) {
-            if ("null".equals(value)) {
-                value = null;
-            } else {
-                if (value.startsWith("\"")) {
-                    value = value.substring(1, value.length());
-                }
-                if (value.endsWith("\"")) {
-                    value = value.substring(0, value.lastIndexOf("\""));
-                }
-            }
-        }
-        return new String[] { field, value };
-    }
-
-    public static Map<String, String> parseObject(String jsonStr) {
-        Map<String, String> data = new HashMap<String, String>();
-        if (null != jsonStr) {
-            jsonStr = jsonStr.substring(jsonStr.indexOf("{") + 1, jsonStr.lastIndexOf("}"));
-            String[] strs = jsonStr.split(",\"");
-            for (String str : strs) {
-                if (str.indexOf(":") > 0) {
-                    String[] entry = getKeyValue(str);
-                    data.put(entry[0], entry[1]);
-                }
-            }
-        }
-        return data;
-    }
-
-    public static List<Map<String, String>> parseArray(String jsonStr) {
-        List<Map<String, String>> list = new ArrayList<Map<String, String>>();
-        if (null != jsonStr) {
-            if (jsonStr.startsWith("[")) {
-                jsonStr = jsonStr.substring(1, jsonStr.length());
-            }
-            if (jsonStr.endsWith("]")) {
-                jsonStr = jsonStr.substring(0, jsonStr.lastIndexOf("]"));
-            }
-            if (jsonStr.indexOf("},") > -1) {
-                String[] js = jsonStr.split("},");
-                for (String j : js) {
-                    if (!j.endsWith("}"))
-                        j = j + "}";
-                    list.add(parseObject(j));
-                }
-            } else if (!(jsonStr.indexOf("{") == -1 || jsonStr.indexOf("}") == -1)) {
-                list.add(parseObject(jsonStr));
-            }
-        }
-        return list;
-    }
-
-}

+ 0 - 89
src/main/java/JsonPrice.java

@@ -1,89 +0,0 @@
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-public class JsonPrice {
-
-    public static Double getPriceByQty(String priceJson, Double qty, String priceProperty) {
-        List<Map<String, String>> array = JSON.parseArray(priceJson);
-        Double start = 0.0d;
-        Double end = 0.0d;
-        try {
-            for (Map<String, String> map : array) {
-                start = Double.parseDouble(map.get("start"));
-                end = Double.parseDouble(map.get("end"));
-                if (Double.compare(start, qty) < 1 && Double.compare(end, qty) > -1) {
-                    String price = map.get(priceProperty);
-                    return (null == price || price.length() == 0) ? null : Double.parseDouble(price);
-                }
-            }
-            return null;
-        }catch (Exception e) {
-            return null;
-        }
-    }
-
-    public static Double getInfoByProperty(String priceJson, Integer index, String property) {
-        List<Map<String, String>> array = JSON.parseArray(priceJson);
-        if(array.size() <= index) {
-            return null;
-        }else {
-            Map<String, String> map = array.get(index);
-            Set<String> properties = map.keySet();
-            for (String proper : properties) {
-                if(proper.equals(property)) {
-                    try {
-                        return Double.parseDouble(map.get(proper));
-                    }catch (Exception e) {
-                        return null;
-                    }
-                }
-            }
-        }
-        return null;
-    }
-
-
-    public static Double getMinPrice(String priceJson, String priceProperty) {
-        List<Map<String, String>> array = JSON.parseArray(priceJson);
-        Double minPrice = Double.MAX_VALUE;
-        for (Map<String, String> map : array) {
-            try {
-                String price = map.get(priceProperty);
-                Double mprice = (null == price || price.length() == 0) ? null : Double.parseDouble(price);
-                if (Double.compare(minPrice, mprice) > 0) {
-                    minPrice = mprice;
-                }
-                if(Double.compare(Double.MAX_VALUE, minPrice) == 0) {
-                    return null;
-                }else {
-                    return minPrice;
-                }
-            }catch (Exception e) {
-                return null;
-            }
-        }
-        return null;
-    }
-
-    public static Double getMaxPrice(String priceJson, String priceProperty) {
-        List<Map<String, String>> array = JSON.parseArray(priceJson);
-        Double maxPrice = Double.MIN_VALUE;
-        try {
-            for (Map<String, String> map : array) {
-                String price = map.get(priceProperty);
-                Double mprice = (null == price || price.length() == 0) ? null : Double.parseDouble(price);
-                if (Double.compare(maxPrice, mprice) < 1) {
-                    maxPrice = mprice;
-                }
-            }
-            if (Double.compare(Double.MIN_VALUE, maxPrice) == 0) {
-                return null;
-            } else {
-                return maxPrice;
-            }
-        }catch (Exception e) {
-            return null;
-        }
-    }
-}