/** * Copy the current immutable object by setting a value for the {@link RegexpValidator#getHaveToContains() haveToContains} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for haveToContains * @return A modified copy of the {@code this} object */ public final ImmutableRegexpValidator withHaveToContains(boolean value) { if (this.haveToContains == value) return this; return new ImmutableRegexpValidator(this.validationRegex, this.name, value); }
/** * This instance is equal to all instances of {@code ImmutableRegexpValidator} that have equal attribute values. * @return {@code true} if {@code this} is equal to {@code another} instance */ @Override public boolean equals(@Nullable Object another) { if (this == another) return true; return another instanceof ImmutableRegexpValidator && equalTo((ImmutableRegexpValidator) another); }
/** * Creates an immutable copy of a {@link RegexpValidator} value. * Uses accessors to get values to initialize the new immutable instance. * If an instance is already immutable, it is returned as is. * @param instance The instance to copy * @return A copied immutable RegexpValidator instance */ public static ImmutableRegexpValidator copyOf(RegexpValidator instance) { if (instance instanceof ImmutableRegexpValidator) { return (ImmutableRegexpValidator) instance; } return ImmutableRegexpValidator.builder() .from(instance) .build(); }
public static Validator toValidator(final String leftBrace, final String rightBrace, final MethodCall method) { Preconditions.checkNotNull(method); MethodUtils.getParameterValueWithName(leftBrace, rightBrace, method, "Search").ifPresent(value -> { if ("Headers".equals(value) || "Body".equals(value)) logger.error("The value \"" + value + "\" for the \"Search\" option has not been taken under account for the LR function with name : " + method.getName()); }); MethodUtils.getParameterValueWithName(leftBrace, rightBrace, method, "SaveCount").ifPresent(value -> logger.warn( "The option \"" + value + "\" for the the LR function with name \"" + method.getName() + "\" has not been taken under account")); Optional<String> textPfx = MethodUtils.getParameterStartingWith(method, "TextPfx"); if (textPfx.isPresent()) { String prefix = MethodUtils.getValueAndVerifyRestrictionForBoundary(leftBrace, rightBrace, method, textPfx); String suffix = MethodUtils.getValueAndVerifyRestrictionForBoundary(leftBrace, rightBrace, method, MethodUtils.getParameterStartingWith(method, "TextSfx")); String regex = "\\Q" + prefix + "\\E.*\\Q" + suffix + "\\E"; return ImmutableRegexpValidator.builder().name(method.getName() + "_" + Integer.toString(currentID++)).haveToContains( NOTFOUND.equals(MethodUtils.getParameterValueWithName(leftBrace, rightBrace, method, "Fail").orElse( NOTFOUND))).validationRegex(regex).build(); } String exactMatch = MethodUtils.getValueAndVerifyRestrictionForBoundary(leftBrace, rightBrace, method, MethodUtils.getParameterStartingWith(method, "Text")); return ImmutableTextValidator.builder().name(method.getName() + "_" + Integer.toString(currentID++)).haveToContains(NOTFOUND.equals( MethodUtils.getParameterValueWithName(leftBrace, rightBrace, method, "Fail").orElse(NOTFOUND))).validationText( exactMatch).build(); } }
/** * Copy the current immutable object by setting a value for the {@link RegexpValidator#getValidationRegex() validationRegex} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for validationRegex * @return A modified copy of the {@code this} object */ public final ImmutableRegexpValidator withValidationRegex(String value) { if (this.validationRegex.equals(value)) return this; String newValue = Objects.requireNonNull(value, "validationRegex"); return new ImmutableRegexpValidator(newValue, this.name, this.haveToContains); }
/** * Copy the current immutable object by setting a value for the {@link RegexpValidator#getName() name} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for name * @return A modified copy of the {@code this} object */ public final ImmutableRegexpValidator withName(String value) { if (this.name.equals(value)) return this; String newValue = Objects.requireNonNull(value, "name"); return new ImmutableRegexpValidator(this.validationRegex, newValue, this.haveToContains); }
/** * Builds a new {@link ImmutableRegexpValidator ImmutableRegexpValidator}. * @return An immutable instance of RegexpValidator * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableRegexpValidator build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableRegexpValidator(validationRegex, name, haveToContains); }