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

com.github.dakusui.actionunit.actions.Leaf Maven / Gradle / Ivy

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

import com.github.dakusui.actionunit.core.Action;
import com.github.dakusui.actionunit.core.Context;
import com.github.dakusui.actionunit.core.ContextConsumer;

import java.util.Formatter;
import java.util.function.Function;

import static java.util.Objects.requireNonNull;

public interface Leaf extends Action, Function {
  Runnable runnable(Context context);

  default Runnable apply(Context context) {
    return runnable(context);
  }

  default void accept(Visitor visitor) {
    visitor.visit(this);
  }

  static Leaf of(ContextConsumer consumer) {
    requireNonNull(consumer);
    return new Leaf() {
      @Override
      public Runnable runnable(Context context) {
        return () -> consumer.accept(context);
      }

      @Override
      public void formatTo(Formatter formatter, int flags, int width, int precision) {
        formatter.format("%s", consumer);
      }
    };
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy