@Override public int hashCode() { final int prime = 31; int result = 1; 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; }
public int hashCode(Object v, Object m) { final int prime = 31; int result = 1; result = prime * result + this.calculateConsistentHashCode(); switch (this) { case DL_SRC: case DL_DST: result = prime * result + ((v == null)? 0 : NetUtils.byteArray4ToInt((byte[])v)); result = prime * result + ((m == null)? 0 : NetUtils.byteArray4ToInt((byte[])m)); break; case NW_SRC: case NW_DST: // Hash code has to take into account only prefix address InetAddress ip = (InetAddress) v; int maskLen = (m == null) ? ((ip instanceof Inet4Address) ? 32 : 128) : NetUtils .getSubnetMaskLength((InetAddress) m); InetAddress prefix = NetUtils.getSubnetPrefix(ip, maskLen); result = prime * result + ((v == null)? 0 : prefix.hashCode()); break; default: result = prime * result + ((v == null)? 0 : v.hashCode()); result = prime * result + ((m == null)? 0 : m.hashCode()); } return result; } public boolean equalValues(Object a, Object b) {