cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vgritse...@apache.org
Subject cvs commit: cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/validationruleimpl RangeValidationRule.java
Date Sun, 04 Jan 2004 04:36:35 GMT
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;
           }
  
  
  

Mime
View raw message