use of org.grails.validation.RangeConstraint in project grails-core by grails.
the class ConstrainedProperty method setRange.
/**
* @param range The range to set.
*/
@SuppressWarnings("rawtypes")
public void setRange(Range range) {
if (appliedConstraints.containsKey(MAX_CONSTRAINT)) {
LOG.warn("Setting range constraint on property [" + propertyName + "] of class [" + owningClass + "] forced removal of max constraint");
appliedConstraints.remove(MAX_CONSTRAINT);
}
if (appliedConstraints.containsKey(MIN_CONSTRAINT)) {
LOG.warn("Setting range constraint on property [" + propertyName + "] of class [" + owningClass + "] forced removal of min constraint");
appliedConstraints.remove(MIN_CONSTRAINT);
}
if (range == null) {
appliedConstraints.remove(RANGE_CONSTRAINT);
} else {
Constraint c = appliedConstraints.get(RANGE_CONSTRAINT);
if (c == null) {
c = new RangeConstraint();
c.setOwningClass(owningClass);
c.setPropertyName(propertyName);
appliedConstraints.put(RANGE_CONSTRAINT, c);
}
c.setParameter(range);
}
}
use of org.grails.validation.RangeConstraint in project grails-core by grails.
the class ConstrainedProperty method getMax.
/**
* @return Returns the max.
*/
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public Comparable getMax() {
Comparable maxValue = null;
MaxConstraint maxConstraint = (MaxConstraint) appliedConstraints.get(MAX_CONSTRAINT);
RangeConstraint rangeConstraint = (RangeConstraint) appliedConstraints.get(RANGE_CONSTRAINT);
if (maxConstraint != null || rangeConstraint != null) {
Comparable maxConstraintValue = maxConstraint == null ? null : maxConstraint.getMaxValue();
Comparable rangeConstraintHighValue = rangeConstraint == null ? null : rangeConstraint.getRange().getTo();
if (maxConstraintValue != null && rangeConstraintHighValue != null) {
maxValue = (maxConstraintValue.compareTo(rangeConstraintHighValue) < 0) ? maxConstraintValue : rangeConstraintHighValue;
} else if (maxConstraintValue == null && rangeConstraintHighValue != null) {
maxValue = rangeConstraintHighValue;
} else if (maxConstraintValue != null && rangeConstraintHighValue == null) {
maxValue = maxConstraintValue;
}
}
return maxValue;
}
use of org.grails.validation.RangeConstraint in project grails-core by grails.
the class ConstrainedProperty method getMin.
/**
* @return Returns the min.
*/
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public Comparable getMin() {
Comparable minValue = null;
MinConstraint minConstraint = (MinConstraint) appliedConstraints.get(MIN_CONSTRAINT);
RangeConstraint rangeConstraint = (RangeConstraint) appliedConstraints.get(RANGE_CONSTRAINT);
if (minConstraint != null || rangeConstraint != null) {
Comparable minConstraintValue = minConstraint != null ? minConstraint.getMinValue() : null;
Comparable rangeConstraintLowValue = rangeConstraint != null ? rangeConstraint.getRange().getFrom() : null;
if (minConstraintValue != null && rangeConstraintLowValue != null) {
minValue = (minConstraintValue.compareTo(rangeConstraintLowValue) > 0) ? minConstraintValue : rangeConstraintLowValue;
} else if (minConstraintValue == null && rangeConstraintLowValue != null) {
minValue = rangeConstraintLowValue;
} else if (minConstraintValue != null && rangeConstraintLowValue == null) {
minValue = minConstraintValue;
}
}
return minValue;
}
Aggregations