ʹ�� Map��value�������� @param map @return
(Map<String, String> map, String sortMethod)
| 31 | * @return |
| 32 | */ |
| 33 | public static Map<String, String> sortMapByValue(Map<String, String> map, String sortMethod) { |
| 34 | if (map == null || map.isEmpty()) { |
| 35 | return null; |
| 36 | } |
| 37 | Map<String, String> sortedMap = new LinkedHashMap<String, String>(); |
| 38 | List<Map.Entry<String, String>> entryList = new ArrayList<Map.Entry<String, String>>(map.entrySet()); |
| 39 | if (sortMethod.equals("ASCENDING")){ |
| 40 | Collections.sort(entryList, new MapValueComparator()); |
| 41 | }else if (sortMethod.equals("DESCENDING")) { |
| 42 | Collections.sort(entryList, new MapValueComparatorDesc()); |
| 43 | } |
| 44 | Iterator<Map.Entry<String, String>> iter = entryList.iterator(); |
| 45 | Map.Entry<String, String> tmpEntry = null; |
| 46 | while (iter.hasNext()) { |
| 47 | tmpEntry = iter.next(); |
| 48 | sortedMap.put(tmpEntry.getKey(), tmpEntry.getValue()); |
| 49 | } |
| 50 | return sortedMap; |
| 51 | } |
| 52 | |
| 53 | |
| 54 | public static String combineMapEntry(Map<String,String> map, Boolean onlyValue, String connector){ |
no test coverage detected