Merge "Checkstyle enforcer"
[controller.git] / opendaylight / sal / api / src / main / java / org / opendaylight / controller / sal / match / Match.java
index e376ba7a17341c72edd82ce93ca750988ca84f2c..00a2f57308d57e1d76c8f0e88aeb86d74a3f910a 100644 (file)
@@ -9,12 +9,12 @@
 
 package org.opendaylight.controller.sal.match;
 
+import java.io.Serializable;
 import java.net.Inet4Address;
 import java.net.Inet6Address;
 import java.net.InetAddress;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
@@ -26,8 +26,6 @@ import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
 import org.opendaylight.controller.sal.utils.EtherTypes;
 import org.opendaylight.controller.sal.utils.IPProtocols;
 import org.opendaylight.controller.sal.utils.NetUtils;
@@ -39,8 +37,9 @@ import org.opendaylight.controller.sal.utils.NetUtils;
  */
 @XmlRootElement
 @XmlAccessorType(XmlAccessType.NONE)
-public class Match implements Cloneable {
-    private static final Map<MatchType, MatchType> reversableMatches;
+public class Match implements Cloneable, Serializable {
+        private static final long serialVersionUID = 1L;
+        private static final Map<MatchType, MatchType> reversableMatches;
     static {
         Map<MatchType, MatchType> map = new HashMap<MatchType, MatchType>();
         map.put(MatchType.DL_SRC, MatchType.DL_DST);
@@ -68,9 +67,9 @@ public class Match implements Cloneable {
      * Generic setter for frame/packet/message's header fields against which to match
      * Note: For MAC addresses, please pass the cloned value to this function
      *
-     * @param type             packet's header field type
-     * @param value    field's value to assign to the match
-     * @param mask             field's bitmask to apply to the match (has to be of the same class type of value)
+     * @param type      packet's header field type
+     * @param value     field's value to assign to the match
+     * @param mask      field's bitmask to apply to the match (has to be of the same class type of value)
      */
     public void setField(MatchType type, Object value, Object mask) {
         MatchField field = new MatchField(type, value, mask);
@@ -84,8 +83,8 @@ public class Match implements Cloneable {
      * Generic setter for frame/packet/message's header fields against which to match
      * Note: For MAC addresses, please pass the cloned value to this function
      *
-     * @param type             packet's header field type
-     * @param value    field's value to assign to the match
+     * @param type      packet's header field type
+     * @param value     field's value to assign to the match
      */
     public void setField(MatchType type, Object value) {
         MatchField field = new MatchField(type, value);
@@ -118,7 +117,7 @@ public class Match implements Cloneable {
     /**
      * Generic getter for fields against which the match is programmed
      *
-     * @param type     frame/packet/message's header field type
+     * @param type  frame/packet/message's header field type
      * @return
      */
     public MatchField getField(MatchType type) {
@@ -138,7 +137,7 @@ public class Match implements Cloneable {
     /**
      * Returns the list of MatchType fields the match is set for
      *
-     * @return List of individual MatchType fields. 
+     * @return List of individual MatchType fields.
      */
     public List<MatchType> getMatchesList() {
         return new ArrayList<MatchType>(fields.keySet());
@@ -147,13 +146,13 @@ public class Match implements Cloneable {
     /**
      * Returns the list of MatchFields the match is set for
      *
-     * @return List of individual MatchField values. 
+     * @return List of individual MatchField values.
      */
     @XmlElement(name="matchField")
     public List<MatchField> getMatchFields() {
-       return new ArrayList<MatchField>(fields.values());
+        return new ArrayList<MatchField>(fields.values());
     }
-    
+
     /**
      * Returns whether this match is for an IPv6 flow
      */
@@ -292,10 +291,8 @@ public class Match implements Cloneable {
                         && filterAddress instanceof Inet4Address) {
                     return true;
                 }
-                InetAddress thisMask = (InetAddress) filter.getField(type)
-                        .getMask();
-                InetAddress filterMask = (InetAddress) filter.getField(type)
-                        .getMask();
+                InetAddress thisMask = (InetAddress) thisField.getMask();
+                InetAddress filterMask = (InetAddress) filterField.getMask();
                 // thisAddress has to be in same subnet of filterAddress
                 if (NetUtils.inetAddressConflict(thisAddress, filterAddress,
                         thisMask, filterMask)) {
@@ -338,12 +335,30 @@ public class Match implements Cloneable {
 
     @Override
     public int hashCode() {
-        return HashCodeBuilder.reflectionHashCode(this);
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((fields == null) ? 0 : fields.hashCode());
+        result = prime * result + matches;
+        return result;
     }
 
     @Override
     public boolean equals(Object obj) {
-        return EqualsBuilder.reflectionEquals(this, obj);
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        Match other = (Match) obj;
+        if (fields == null) {
+            if (other.fields != null)
+                return false;
+        } else if (!fields.equals(other.fields))
+            return false;
+        if (matches != other.matches)
+            return false;
+        return true;
     }
 
     @Override