All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.compilit.validation.RuleDefinitionBuilder Maven / Gradle / Ivy

package com.compilit.validation;

import com.compilit.validation.api.Rule;
import com.compilit.validation.api.RuleBuilder;
import java.util.function.BiPredicate;
import java.util.function.Predicate;

final class RuleDefinitionBuilder implements RuleBuilder {

  private final Predicate predicate;

  RuleDefinitionBuilder(final Predicate predicate) {
    this.predicate = predicate;
  }

  @Override
  public Rule otherwiseReport(final String message, final Object... formatArguments) {
    final var actualMessage = String.format(message, formatArguments);
    return new RuleDefinition<>(predicate, actualMessage);
  }

  static final class WithDualInput implements RuleBuilder.WithDualInput {

    private final BiPredicate predicate;

    WithDualInput(final BiPredicate predicate) {
      this.predicate = predicate;
    }

    @Override
    public Rule.WithDualInput otherwiseReport(final String message, final Object... formatArguments) {
      final var actualMessage = String.format(message, formatArguments);
      return new RuleDefinition.WithDualInput<>(predicate, actualMessage);
    }

  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy