You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by vg...@apache.org on 2004/01/04 05:36:35 UTC
cvs commit: cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/validationruleimpl RangeValidationRule.java
vgritsenko 2004/01/03 20:36:35
Modified: src/blocks/woody/java/org/apache/cocoon/woody/datatype/validationruleimpl
RangeValidationRule.java
Log:
Add support for Double and Float to this profane hack :-)
Revision Changes Path
1.6 +8 -1 cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/validationruleimpl/RangeValidationRule.java
Index: RangeValidationRule.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/validationruleimpl/RangeValidationRule.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- RangeValidationRule.java 30 Dec 2003 20:22:08 -0000 1.5
+++ RangeValidationRule.java 4 Jan 2004 04:36:35 -0000 1.6
@@ -60,7 +60,9 @@
import org.outerj.expression.ExpressionContext;
/**
- * Checks numeric ranges. Works for Integer, Long and BigDecimal values.
+ * Checks numeric ranges.
+ * Works for Integer, Long, BigDecimal, Float, Double, and Date values.
+ * Numbers are converted to the BigDecimal before comparing.
*
* <p>This validation rule can perform 3 different checks:
* <ul>
@@ -87,11 +89,16 @@
}
public ValidationError validate(Object value, ExpressionContext expressionContext) {
+ // HACK: JDK's Comparable can't even compare Decimal to Integer
Comparable decimal;
if (value instanceof Integer) {
decimal = new BigDecimal(((Integer) value).intValue());
} else if (value instanceof Long) {
decimal = new BigDecimal(((Long) value).longValue());
+ } else if (value instanceof Float) {
+ decimal = new BigDecimal(((Float) value).floatValue());
+ } else if (value instanceof Double) {
+ decimal = new BigDecimal(((Double) value).doubleValue());
} else {
decimal = (Comparable) value;
}