1 23 24 package org.infoglue.cms.util.validators; 25 26 import org.infoglue.cms.exception.Bug; 27 import org.infoglue.cms.exception.ConstraintException; 28 import org.infoglue.cms.util.ConstraintExceptionBuffer; 29 30 31 44 public class FloatValidator extends AbstractValidator 45 { 46 48 private static final String ILLEGAL_VALUE_ERROR_CODE = "306"; 50 51 52 53 55 private float lowerLimit; 57 private float upperLimit; 58 59 60 61 64 67 FloatValidator(String fieldName, boolean isRequired, float lowerLimit, float upperLimit) { 68 super(fieldName, isRequired); 69 70 if(lowerLimit > upperLimit) { 71 throw new Bug("Illegal arguments : lowerLimit=" + lowerLimit + ", upperLimit=" + upperLimit + "."); 72 } 73 this.lowerLimit = lowerLimit; 74 this.upperLimit = upperLimit; 75 } 76 77 78 79 81 84 public void validate(Float value) throws ConstraintException { 85 validateIsRequired(value); 86 if(value == null) { return; 88 } 89 validateValueSpace(value.floatValue()); 90 failIfAnyExceptionsFound(); 91 } 92 93 95 public void validate(Float value, ConstraintExceptionBuffer ceb) { 96 try { 97 validate(value); 98 } catch(ConstraintException e) { 99 ceb.add(e); 100 } 101 } 102 103 108 111 private void validateValueSpace(float value) { 112 if(value < this.lowerLimit || value > this.upperLimit) { 113 addConstraintException(ILLEGAL_VALUE_ERROR_CODE); 114 } 115 } 116 117 118 119 } | Popular Tags |