class NotNegativeNumberValidator implements ConstraintValidator<NotNegative, Number> {

    @Override
    public boolean isValid(Number value, ConstraintValidatorContext constraintValidatorContext) {
        if (value == null) {
            return true;
        }
        if (value instanceof BigDecimal) {
            return ((BigDecimal) value).compareTo(BigDecimal.ZERO) == 1 ||
                    ((BigDecimal) value).compareTo(BigDecimal.ZERO) == 0;
        } else if (value instanceof BigInteger) {
            return ((BigInteger) value).compareTo(BigInteger.ZERO) == 1 ||
                    ((BigInteger) value).compareTo(BigInteger.ZERO) == 0;
        } else {
            return value.floatValue() >= 0;
        }
    }

}