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

com.github.dakusui.crest.core.Call Maven / Gradle / Ivy

package com.github.dakusui.crest.core;

import com.github.dakusui.faultsource.printable.Functions;

import java.util.function.Function;

import static java.util.Objects.requireNonNull;

public interface Call {
  Call andThen(String methodName, Object... args);

   Function $();

  static Call create(String methodName, Object... args) {
    return new Call.Impl(null, methodName, args);
  }

  class Impl implements Call {
    private final String   methodName;
    private final Object[] args;
    private final Call     parent;

    Impl(Call parent, String methodName, Object... args) {
      this.parent = parent;
      this.methodName = requireNonNull(methodName);
      this.args = args;
    }

    @Override
    public Call andThen(String methodName, Object... args) {
      return new Impl(this, methodName, args);
    }

    @SuppressWarnings("unchecked")
    @Override
    public  Function $() {
      return this.parent == null ?
          Function.class.cast(Functions.invoke(methodName, args)) :
          this.parent.$().andThen(Function.class.cast(Functions.invoke(methodName, args)));
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy