import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.TreeMap;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + ((fields == null) ? 0 : fields.hashCode());
+ if (this.fields == null) {
+ result = prime * result;
+ } else {
+ // use a tree map as the order of hashMap is not guaranteed.
+ // 2 Match objects with fields in different order are still equal.
+ // Hence the hashCode should be the same too.
+ TreeMap<MatchType, MatchField> tm = new TreeMap<MatchType, MatchField>(this.fields);
+ for (MatchType field : tm.keySet()) {
+ MatchField f = tm.get(field);
+ int fieldHashCode = (field==null ? 0 : field.calculateConsistentHashCode()) ^
+ (f==null ? 0 : f.hashCode());
+ result = prime * result + fieldHashCode;
+ }
+ }
result = prime * result + matches;
return result;
}
@Override
public String toString() {
- return "Match[" + fields.values() + "]";
+ StringBuilder builder = new StringBuilder();
+ builder.append("Match [fields=");
+ builder.append(fields);
+ builder.append(", matches=");
+ builder.append(matches);
+ builder.append("]");
+ return builder.toString();
}
+
}