X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fsal%2Fapi%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fmatch%2FMatchField.java;h=54be4c67189412a208dc5cfebb6fef2ff49f0301;hb=refs%2Fchanges%2F69%2F969%2F2;hp=bd5ef2bafbd4134e74469824962b6e18f42edaeb;hpb=541d0a36997f292bb037a2199463431eee538358;p=controller.git diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/match/MatchField.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/match/MatchField.java index bd5ef2bafb..54be4c6718 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/match/MatchField.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/match/MatchField.java @@ -9,7 +9,6 @@ package org.opendaylight.controller.sal.match; import java.io.Serializable; - import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; @@ -27,12 +26,11 @@ 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 + // specified field private transient boolean isValid; // To satisfy JAXB @@ -134,16 +132,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 +147,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; @@ -188,24 +177,20 @@ public class MatchField implements Cloneable, Serializable { } } } 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 +208,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); } }