Search in sources :

Example 1 with SizeConstraint

use of org.grails.validation.SizeConstraint in project grails-core by grails.

the class ConstrainedProperty method getMinSize.

/**
     * @return Returns the minSize.
     */
@Override
public Integer getMinSize() {
    Integer minSize = null;
    MinSizeConstraint minSizeConstraint = (MinSizeConstraint) appliedConstraints.get(MIN_SIZE_CONSTRAINT);
    SizeConstraint sizeConstraint = (SizeConstraint) appliedConstraints.get(SIZE_CONSTRAINT);
    if (minSizeConstraint != null || sizeConstraint != null) {
        int minSizeConstraintValue = minSizeConstraint == null ? Integer.MIN_VALUE : minSizeConstraint.getMinSize();
        int sizeConstraintLowValue = sizeConstraint == null ? Integer.MIN_VALUE : sizeConstraint.getRange().getFromInt();
        minSize = Math.max(minSizeConstraintValue, sizeConstraintLowValue);
    }
    return minSize;
}
Also used : MinSizeConstraint(org.grails.validation.MinSizeConstraint) MaxSizeConstraint(org.grails.validation.MaxSizeConstraint) SizeConstraint(org.grails.validation.SizeConstraint) MinSizeConstraint(org.grails.validation.MinSizeConstraint) MaxSizeConstraint(org.grails.validation.MaxSizeConstraint) MinConstraint(org.grails.validation.MinConstraint) SizeConstraint(org.grails.validation.SizeConstraint) MinSizeConstraint(org.grails.validation.MinSizeConstraint) BlankConstraint(org.grails.validation.BlankConstraint) RangeConstraint(org.grails.validation.RangeConstraint) ValidatorConstraint(org.grails.validation.ValidatorConstraint) ScaleConstraint(org.grails.validation.ScaleConstraint) NullableConstraint(org.grails.validation.NullableConstraint) MaxConstraint(org.grails.validation.MaxConstraint) CreditCardConstraint(org.grails.validation.CreditCardConstraint) UrlConstraint(org.grails.validation.UrlConstraint) InListConstraint(org.grails.validation.InListConstraint) MatchesConstraint(org.grails.validation.MatchesConstraint) NotEqualConstraint(org.grails.validation.NotEqualConstraint) EmailConstraint(org.grails.validation.EmailConstraint)

Example 2 with SizeConstraint

use of org.grails.validation.SizeConstraint in project grails-core by grails.

the class ConstrainedProperty method getMaxSize.

/**
     * @return Returns the maxSize.
     */
@Override
public Integer getMaxSize() {
    Integer maxSize = null;
    MaxSizeConstraint maxSizeConstraint = (MaxSizeConstraint) appliedConstraints.get(MAX_SIZE_CONSTRAINT);
    SizeConstraint sizeConstraint = (SizeConstraint) appliedConstraints.get(SIZE_CONSTRAINT);
    if (maxSizeConstraint != null || sizeConstraint != null) {
        int maxSizeConstraintValue = maxSizeConstraint == null ? Integer.MAX_VALUE : maxSizeConstraint.getMaxSize();
        int sizeConstraintHighValue = sizeConstraint == null ? Integer.MAX_VALUE : sizeConstraint.getRange().getToInt();
        maxSize = Math.min(maxSizeConstraintValue, sizeConstraintHighValue);
    }
    return maxSize;
}
Also used : MaxSizeConstraint(org.grails.validation.MaxSizeConstraint) MaxSizeConstraint(org.grails.validation.MaxSizeConstraint) SizeConstraint(org.grails.validation.SizeConstraint) MinSizeConstraint(org.grails.validation.MinSizeConstraint) MaxSizeConstraint(org.grails.validation.MaxSizeConstraint) MinConstraint(org.grails.validation.MinConstraint) SizeConstraint(org.grails.validation.SizeConstraint) MinSizeConstraint(org.grails.validation.MinSizeConstraint) BlankConstraint(org.grails.validation.BlankConstraint) RangeConstraint(org.grails.validation.RangeConstraint) ValidatorConstraint(org.grails.validation.ValidatorConstraint) ScaleConstraint(org.grails.validation.ScaleConstraint) NullableConstraint(org.grails.validation.NullableConstraint) MaxConstraint(org.grails.validation.MaxConstraint) CreditCardConstraint(org.grails.validation.CreditCardConstraint) UrlConstraint(org.grails.validation.UrlConstraint) InListConstraint(org.grails.validation.InListConstraint) MatchesConstraint(org.grails.validation.MatchesConstraint) NotEqualConstraint(org.grails.validation.NotEqualConstraint) EmailConstraint(org.grails.validation.EmailConstraint)

Example 3 with SizeConstraint

use of org.grails.validation.SizeConstraint in project grails-core by grails.

the class ConstrainedProperty method setSize.

/**
     * @param size The size to set.
     */
@SuppressWarnings("rawtypes")
public void setSize(Range size) {
    Constraint c = appliedConstraints.get(SIZE_CONSTRAINT);
    if (size == null) {
        appliedConstraints.remove(SIZE_CONSTRAINT);
    } else {
        if (c == null) {
            c = new SizeConstraint();
            c.setOwningClass(owningClass);
            c.setPropertyName(propertyName);
            appliedConstraints.put(SIZE_CONSTRAINT, c);
        }
        c.setParameter(size);
    }
}
Also used : MaxSizeConstraint(org.grails.validation.MaxSizeConstraint) MinConstraint(org.grails.validation.MinConstraint) SizeConstraint(org.grails.validation.SizeConstraint) MinSizeConstraint(org.grails.validation.MinSizeConstraint) BlankConstraint(org.grails.validation.BlankConstraint) RangeConstraint(org.grails.validation.RangeConstraint) ValidatorConstraint(org.grails.validation.ValidatorConstraint) ScaleConstraint(org.grails.validation.ScaleConstraint) NullableConstraint(org.grails.validation.NullableConstraint) MaxConstraint(org.grails.validation.MaxConstraint) CreditCardConstraint(org.grails.validation.CreditCardConstraint) UrlConstraint(org.grails.validation.UrlConstraint) InListConstraint(org.grails.validation.InListConstraint) MatchesConstraint(org.grails.validation.MatchesConstraint) NotEqualConstraint(org.grails.validation.NotEqualConstraint) EmailConstraint(org.grails.validation.EmailConstraint) MaxSizeConstraint(org.grails.validation.MaxSizeConstraint) SizeConstraint(org.grails.validation.SizeConstraint) MinSizeConstraint(org.grails.validation.MinSizeConstraint)

Aggregations

BlankConstraint (org.grails.validation.BlankConstraint)3 CreditCardConstraint (org.grails.validation.CreditCardConstraint)3 EmailConstraint (org.grails.validation.EmailConstraint)3 InListConstraint (org.grails.validation.InListConstraint)3 MatchesConstraint (org.grails.validation.MatchesConstraint)3 MaxConstraint (org.grails.validation.MaxConstraint)3 MaxSizeConstraint (org.grails.validation.MaxSizeConstraint)3 MinConstraint (org.grails.validation.MinConstraint)3 MinSizeConstraint (org.grails.validation.MinSizeConstraint)3 NotEqualConstraint (org.grails.validation.NotEqualConstraint)3 NullableConstraint (org.grails.validation.NullableConstraint)3 RangeConstraint (org.grails.validation.RangeConstraint)3 ScaleConstraint (org.grails.validation.ScaleConstraint)3 SizeConstraint (org.grails.validation.SizeConstraint)3 UrlConstraint (org.grails.validation.UrlConstraint)3 ValidatorConstraint (org.grails.validation.ValidatorConstraint)3