package com.rfang.config;
import java.util.*;
import com.rfang.entity.UserEntity;
import java.util.stream.Collectors;
public class Test {
public static void main(String[] args) {
List<UserEntity> entities = new ArrayList<>();
UserEntity entity = new UserEntity();
entity.setUsername("0089090009");
entity.setPassword("2345678");
entity.setStatus(0);
entity.setMobile("2345678");
entities.add(entity);
UserEntity entity3 = new UserEntity();
entity3.setUsername("12345609");
entity3.setPassword("23456345678");
entity3.setStatus(0);
entity3.setMobile("2345678");
entities.add(entity3);
List<UserEntity> userEntities = new ArrayList<>();
UserEntity entity2 = new UserEntity();
entity2.setUsername("0089090009");
entity2.setPassword("2345678");
entity2.setStatus(0);
entity2.setMobile("2345678");
userEntities.add(entity2);
UserEntity entity6 = new UserEntity();
entity6.setUsername("222222222");
entity6.setPassword("2345678");
entity6.setStatus(0);
entity6.setMobile("2345678");
userEntities.add(entity6);
UserEntity entitye= new UserEntity();
entitye.setUsername("222222222");
entitye.setPassword("2345678");
entitye.setStatus(0);
entitye.setMobile("2345678");
userEntities.add(entitye);
System.out.println("entity:"+userEntities.size());
System.out.println("-----");
System.out.println("userEntities:"+userEntities.size());
System.out.println("userEntities-set:"+userEntities.stream().distinct().collect(Collectors.toList()).size());
List<UserEntity> cm = cm(entities, userEntities);
System.out.println("end:"+cm.size());
}
public static List<UserEntity> cm(List<UserEntity> entities,List<UserEntity> userEntities){
userEntities = userEntities.stream().distinct().collect(Collectors.toList());
entities = entities.stream().distinct().collect(Collectors.toList());
List<UserEntity> list = new ArrayList<>();
for(UserEntity entity:userEntities){
entities.forEach(
s->{
if(s.getPassword().equals(entity.getPassword())&&s.getUsername().equals(entity.getUsername())){
list.add(entity);
}
}
);
}
List<UserEntity> models = userEntities.stream().filter(s -> !list.contains(s)).collect(Collectors.toList());
ArrayList<UserEntity> info = models.stream().collect(
Collectors.collectingAndThen(
Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(user -> user.getUsername() + ";" + user.getPassword()))), ArrayList::new));
List<UserEntity> classNameList = new ArrayList(new HashSet(info));
return classNameList;
}
}