Assume you have some objects which have several fields they can be compared by:
public class Person {
private String firstName;
private String lastN
import com.google.common.collect.ComparisonChain;
/**
* @author radler
* Class Description ...
*/
public class Attribute implements Comparable {
private String type;
private String value;
public String getType() { return type; }
public void setType(String type) { this.type = type; }
public String getValue() { return value; }
public void setValue(String value) { this.value = value; }
@Override
public String toString() {
return "Attribute [type=" + type + ", value=" + value + "]";
}
@Override
public int compareTo(Attribute that) {
return ComparisonChain.start()
.compare(this.type, that.type)
.compare(this.value, that.value)
.result();
}
}