/** * Checks to see if the size parameter of an some element is a multiple of the in input multiple value. * * @param multiple the multiple value to check the size against. * @param size the size value to check against. * @param validationContext The context of the item in the class being validated. This is used in case of an error. * @param elementType the type of the element being checked. * @param raveErrors the list of {@link RaveError}s. * @return a list of {@link RaveError}. */ private static List<RaveError> testMultipleParameter( long multiple, int size, ValidationContext validationContext, String elementType, List<RaveError> raveErrors) { if (multiple >= 0 && size % multiple != 0) { String msg = elementType + " is not a multiple of " + multiple + ", size is " + size; raveErrors = appendError(validationContext, msg, raveErrors); } return raveErrors; }
/** * Checks to see if the size of the input string is of a size as denoted by {@code min} and {@code max}. Also check * the {@code multiple} constraint of size. * * @param string The string to validate. * @param isNullable if true than null is a valid value for the input string regardless of min and max. * @param min The string must be at least this long. * @param max The string must not exceed this length. * @param multiple The multiple constraint on the Size. If less than zero it is * ignored. * @param validationContext The context of the item in the class being validated. This is used in case of an error. * @return {@link List} of {@link RaveError}s which list the validation violations. Null otherwise. */ protected static List<RaveError> isSizeOk( @Nullable String string, boolean isNullable, long min, long max, long multiple, ValidationContext validationContext) { List<RaveError> errors = checkNullable(string, isNullable, validationContext); if (string == null) { return errors; } int stringSize = string.length(); errors = testMultipleParameter(multiple, stringSize, validationContext, "String", errors); if (stringSize <= max && stringSize >= min) { return errors; } String msg = "String size out of bounds. Size is: " + string.length() + " when should be " + "between " + min + " and " + max; return appendError(validationContext, msg, errors); }
return appendError(validationContext, msg, raveErrors);
return appendError(validationContext, msg, raveErrors);
/** * Validate the size of an Array. * * @param array the array to validate. * @param isNullable if true than null is a valid value for the input string regardless of min and max. * @param min The Array must have least this many elements in it. * @param max The Array can have at most this many elements in it. * @param multiple The multiple constraint on the Size. If less than zero it is * ignored. * @param validationContext The context of the item in the class being validated. This is used in case of an error. * @param <T> can be anytype. * @return {@link List} of {@link RaveError}s which list the validation violations. Null otherwise. */ @Nullable protected static <T> List<RaveError> isSizeOk( @Nullable T[] array, boolean isNullable, long min, long max, long multiple, ValidationContext validationContext) { List<RaveError> raveErrors = checkNullable(array, isNullable, validationContext); if (array == null) { return raveErrors; } raveErrors = testMultipleParameter(multiple, array.length, validationContext, "", raveErrors); if (array.length <= max && array.length >= min) { return raveErrors; } String msg = "With size" + array.length + " is not within " + "bounds min:" + min + " and max:" + max; return appendError(validationContext, msg, raveErrors); }