@Test public void testSortByKeyOutOfOrder() { Map<Integer, String> outOfOrder = new HashMap<>(); outOfOrder.put(2, "c"); outOfOrder.put(0, "a"); outOfOrder.put(3, "d"); outOfOrder.put(1, "b"); Map<Integer, String> cMap = DefaultAtlasCombineStrategy.sortByKey(outOfOrder); int count = 0; for (String str : cMap.values()) { if (count == 0) { assertEquals("a", str); } if (count == 1) { assertEquals("b", str); } if (count == 2) { assertEquals("c", str); } if (count == 3) { assertEquals("d", str); } count++; } }
protected static Map<Integer, String> sortByKey(Map<Integer, String> map) { TreeMap<Integer, String> treeMap = new TreeMap<>((key1, key2) -> { if (key1 == null && key2 == null) { return 0; } else if (key1 == null) { return -1; } else if (key2 == null) { return 1; } else { return key1.compareTo(key2); } }); treeMap.putAll(map); return treeMap; }
DefaultAtlasCombineStrategy implements AtlasCombineStrategy { protected static Map<Integer, String> sortByKey(Map<Integer, String> map) { TreeMap<Integer, String> treeMap = new TreeMap<>((key1, key2) -> { if (key1 == null && key2 == null) { return 0; } else if (key1 == null) { return -1; } else if (key2 == null) { return 1; } else { return key1.compareTo(key2); } }); treeMap.putAll(map); return treeMap; } }
DefaultAtlasCombineStrategy implements AtlasCombineStrategy { protected static Map<Integer, String> sortByKey(Map<Integer, String> map) { TreeMap<Integer, String> treeMap = new TreeMap<>((key1, key2) -> { if (key1 == null && key2 == null) { return 0; } else if (key1 == null) { return -1; } else if (key2 == null) { return 1; } else { return key1.compareTo(key2); } }); treeMap.putAll(map); return treeMap; }  }
DefaultAtlasCombineStrategy implements AtlasCombineStrategy { protected static Map<Integer, String> sortByKey(Map<Integer, String> map) { TreeMap<Integer, String> treeMap = new TreeMap<>((key1, key2) -> { if (key1 == null && key2 == null) { return 0; } else if (key1 == null) { return -1; } else if (key2 == null) { return 1; } else { return key1.compareTo(key2); } }); treeMap.putAll(map); return treeMap; }  @Override StringDelimiter getDelimiter(); @Override void setDelimiter(StringDelimiter delimiter); @Override Integer getLimit(); @Override void setLimit(Integer limit); boolean isDisableAutoTrim(); void setDisableAutoTrim(boolean disableAutoTrim); boolean isDisableAddDelimiterOnNull(); void setDisableAddDelimiterOnNull(boolean disableAddDelimiterOnNull); @Override String combineValues(Map<Integer, String> values); @Override String combineValues(Map<Integer, String> values, StringDelimiter delimiter); @Override String combineValues(Map<Integer, String> values, StringDelimiter delimiter, Integer limit); @Override String combineValues(Map<Integer, String> values, String delimiter); }
DefaultAtlasCombineStrategy implements AtlasCombineStrategy { protected static Map<Integer, String> sortByKey(Map<Integer, String> map) { TreeMap<Integer, String> treeMap = new TreeMap<>((key1, key2) -> { if (key1 == null && key2 == null) { return 0; } else if (key1 == null) { return -1; } else if (key2 == null) { return 1; } else { return key1.compareTo(key2); } }); treeMap.putAll(map); return treeMap; }  @Override StringDelimiter getDelimiter(); @Override void setDelimiter(StringDelimiter delimiter); @Override Integer getLimit(); @Override void setLimit(Integer limit); boolean isDisableAutoTrim(); void setDisableAutoTrim(boolean disableAutoTrim); boolean isDisableAddDelimiterOnNull(); void setDisableAddDelimiterOnNull(boolean disableAddDelimiterOnNull); @Override String combineValues(Map<Integer, String> values); @Override String combineValues(Map<Integer, String> values, StringDelimiter delimiter); @Override String combineValues(Map<Integer, String> values, StringDelimiter delimiter, Integer limit); @Override String combineValues(Map<Integer, String> values, String delimiter); static final StringDelimiter DEFAULT_COMBINE_DELIMITER; static final Integer DEFAULT_COMBINE_LIMIT; }