X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=opendaylight%2Fsal%2Fapi%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fmatch%2FMatch.java;h=910695c1e9cbc0ebcfb121b621fb7187305aff37;hb=cb1e31959fc051916dc7ff27020571a6432323af;hp=2c3cfb8303736229e6c86b618642f6bd72b12aaa;hpb=d245dda0d7f6e14891af8a3a8f44d20939e00ee4;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 2c3cfb8303..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; @@ -444,13 +445,16 @@ public class Match implements Cloneable, Serializable { if (this.fields == null) { result = prime * result; } else { - int sum = 0; - for (MatchType field : this.fields.keySet()) { - MatchField f = this.fields.get(field); - sum = sum + ((field==null ? 0 : field.calculateConsistentHashCode()) ^ - (f==null ? 0 : f.hashCode())); + // 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 + sum; } result = prime * result + matches; return result;