testing.java 2.19 KB
package com.huaheng.test;


import com.huaheng.pc.inventory.InventoryMaterialSummary.domain.InventoryMaterialSummary;

import java.math.BigDecimal;
import java.math.RoundingMode;
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) {

        System.out.println(new BigDecimal((double) 1 / (double)28116).setScale(3, RoundingMode.UP).doubleValue());


        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);


    }





}