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

com.github.dakusui.crest.utils.printable.PrintablePredicate Maven / Gradle / Ivy

package com.github.dakusui.crest.utils.printable;

import java.util.function.Predicate;

import static java.util.Objects.requireNonNull;

class PrintablePredicate implements Predicate {
  private final String       s;
  private final Predicate predicate;

  PrintablePredicate(String s, Predicate predicate) {
    this.s = s;
    this.predicate = predicate;
  }

  @Override
  public boolean test(T t) {
    return predicate.test(t);
  }

  @Override
  public Predicate and(Predicate other) {
    requireNonNull(other);
    return new PrintablePredicate(String.format("(%s&&%s)", s, other), predicate.and(other));
  }

  @Override
  public Predicate negate() {
    return new PrintablePredicate(String.format("!%s", s), predicate.negate());
  }

  @Override
  public Predicate or(Predicate other) {
    requireNonNull(other);
    return new PrintablePredicate(String.format("(%s||%s)", s, other), predicate.or(other));
  }

  @Override
  public String toString() {
    return s;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy