1. package com.rfang.config;
    2. import java.util.*;
    3. import com.rfang.entity.UserEntity;
    4. import java.util.stream.Collectors;
    5. public class Test {
    6. public static void main(String[] args) {
    7. List<UserEntity> entities = new ArrayList<>();
    8. UserEntity entity = new UserEntity();
    9. entity.setUsername("0089090009");
    10. entity.setPassword("2345678");
    11. entity.setStatus(0);
    12. entity.setMobile("2345678");
    13. entities.add(entity);
    14. UserEntity entity3 = new UserEntity();
    15. entity3.setUsername("12345609");
    16. entity3.setPassword("23456345678");
    17. entity3.setStatus(0);
    18. entity3.setMobile("2345678");
    19. entities.add(entity3);
    20. List<UserEntity> userEntities = new ArrayList<>();
    21. UserEntity entity2 = new UserEntity();
    22. entity2.setUsername("0089090009");
    23. entity2.setPassword("2345678");
    24. entity2.setStatus(0);
    25. entity2.setMobile("2345678");
    26. userEntities.add(entity2);
    27. UserEntity entity6 = new UserEntity();
    28. entity6.setUsername("222222222");
    29. entity6.setPassword("2345678");
    30. entity6.setStatus(0);
    31. entity6.setMobile("2345678");
    32. userEntities.add(entity6);
    33. UserEntity entitye= new UserEntity();
    34. entitye.setUsername("222222222");
    35. entitye.setPassword("2345678");
    36. entitye.setStatus(0);
    37. entitye.setMobile("2345678");
    38. userEntities.add(entitye);
    39. System.out.println("entity:"+userEntities.size());
    40. System.out.println("-----");
    41. System.out.println("userEntities:"+userEntities.size());
    42. System.out.println("userEntities-set:"+userEntities.stream().distinct().collect(Collectors.toList()).size());
    43. List<UserEntity> cm = cm(entities, userEntities);
    44. System.out.println("end:"+cm.size());
    45. }
    46. public static List<UserEntity> cm(List<UserEntity> entities,List<UserEntity> userEntities){
    47. userEntities = userEntities.stream().distinct().collect(Collectors.toList());
    48. entities = entities.stream().distinct().collect(Collectors.toList());
    49. List<UserEntity> list = new ArrayList<>();
    50. for(UserEntity entity:userEntities){
    51. entities.forEach(
    52. s->{
    53. if(s.getPassword().equals(entity.getPassword())&&s.getUsername().equals(entity.getUsername())){
    54. list.add(entity);
    55. }
    56. }
    57. );
    58. }
    59. List<UserEntity> models = userEntities.stream().filter(s -> !list.contains(s)).collect(Collectors.toList());
    60. ArrayList<UserEntity> info = models.stream().collect(
    61. Collectors.collectingAndThen(
    62. Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(user -> user.getUsername() + ";" + user.getPassword()))), ArrayList::new));
    63. List<UserEntity> classNameList = new ArrayList(new HashSet(info));
    64. return classNameList;
    65. }
    66. }