Class FulfillmentValidationUtil


  • public class FulfillmentValidationUtil
    extends Object
    Utility class with helper functions to perform validation.
    Author:
    Jacob Mitash
    • Constructor Detail

      • FulfillmentValidationUtil

        public FulfillmentValidationUtil()
    • Method Detail

      • hasHint

        public static boolean hasHint​(@NonNull
                                      @NonNull Collection<Object> hints,
                                      @NonNull
                                      @NonNull String requestedHint)
        Tells if the specified hint is in the collection of hints.
        Parameters:
        hints - the collection of hints to check
        requestedHint - the hint to check if present
        Returns:
        true if the hint is present, false otherwise
      • rejectIfNegative

        public static void rejectIfNegative​(@NonNull
                                            @NonNull org.springframework.validation.Errors errors,
                                            @NonNull
                                            @NonNull String fieldName,
                                            @NonNull
                                            @NonNull String errorCode)
        Rejects a value if it is non-null and negative.
        Parameters:
        errors - the errors container to pull the value and add the rejection to
        fieldName - the name of the field to test
        errorCode - the error code to add to the errors
      • rejectIfNull

        public static void rejectIfNull​(@NonNull
                                        @NonNull org.springframework.validation.Errors errors,
                                        @NonNull
                                        @NonNull String fieldName,
                                        @NonNull
                                        @NonNull String errorCode)
        Rejects a value if it is null.
        Parameters:
        errors - the errors container to pull the value and add the rejection to
        fieldName - the name of the field to test
        errorCode - the error code to add to the errors
      • rejectIfTrue

        public static void rejectIfTrue​(@NonNull
                                        @NonNull org.springframework.validation.Errors errors,
                                        @NonNull
                                        @NonNull String fieldName,
                                        @NonNull
                                        @NonNull String errorCode)
        Rejects a value if it is non-null and true.
        Parameters:
        errors - the errors container to pull the value and add the rejection to
        fieldName - the name of the field to test
        errorCode - the error code to add to the errors
      • rejectIfFalse

        public static void rejectIfFalse​(@NonNull
                                         @NonNull org.springframework.validation.Errors errors,
                                         @NonNull
                                         @NonNull String fieldName,
                                         @NonNull
                                         @NonNull String errorCode)
        Rejects a value if it is non-null and false.
        Parameters:
        errors - the errors container to pull the value and add the rejection to
        fieldName - the name of the field to test
        errorCode - the error code to add to the errors
      • rejectIfEmptyCollection

        public static void rejectIfEmptyCollection​(@NonNull
                                                   @NonNull org.springframework.validation.Errors errors,
                                                   @NonNull
                                                   @NonNull String fieldName,
                                                   @NonNull
                                                   @NonNull String errorCode)
        Rejects a collection value if it is empty or null.
        Parameters:
        errors - the errors container to pull the value and add the rejection to
        fieldName - the name of the field to test
        errorCode - the error code to add to the errors
      • getField

        @Nullable
        public static <T> T getField​(@NonNull
                                     @NonNull org.springframework.validation.Errors errors,
                                     @NonNull
                                     @NonNull String fieldName,
                                     @NonNull
                                     @NonNull Class<T> clazz)
        Gets the value from a field casted to the requested type.
        Type Parameters:
        T - the type the field value should be cast to
        Parameters:
        errors - the errors container to grab the value from
        fieldName - the name of the field to fetch the value of
        clazz - the class the field value should be cast to
        Returns:
        the value of the field
      • validateFields

        public static void validateFields​(@NonNull
                                          @NonNull org.springframework.validation.Errors errors,
                                          @NonNull
                                          @NonNull Collection<String> fieldNames,
                                          @NonNull
                                          @NonNull FulfillmentValidationUtil.FieldValidator fieldValidator,
                                          @NonNull
                                          @NonNull String errorCodePattern)
        Validates multiple fields' values.
        Parameters:
        errors - the error container to pull values and add rejections to
        fieldNames - the names of the fields to validate
        fieldValidator - the validator that will validate the fields value
        errorCodePattern - the error code with a '{}' in place of the field name (see errorCode(String, String))