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

com.github.dakusui.printables.Printables Maven / Gradle / Ivy

There is a newer version: 6.0.1
Show newest version
package com.github.dakusui.printables;

import java.util.Map;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;

import static com.github.dakusui.actionunit.utils.InternalUtils.summary;

public enum Printables {
  ;

  public static Predicate isEmptyString() {
    return printablePredicate(String::isEmpty).describe("isEmptyString");
  }

  public static  PrintablePredicate.Builder printablePredicate(Predicate predicate) {
    return new PrintablePredicate.Builder<>(predicate);
  }

  public static  PrintableConsumer.Builder printableConsumer(Consumer consumer) {
    return new PrintableConsumer.Builder<>(consumer);
  }

  public static  PrintableFunction.Builder printableFunction(Function function) {
    return new PrintableFunction.Builder<>(function);
  }

  public static  Predicate isKeyOf(Map values) {
    return printablePredicate((Predicate) values::containsKey)
        .describe(() -> String.format("isKeyOf[%s]", summary(values.toString())));
  }

  public static  Predicate isEqualTo(T value) {
    return printablePredicate((Predicate) v -> Objects.equals(v, value))
        .describe(() -> String.format("is[%s]", value));
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy