Make use of NetUtils.getBroadcastMacAddr()
[controller.git] / opendaylight / sal / api / src / main / java / org / opendaylight / controller / sal / match / MatchField.java
index bd5ef2bafbd4134e74469824962b6e18f42edaeb..554d7e2fb3df93564cc7575fe6a83486deaa131f 100644 (file)
@@ -27,13 +27,12 @@ import org.slf4j.LoggerFactory;
 @XmlAccessorType(XmlAccessType.NONE)
 public class MatchField implements Cloneable, Serializable {
     private static final long serialVersionUID = 1L;
-    private static final Logger logger = LoggerFactory
-            .getLogger(MatchField.class);
+    private static final Logger logger = LoggerFactory.getLogger(MatchField.class);
     private MatchType type; // the field we want to match
     private Object value; // the value of the field we want to match
     private Object mask; // the value of the mask we want to match on the
-                         // specified field
-    private transient boolean isValid;
+    // specified field
+    private boolean isValid;
 
     // To satisfy JAXB
     @SuppressWarnings("unused")
@@ -134,16 +133,11 @@ public class MatchField implements Cloneable, Serializable {
 
     private boolean checkValueType() {
         if (type.isCongruentType(value, mask) == false) {
-            String valueClass = (value == null) ? "null" : value.getClass()
-                    .getSimpleName();
-            String maskClass = (mask == null) ? "null" : mask.getClass()
-                    .getSimpleName();
-            String error = "Invalid match field's value or mask types.For field: "
-                    + type.id()
-                    + " Expected:"
-                    + type.dataType().getSimpleName()
-                    + " or equivalent,"
-                    + " Got:(" + valueClass + "," + maskClass + ")";
+            String valueClass = (value == null) ? "null" : value.getClass().getSimpleName();
+            String maskClass = (mask == null) ? "null" : mask.getClass().getSimpleName();
+            String error = "Invalid match field's value or mask types.For field: " + type.id() + " Expected:"
+                    + type.dataType().getSimpleName() + " or equivalent," + " Got:(" + valueClass + "," + maskClass
+                    + ")";
             throwException(error);
             return false;
         }
@@ -154,13 +148,9 @@ public class MatchField implements Cloneable, Serializable {
         if (type.isValid(value, mask) == false) {
             String maskString = (mask == null) ? "null" : ("0x" + Integer
                     .toHexString(Integer.parseInt(mask.toString())));
-            String error = "Invalid match field's value or mask assignement.For field: "
-                    + type.id()
-                    + " Expected: "
-                    + type.getRange()
-                    + ", Got:(0x"
-                    + Integer.toHexString(Integer.parseInt(value.toString()))
-                    + "," + maskString + ")";
+            String error = "Invalid match field's value or mask assignement.For field: " + type.id() + " Expected: "
+                    + type.getRange() + ", Got:(0x" + Integer.toHexString(Integer.parseInt(value.toString())) + ","
+                    + maskString + ")";
 
             throwException(error);
             return false;
@@ -187,25 +177,23 @@ public class MatchField implements Cloneable, Serializable {
                     cloned.mask = ((byte[]) this.mask).clone();
                 }
             }
+            cloned.type = this.type;
+            cloned.isValid = this.isValid;
         } catch (CloneNotSupportedException e) {
-            logger.error("",e);
+            logger.error("", e);
         }
         return cloned;
     }
 
     @Override
     public String toString() {
-        return type + "(" + getValueString() + "," + getMaskString() + ")";
+        return (mask == null) ? String.format("%s(%s)", getTypeString(), getValueString()) :
+            String.format("%s(%s,%s)", getTypeString(), getValueString(), getMaskString());
     }
 
     @Override
     public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + ((mask == null) ? 0 : mask.hashCode());
-        result = prime * result + ((type == null) ? 0 : type.hashCode());
-        result = prime * result + ((value == null) ? 0 : value.hashCode());
-        return result;
+        return type.hashCode(value, mask);
     }
 
     @Override
@@ -223,7 +211,6 @@ public class MatchField implements Cloneable, Serializable {
         if (type != other.type) {
             return false;
         }
-        return (type.equalValues(this.value, other.value) && type.equalMasks(
-                this.mask, other.mask));
+        return type.equals(this.value, other.value, this.mask, other.mask);
     }
 }