|
@@ -894,14 +894,55 @@ public class CoreUtil {
|
|
.collect(Collectors.toList());
|
|
.collect(Collectors.toList());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public static <V> Map<String, List<V>> makeEntityListMap(List<V> list, String field1, String field2) {
|
|
|
|
+ Map<String, List<V>> map = new LinkedHashMap();
|
|
|
|
+ if (ListUtil.isNotEmpty(list)) {
|
|
|
|
+ for (V v : list) {
|
|
|
|
+ String value1 = (String)CoreUtil.getFieldValue(v, field1);
|
|
|
|
+ String value2 = (String)CoreUtil.getFieldValue(v, field2);
|
|
|
|
+ String unionKey = "";
|
|
|
|
+ if (StringUtil.isNotBlank(value1)) {
|
|
|
|
+ unionKey += value1;
|
|
|
|
+ }
|
|
|
|
+ unionKey += "*****";
|
|
|
|
+ if (StringUtil.isNotBlank(value2)) {
|
|
|
|
+ unionKey += value2;
|
|
|
|
+ }
|
|
|
|
+ List<V> groupList = (List<V>)map.get(unionKey);
|
|
|
|
+ if (groupList == null) {
|
|
|
|
+ groupList = new ArrayList();
|
|
|
|
+ }
|
|
|
|
+ groupList.add(v);
|
|
|
|
+ map.put(unionKey, groupList);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return map;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
public static void main(String[] args) {
|
|
public static void main(String[] args) {
|
|
- // List<Item> list = new ArrayList<>();
|
|
|
|
- // Item item = new Item();
|
|
|
|
- // item.setUniqueName(null);
|
|
|
|
- // item.setName("aaa");
|
|
|
|
- // list.add(item);
|
|
|
|
- // // list = null;
|
|
|
|
- // List<String> res = getNoUniqueList(list);
|
|
|
|
- // System.out.println(res);
|
|
|
|
|
|
+ List<Item> list = new ArrayList<>();
|
|
|
|
+ Item item = new Item();
|
|
|
|
+ item.setUniqueName("test1");
|
|
|
|
+ item.setName("test");
|
|
|
|
+ list.add(item);
|
|
|
|
+
|
|
|
|
+ Item item2 = new Item();
|
|
|
|
+ item2.setUniqueName("test2");
|
|
|
|
+ item2.setName("test");
|
|
|
|
+ list.add(item2);
|
|
|
|
+
|
|
|
|
+ Item item3 = new Item();
|
|
|
|
+ item3.setUniqueName("test1");
|
|
|
|
+ item3.setName("test");
|
|
|
|
+ list.add(item3);
|
|
|
|
+
|
|
|
|
+ Item item4 = new Item();
|
|
|
|
+ item4.setUniqueName("test2");
|
|
|
|
+ item4.setName("test");
|
|
|
|
+ list.add(item4);
|
|
|
|
+ Map<String, List<Item>> map = makeEntityListMap(list, "name", "uniqueName");
|
|
|
|
+
|
|
|
|
+ System.out.println(map);
|
|
}
|
|
}
|
|
}
|
|
}
|