use of org.grails.validation.MinConstraint in project grails-core by grails.
the class ConstrainedProperty method setMin.
/**
* @param min The min to set.
*/
@SuppressWarnings("rawtypes")
public void setMin(Comparable min) {
if (min == null) {
appliedConstraints.remove(MIN_CONSTRAINT);
return;
}
if (!propertyType.equals(min.getClass())) {
throw new MissingPropertyException(MIN_CONSTRAINT, propertyType);
}
Range r = getRange();
if (r != null) {
LOG.warn("Range constraint already set ignoring constraint [" + MIN_CONSTRAINT + "] for value [" + min + "]");
return;
}
Constraint c = appliedConstraints.get(MIN_CONSTRAINT);
if (c == null) {
c = new MinConstraint();
c.setOwningClass(owningClass);
c.setPropertyName(propertyName);
appliedConstraints.put(MIN_CONSTRAINT, c);
}
c.setParameter(min);
}
use of org.grails.validation.MinConstraint 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