public class LabelValue {
private String label;
private String value;
public LabelValue(final String label, final String value) {
this.label = label;
this.value = value;
}
public String getLabel() {
return this.label;
}
public void setLabel(String label) {
this.label = label;
}
public String getValue() {
return this.value;
}
public void setValue(String value) {
this.value = value;
}
public int hashCode() {
return (this.getValue() == null) ? 17 : this.getValue().hashCode();
}
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof LabelValue)) {
return false;
}
LabelValue bean = (LabelValue) obj;
int nil = (this.getValue() == null) ? 1 : 0;
nil += (bean.getValue() == null) ? 1 : 0;
if (nil == 2) {
return true;
} else if (nil == 1) {
return false;
} else {
return this.getValue().equals(bean.getValue());
}
}
}
public class MyResult {
public static void main(String[] args) {
LabelValue lv1 = new LabelValue("1","router");
LabelValue lv2 = new LabelValue("2","switch");
LabelValue lv3 = new LabelValue("3","router");
LabelValue lv4 = new LabelValue("4","");
System.out.println(lv4.hashCode());
}
}