具体代码如下:
import java.util.Collection;
import java.util.List;
import java.util.Objects;
/**
* Table metadata.
*
* @author lxk
*/
public class ListEqualMethod {
private Collection<OuAndAddressInformationDto> dtos;
public ListEqualMethod(Collection<OuAndAddressInformationDto> dtos) {
this.dtos = dtos;
}
public Collection<OuAndAddressInformationDto> getDtos() {
return dtos;
}
public void setDtos(Collection<OuAndAddressInformationDto> dtos) {
this.dtos = dtos;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ListEqualMethod that = (ListEqualMethod) o;
if (dtos.size() != that.getDtos().size()) {
return false;
}
return dtos.containsAll(that.getDtos());
}
@Override
public int hashCode() {
return Objects.hash(dtos);
}
}
调用代码如下:
ListEqualMethod list1 = new ListEqualMethod(OUAreaList);
ListEqualMethod list2 = new ListEqualMethod(allOUAreaList);
boolean flag = list1.equals(list2);
xxxDto可以替换为进行比较的对象