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.Optional;
import java.util.function.Function;
import java.util.function.Predicate;

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

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

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

  @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;
  }

  public Optional name() {
    return name != null ?
        Optional.of(this.name) :
        Optional.empty();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy