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

com.codepoetics.fluvius.flows.SourceTargetCapture2 Maven / Gradle / Ivy

There is a newer version: 1.10
Show newest version
package com.codepoetics.fluvius.flows;

import com.codepoetics.fluvius.api.Flow;
import com.codepoetics.fluvius.api.functional.DoubleParameterStep;
import com.codepoetics.fluvius.api.scratchpad.Key;

/**
 * The stage in the fluent API where we have captured the target key and two source keys of a Flow.
 *
 * @param       The type of the first source key.
 * @param       The type of the second source key.
 * @param  The type of the target key.
 */
public final class SourceTargetCapture2 {
  private final Key sourceA;
  private final Key sourceB;
  private final Key target;

  SourceTargetCapture2(Key sourceA, Key sourceB, Key target) {
    this.sourceA = sourceA;
    this.sourceB = sourceB;
    this.target = target;
  }

  /**
   * Create a Flow from the source keys to the target key, using the given name and function.
   *
   * @param name The name of the Flow.
   * @param doubleParameterStep   The function to use to transform the source values to the target value.
   * @return The constructed Flow.
   */
  public Flow using(String name, DoubleParameterStep doubleParameterStep) {
    return Fluent.inputKeysCapture(sourceA, sourceB).to(target).using(
        name,
        Extractors.make(sourceA, sourceB, doubleParameterStep));
  }

  /**
   * Create a Flow from the source keys to the target key, using the given function.
   * The flow is automatically named based on the key names.
   *
   * @param doubleParameterStep The function to use to transform the source values to the target value.
   * @return The constructed Flow.
   */
  public Flow using(DoubleParameterStep doubleParameterStep) {
    return using("Obtain " + target.getName()
            + " from " + sourceA.getName()
            + " and " + sourceB.getName(),
        doubleParameterStep);
  }
}