X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fsal%2Fapi%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fmatch%2FMatch.java;h=910695c1e9cbc0ebcfb121b621fb7187305aff37;hb=2c4b7c792b049ece3177b8b6fc6b6331038c5f5b;hp=b6381cc7d8fbe089cc96dbea518e82be27c06817;hpb=f5ae77b71afeee5667bf2a8ad9d0753025ee1947;p=controller.git diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/match/Match.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/match/Match.java index b6381cc7d8..910695c1e9 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/match/Match.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/match/Match.java @@ -20,6 +20,7 @@ import java.util.HashMap; 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; @@ -441,7 +442,20 @@ public class Match implements Cloneable, Serializable { 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 tm = new TreeMap(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; } @@ -473,6 +487,13 @@ public class Match implements Cloneable, Serializable { @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(); } + }