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

com.github.hakenadu.javalangchains.chains.ChainLink Maven / Gradle / Ivy

package com.github.hakenadu.javalangchains.chains;

/**
 * A Link Between Worlds ;-)
 *
 * @param  type of the input chain's input
 * @param  type of the input chain's output and the output chain's input
 * @param  type of the output chain's output
 */
public final class ChainLink implements Chain {

	private final Chain inputChain;
	private final Chain outputChain;

	/**
	 * @param inputChain  {@link #inputChain}
	 * @param outputChain {@link #outputChain}
	 */
	ChainLink(final Chain inputChain, final Chain outputChain) {
		this.inputChain = inputChain;
		this.outputChain = outputChain;
	}

	@Override
	public O run(final I input) {
		final M intermediateOutput = inputChain.run(input);

		final O output = outputChain.run(intermediateOutput);

		return output;
	}

	/**
	 * @return true if this {@link ChainLink} is the first one of the whole chain
	 */
	public boolean isHead() {
		return !(inputChain instanceof ChainLink);
	}

	/**
	 * @return true if this {@link ChainLink} is the final one of the whole chain
	 */
	public boolean isTail() {
		return !(outputChain instanceof ChainLink);
	}

	/**
	 * @return {@link #inputChain}
	 */
	public Chain getInputChain() {
		return inputChain;
	}

	/**
	 * @return {@link #outputChain}
	 */
	public Chain getOutputChain() {
		return outputChain;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy