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

com.github.dakusui.crest.functions.TransformingPredicate Maven / Gradle / Ivy

package com.github.dakusui.crest.functions;

import java.util.function.Function;
import java.util.function.Predicate;

public class TransformingPredicate implements Predicate {
  private final Predicate             predicate;
  private final Function function;
  private final String                           name;

  public TransformingPredicate(Predicate predicate, Function function) {
    this(null, predicate, function);
  }

  public TransformingPredicate(String name, Predicate predicate, Function function) {
    this.predicate = predicate;
    this.function = function;
    this.name = name;
  }

  @Override
  public boolean test(O v) {
    ////
    // This method is usually not called. Because Assertion class invokes function
    // and predicate of this object by itself and do not use this method.
    return predicate.test(function.apply(v));
  }

  public Predicate predicate() {
    return this.predicate;
  }

  public Function function() {
    return this.function;
  }

  @Override
  public String toString() {
    return String.format("%s%s %s", this.name == null ? "" : this.name, function(), predicate());
  }
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy