| | |
| | | standardProductList.setMethodS(code); |
| | | return standardProductList; |
| | | }).collect(Collectors.toList()); |
| | | //按照电路试验--辐射试验--温湿度试验--环境试验进行排序 |
| | | // 定义自定义排序器 |
| | | Comparator<StandardProductList> testTypeComparator = (o1, o2) -> { |
| | | String[] order = {"电路试验", "辐射试验", "温湿度试验", "环境试验"}; |
| | | int index1 = -1; |
| | | int index2 = -1; |
| | | // 找出两个对象 在自定义顺序数组中的位置 |
| | | for (int i = 0; i < order.length; i++) { |
| | | if (o1.getInspectionItem().equals(order[i])) { |
| | | index1 = i; |
| | | } |
| | | if (o2.getInspectionItem().equals(order[i])) { |
| | | index2 = i; |
| | | } |
| | | if (index1 != -1 && index2 != -1) { |
| | | break; // 两个位置都找到了,可以退出循环 |
| | | } |
| | | } |
| | | // 比较位置 |
| | | return Integer.compare(index1, index2); |
| | | }; |
| | | // 对列表进行排序 |
| | | Collections.sort(list, testTypeComparator); |
| | | return list; |
| | | } |
| | | |