package cn.com.countrygarden.bi.main.model.test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class ListSortJava8 {
//    public static void main(String[] args) {
//    	List<Teacher> teachers = new ArrayList<Teacher>();
//      teachers.add(new Teacher("张三", 24));
//      teachers.add(new Teacher("李四", 23));
//      teachers.add(new Teacher("王五", 25));
//      teachers.add(new Teacher("钱二", 23));
//   
//        System.out.println("before sort:");
//        for (Teacher bean : teachers) {
//            System.out.println("before sort---->age: " + bean.getAge() + "==name：" + bean.getName());
//        }
//        //Lambda
////        teachers.sort((t1, t2) -> s1.getAge().compareTo(s2.getAge()));
//        //Comparator
////        Collections.sort(teachers, Comparator.comparing(Teacher::getAge));
//        //reversed
////        Comparator<Teacher> comparator = (t1, t2) -> t1.getAge().compareTo(t2.getAge());
////        teachers.sort(comparator.reversed());
//        //组合排序
//        Collections.sort(teachers, Comparator.comparing(Teacher::getAge));
//        System.out.println("after sort:");
//        for (Teacher bean : teachers) {
//            System.out.println("after sort---->age: " + bean.getAge() + "==name：" + bean.getName());
//        }
//        
//        
//    }
	public static void main(String[] args) {
    	List<Teacher> teachers = new ArrayList<Teacher>();
      teachers.add(new Teacher("张三", 24));
      teachers.add(new Teacher("李四", 23));
      teachers.add(new Teacher("王五", 25));
      teachers.add(new Teacher("钱二", 23));
      List<Teacher> list= new ArrayList<Teacher>();
      list.add(new Teacher("张三", 24));
      list.add(new Teacher("tom", 24));
	    teachers.retainAll(list);
	    if(teachers.size()>0){
	        System.out.println("这两个集合有相同的交集"+teachers.get(0).getName()+","+teachers.size());
	    }else{
	        System.out.println("这两个集合没有相同的交集");
	    }
	}
}



//@AllArgsConstructor
//@NoArgsConstructor
//@Data

class Teacher {
    private String name;
    private Integer age;
    public Teacher(String name, Integer age) {
        this.name = name;
        this.age = age;
    }
    
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Integer getAge() {
		return age;
	}
	public void setAge(Integer age) {
		this.age = age;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((age == null) ? 0 : age.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Teacher other = (Teacher) obj;
		if (age == null) {
			if (other.age != null)
				return false;
		} else if (!age.equals(other.age))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}
    
	

}
