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;
/**
* Represents the generic matching field
- *
+ *
*/
@XmlRootElement
@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
/**
* Mask based match constructor
- *
+ *
* @param type
* @param value
* @param mask
/**
* Full match constructor
- *
+ *
* @param type
* @param value
*/
/**
* Returns the value set for this match field
- *
+ *
* @return
*/
public Object getValue() {
/**
* Returns the type field this match field object is for
- *
+ *
* @return
*/
public MatchType getType() {
/**
* Returns the mask value set for this field match A null mask means this is
* a full match
- *
+ *
* @return
*/
public Object getMask() {
/**
* Returns the bitmask set for this field match
- *
+ *
* @return
*/
public long getBitMask() {
/**
* Returns whether the field match configuration is valid or not
- *
+ *
* @return
*/
public boolean isValid() {
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;
}
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;
}
}
} catch (CloneNotSupportedException e) {
- e.printStackTrace();
+ 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
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);
}
}