testing.java
2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package com.huaheng.test;
import com.huaheng.pc.inventory.InventoryMaterialSummary.domain.InventoryMaterialSummary;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
public class testing {
private static List<User> list = new ArrayList<User>();
public static void main(String[] args) {
User user0 = new User();
user0.setName("小强");
user0.setAge(11);
user0.setSex("男");
list.add(user0);
User user2 = new User();
user2.setName("小强");
user2.setAge(15);
user2.setSex("男");
list.add(user2);
User user3 = new User();
user3.setName("小强");
user3.setAge(23);
user3.setSex("男");
list.add(user3);
User user4 = new User();
user4.setName("小雨");
user4.setAge(24);
user4.setSex("女");
list.add(user4);
User user5 = new User();
user5.setName("小雨");
user5.setAge(24);
user5.setSex("女");
list.add(user5);
User user6 = new User();
user6.setName("小雨");
user6.setAge(15);
user6.setSex("女");
list.add(user6);
System.out.println("原始数据:" + list);
List<User> u = new ArrayList<>();
//先找货主和物料码相同的物料SKU相加得总数
for(User o:list){
int numQty = 0;
for (User t:list){
if(o.getName().equals(t.getName()) &&
o.getSex().equals(t.getSex())){
numQty = numQty + t.getAge();
o.setAge(numQty);
}
}
}
//多条件去重
list.stream().collect(Collectors.collectingAndThen(
Collectors.toCollection(() -> new TreeSet<>(
Comparator.comparing(user -> user.getSex() + ";" + user.getName()))), ArrayList::new))
.forEach(user -> u.add(user));
System.out.println("多条件去重后数据:" + u);
}
}