if (number != null) {
// check number sub-type constraint
if (numberSubTypeConstraint != null) {
if (!numberSubTypeConstraint.getNumberSubType().equals(
number.getClass())) {
errors.add(new VerificationError(
VerificationError.TYPE_CONSTRAINT_VIOLATION, path,
value, numberSubTypeConstraint,
"Invalid number type. Expected: " +
numberSubTypeConstraint.getNumberSubType() +
", found: " + number.getClass()));
}
}
// check minimum value constraint
if (minimumValueConstraint != null) {
final Number minimum =
minimumValueConstraint.getLimitAsNumber();
final boolean inclusive =
minimumValueConstraint.isInclusive();
final int compareResult =
NUMBER_COMPARATOR.compare(number, minimum);
if (compareResult < 0 || compareResult == 0 && !inclusive) {
errors.add(new VerificationError(
VerificationError.TYPE_CONSTRAINT_VIOLATION, path,
value, minimumValueConstraint,
"Minimum value constraint violated. " +
"Minimum value: " + minimum +
(inclusive? " (inclusive)": " (exclusive)") +
", received: " + number));
}
}
// check maximum value constraint
if (maximumValueConstraint != null) {
final Number maximum =
maximumValueConstraint.getLimitAsNumber();
final boolean inclusive =
maximumValueConstraint.isInclusive();
final int compareResult =
NUMBER_COMPARATOR.compare(maximum, number);
if (compareResult < 0 || compareResult == 0 && !inclusive) {
errors.add(new VerificationError(
VerificationError.TYPE_CONSTRAINT_VIOLATION, path,
value, maximumValueConstraint,
"Maximum value constraint violated. " +
"Maximum value: " + maximum +
(inclusive? " (inclusive)": " (exclusive)") +
", received: " + number));
}
}
} else {
errors.add(new VerificationError(
VerificationError.TYPE_NULL_VALUE, path, value, null,
"Value cannot be null."));
}
}
return errors;