Class RuleBuilder<V>

java.lang.Object
com.atlassian.crowd.embedded.validator.rule.RuleBuilder<V>
Type Parameters:
V - Entity type to be validated
Direct Known Subclasses:
DirectoryRuleBuilder, MailServerRuleBuilder

public class RuleBuilder<V> extends Object
Builder class which facilitates creation of ValidationRule
Since:
3.2.0
  • Constructor Details

    • RuleBuilder

      public RuleBuilder(String fieldName)
  • Method Details

    • regex

      public static Predicate<String> regex(String pattern)
      Utility method which returns the predicate for matching any string value to the given regex pattern.
      Parameters:
      pattern - The pattern to which the string is to be tested against
      Returns:
      The generated predicate which tests an input string to specified regex
    • notNull

      public static Predicate<String> notNull()
    • isNull

      public static Predicate<String> isNull()
    • eq

      public static Predicate<String> eq(String testValue)
    • not

      public static <K> Predicate<K> not(Predicate<K> predicate)
    • matchesAny

      public static <K> Predicate<K> matchesAny(Predicate<K>... predicates)
    • matchesAll

      public static <K> Predicate<K> matchesAll(Predicate<K>... predicates)
    • message

      public static Supplier<String> message(I18nHelper i18nHelper, String messageKey)
    • isValidURI

      public static Predicate<String> isValidURI()
    • inLongRange

      public static Predicate<String> inLongRange(Long min, Long max)
    • greaterThanOrEquals

      public static Predicate<String> greaterThanOrEquals(Long number)
    • isValidRegex

      public static Predicate<String> isValidRegex()
    • check

      public <M> RuleBuilder<V> check(Function<V,M> valueRetriever, Predicate<M> predicate)
      Adds the value function, with the corresponding predicate to the checks list
      Parameters:
      valueRetriever - The value function to be used to retrieve value
      predicate - The predicate to be tested against the retrieved value from Function
      Returns:
      Current builder instance
    • check

      public RuleBuilder<V> check(Predicate<V> valueRetriever, boolean expectedValue)
      Adds the value function, with the corresponding predicate to the checks list
      Parameters:
      valueRetriever - Predicate which will be used to check condition
      expectedValue - The value which will be compare in predicate
      Returns:
      Current builder instance
    • ifMatchesThenSet

      public RuleBuilder<V> ifMatchesThenSet(Supplier<String> messageSupplier)
      Sets the message supplier, which will be used to get the actual error message for the field error
      Parameters:
      messageSupplier - The supplier for the error message
      Returns:
      Current builder's instance
    • ifMatchesThenSet

      public RuleBuilder<V> ifMatchesThenSet(Function<V,String> messageFunction)
      Sets the message function, which will be used to get the actual error message for the field error
      Parameters:
      messageFunction - the function, which will be used to get proper error message
      Returns:
      Current builder's instance
    • build

      public ValidationRule<V> build()
      Build the ValidationRule with the supplied value functions and their corresponding predicates, all of which must be positively tested to generate aa error
      Returns:
      ValidationRule A rule that can be applied on the RuleBuilder entity to be validated