Methods Summary |
---|
public boolean | matches(java.lang.Object value)match with the given Object value.
boolean result = false;
switch (matchExpr) {
case Constants.MATCH_EQUALS:
result = matchValue.equals(value);
break;
case Constants.MATCH_NOT_EQUALS:
result = !(matchValue.equals(value));
break;
case Constants.MATCH_GREATER:
// convert to a Float type
{
Float lval = new Float(value.toString());
result = (lval.floatValue() > minValue);
}
break;
case Constants.MATCH_LESSER:
// convert to a Float type
{
Float lval = new Float(value.toString());
result = (lval.floatValue() < maxValue);
}
break;
case Constants.MATCH_IN_RANGE:
// convert to a Float type
{
Float lval = new Float(value.toString());
result = (lval.floatValue() >= minValue &&
lval.floatValue() <= maxValue);
}
break;
}
// did it match?
return (result == true) ? cacheOnMatch : cacheOnMatchFailure;
|
private void | parseRangeValue(java.lang.String value)match the given a range of values
float val1, val2;
if (value == null || value.length() <= 2) {
String msg = _rb.getString("cache.mapping.illegalValueRange");
Object[] params = { value };
msg = MessageFormat.format(msg, params);
throw new IllegalArgumentException(msg);
}
// get the separator first
int separator;
if (value.charAt(0) == '-") {
separator = value.indexOf('-", 1);
} else {
separator = value.indexOf('-", 0);
}
if (separator == -1) {
String msg = _rb.getString("cache.mapping.missingRangeSep");
Object[] params = { value };
msg = MessageFormat.format(msg, params);
throw new IllegalArgumentException(msg);
}
// get the first value
String sval1 = value.substring(0, separator).trim();
try {
val1 = Float.parseFloat(sval1);
} catch (NumberFormatException nfe) {
String msg = _rb.getString("cache.mapping.lowerRangeRequiresNumber");
Object[] params = { sval1 };
msg = MessageFormat.format(msg, params);
throw new IllegalArgumentException(msg);
}
// is max value specified at all?
if (separator == value.length()){
String msg = _rb.getString("cache.mapping.rangeRequiresUpperBound");
Object[] params = { value };
msg = MessageFormat.format(msg, params);
throw new IllegalArgumentException(msg);
}
String sval2 = value.substring(separator + 1).trim();
try {
val2 = Float.parseFloat(sval2);
} catch (NumberFormatException nfe) {
String msg = _rb.getString("cache.mapping.upperRangeRequiresNumber");
Object[] params = { sval2 };
msg = MessageFormat.format(msg, params);
throw new IllegalArgumentException(msg);
}
this.minValue = val1;
this.maxValue = val2;
|
public void | setCacheOnMatch(boolean cacheOnMatch)set whether to cache if there was a match
this.cacheOnMatch = cacheOnMatch;
|
public void | setCacheOnMatchFailure(boolean cacheOnMatchFailure)set whether to cache if there was a failure to match
this.cacheOnMatchFailure = cacheOnMatchFailure;
|
public void | setMatchExpr(int expr)set field matching expression
this.matchExpr = expr;
|
public void | setMaxValue(float value)set the maximum value
this.maxValue = value;
|
public void | setMinValue(float value)set minimum value
this.minValue = value;
|
public void | setValue(java.lang.String value)set value for this constraint
this.matchValue = value;
|
public java.lang.String | toString()
if (str == null) {
str = "match value = " + matchValue + " match expr = "
+ EXPR_NAMES[matchExpr];
}
return str;
|