
org.scijava.ops.api.OpBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scijava-ops-api Show documentation
Show all versions of scijava-ops-api Show documentation
The public API of SciJava Ops.
The newest version!
/*-
* #%L
* The public API of SciJava Ops.
* %%
* Copyright (C) 2021 - 2024 SciJava developers.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* #L%
*/
/*
* This is autogenerated source code -- DO NOT EDIT. Instead, edit the
* corresponding template in templates/ and rerun bin/generate.groovy.
*/
package org.scijava.ops.api;
import java.lang.reflect.Type;
import java.util.function.BiFunction;
import java.util.function.Function;
import org.scijava.function.Computers;
import org.scijava.function.Functions;
import org.scijava.function.Inplaces;
import org.scijava.function.Producer;
import org.scijava.common3.Any;
import org.scijava.types.Nil;
import org.scijava.common3.Types;
/**
* Convenience class for looking up and/or executing ops using a builder
* pattern. Typical entry point is through {@link OpEnvironment#op(String)},
* which contains full usage information.
*
* Note that the intermediate builder steps use the following acronyms:
*
*
* - IV/OV: Input/Output Value. Indicates instances will be used for matching; ideal if you want to directly run the matched Op, e.g. via
apply
, compute
, mutate
or create
methods.
* - IT/OT: Input/Output Types. Indicates {@code Classes} will be used for matching; matching will produce an Op instance that can then be (re)used. There are two "Type" options: raw types or {@code Nil}s. If you are matching using a parameterized type use the {@code Nil} option to preserve the type parameter.
* - OU: Output Unknown. Indicates an output type/value has not been specified to the builder yet. The output, if any, will simply be an {@code Object}
*
*
* @author Curtis Rueden
* @author Gabriel Selzer
* @author Mark Hiner
*/
public class OpBuilder {
private final OpEnvironment env;
private final String opName;
private Hints hints;
public OpBuilder(final OpEnvironment env, final String opName) {
this(env, opName, env.getDefaultHints());
}
public OpBuilder(final OpEnvironment env, final String opName, final Hints hints) {
this.env = env;
this.opName = opName;
this.hints = hints;
}
/**
* Matches with this builder will use the given pre-allocated output instance.
*
* @see #create() To match then immediately run a Producer Op without specifying its type, creating an Object.
* @see #outType(Class) To specify the output type without providing a concrete instance.
* @see #outType(Nil) To specify the output type, preserving its generic parameters.
* @see #producer() For a reusable Op to create naively-typed Objects without re-matching.
*/
public Arity0_OV output(final O out) {
return new Arity0_OV<>(out);
}
/**
* Matches with this builder will use the indicated output class.
*
* @see #create() To match then immediately run a Producer Op without specifying its type, creating an Object.
* @see #output(Object) To specify a concrete output instance. (e.g. pre-allocated for Computers)
* @see #outType(Nil) To specify the output type, preserving its generic parameters.
* @see #producer() For a reusable Op to create naively-typed Objects without re-matching.
*/
public Arity0_OT outType(final Class outType) {
return outType(Nil.of(outType));
}
/**
* Matches with this builder will use the output type of the indicated {@code Nil}'s generic parameter.
*
* @see #create() To match then immediately run a Producer Op without specifying its type, creating an Object.
* @see #output(Object) To specify a concrete output instance. (e.g. pre-allocated for Computers)
* @see #outType(Class) To specify the output type without providing a concrete instance.
* @see #producer() For a reusable Op to create naively-typed Objects without re-matching.
*/
public Arity0_OT outType(final Nil outType) {
return new Arity0_OT<>(outType);
}
/**
* Match a {@link Producer} op, based on the choices made with this builder, for creating {@code Object} instances.
*
* @return An instance of the matched op, e.g. for reuse.
*
* @throws OpMatchingException if the Op request cannot be satisfied.
*
* @see #create() To match then immediately run a Producer Op without specifying its type, creating an Object.
* @see #output(Object) To specify a concrete output instance. (e.g. pre-allocated for Computers)
* @see #outType(Class) To specify the output type without providing a concrete instance.
* @see #outType(Nil) To specify the output type, preserving its generic parameters.
*/
public Producer> producer() {
final Nil> specialType = new Nil<>() {
@Override
public Type type() {
return Types.parameterize(Producer.class, new Type[] {
Object.class });
}
};
return env.op(opName, specialType, new Nil>[0], Nil.of(
Object.class), OpBuilder.this.hints);
}
/**
* Match then immediately run a type-unsafe {@link Producer} op and get its output.
*
* @return The {@code Object} created by this op
*
* @throws OpMatchingException if the Op request cannot be satisfied.
*
* @see #output(Object) To specify a concrete output instance. (e.g. pre-allocated for Computers)
* @see #outType(Class) To specify the output type without providing a concrete instance.
* @see #outType(Nil) To specify the output type, preserving its generic parameters.
* @see #producer() For a reusable Op to create naively-typed Objects without re-matching.
*/
public Object create() {
return producer().create();
}
/**
* Finds all Ops matching the current partial OpBuilder request
* @return a {@link String} with a simple entry for each Op satisfying the partial request
*/
public String help() {
return env.help(new PartialOpRequest(opName, null));
}
/**
* Finds all Ops matching the current partial OpBuilder request
* @return a {@link String} with a verbose entry for each Op satisfying the partial request
*/
public String helpVerbose() {
return env.helpVerbose(new PartialOpRequest(opName, null));
}
/** Set the Hints instance for this builder */
public void setHints(Hints hints) { this.hints = hints; }
/** Get the Hints instance for this builder */
public Hints hints() { return hints; }
/** Specifies 1 input by value. */
public Arity1_IV_OU input(final I1 in1)
{
return new Arity1_IV_OU<>(in1);
}
/** Specifies 1 input by raw type. */
public Arity1_IT_OU inType(final Class in1Class)
{
return inType(Nil.of(in1Class));
}
/** Specifies 1 input by generic type. */
public Arity1_IT_OU inType(final Nil in1Type)
{
return new Arity1_IT_OU<>(in1Type);
}
/** Specifies 2 input by value. */
public Arity2_IV_OU input(final I1 in1, final I2 in2)
{
return new Arity2_IV_OU<>(in1, in2);
}
/** Specifies 2 input by raw type. */
public Arity2_IT_OU inType(final Class in1Class, final Class in2Class)
{
return inType(Nil.of(in1Class), Nil.of(in2Class));
}
/** Specifies 2 input by generic type. */
public Arity2_IT_OU inType(final Nil in1Type, final Nil in2Type)
{
return new Arity2_IT_OU<>(in1Type, in2Type);
}
/** Specifies 3 input by value. */
public Arity3_IV_OU input(final I1 in1, final I2 in2, final I3 in3)
{
return new Arity3_IV_OU<>(in1, in2, in3);
}
/** Specifies 3 input by raw type. */
public Arity3_IT_OU inType(final Class in1Class, final Class in2Class, final Class in3Class)
{
return inType(Nil.of(in1Class), Nil.of(in2Class), Nil.of(in3Class));
}
/** Specifies 3 input by generic type. */
public Arity3_IT_OU inType(final Nil in1Type, final Nil in2Type, final Nil in3Type)
{
return new Arity3_IT_OU<>(in1Type, in2Type, in3Type);
}
/** Specifies 4 input by value. */
public Arity4_IV_OU input(final I1 in1, final I2 in2, final I3 in3, final I4 in4)
{
return new Arity4_IV_OU<>(in1, in2, in3, in4);
}
/** Specifies 4 input by raw type. */
public Arity4_IT_OU inType(final Class in1Class, final Class in2Class, final Class in3Class, final Class in4Class)
{
return inType(Nil.of(in1Class), Nil.of(in2Class), Nil.of(in3Class), Nil.of(in4Class));
}
/** Specifies 4 input by generic type. */
public Arity4_IT_OU inType(final Nil in1Type, final Nil in2Type, final Nil in3Type, final Nil in4Type)
{
return new Arity4_IT_OU<>(in1Type, in2Type, in3Type, in4Type);
}
/** Specifies 5 input by value. */
public Arity5_IV_OU input(final I1 in1, final I2 in2, final I3 in3, final I4 in4, final I5 in5)
{
return new Arity5_IV_OU<>(in1, in2, in3, in4, in5);
}
/** Specifies 5 input by raw type. */
public Arity5_IT_OU inType(final Class in1Class, final Class in2Class, final Class in3Class, final Class in4Class, final Class in5Class)
{
return inType(Nil.of(in1Class), Nil.of(in2Class), Nil.of(in3Class), Nil.of(in4Class), Nil.of(in5Class));
}
/** Specifies 5 input by generic type. */
public Arity5_IT_OU inType(final Nil in1Type, final Nil in2Type, final Nil in3Type, final Nil in4Type, final Nil in5Type)
{
return new Arity5_IT_OU<>(in1Type, in2Type, in3Type, in4Type, in5Type);
}
/** Specifies 6 input by value. */
public Arity6_IV_OU input(final I1 in1, final I2 in2, final I3 in3, final I4 in4, final I5 in5, final I6 in6)
{
return new Arity6_IV_OU<>(in1, in2, in3, in4, in5, in6);
}
/** Specifies 6 input by raw type. */
public Arity6_IT_OU inType(final Class in1Class, final Class in2Class, final Class in3Class, final Class in4Class, final Class in5Class, final Class in6Class)
{
return inType(Nil.of(in1Class), Nil.of(in2Class), Nil.of(in3Class), Nil.of(in4Class), Nil.of(in5Class), Nil.of(in6Class));
}
/** Specifies 6 input by generic type. */
public Arity6_IT_OU inType(final Nil in1Type, final Nil in2Type, final Nil in3Type, final Nil in4Type, final Nil in5Type, final Nil in6Type)
{
return new Arity6_IT_OU<>(in1Type, in2Type, in3Type, in4Type, in5Type, in6Type);
}
/** Specifies 7 input by value. */
public Arity7_IV_OU input(final I1 in1, final I2 in2, final I3 in3, final I4 in4, final I5 in5, final I6 in6, final I7 in7)
{
return new Arity7_IV_OU<>(in1, in2, in3, in4, in5, in6, in7);
}
/** Specifies 7 input by raw type. */
public Arity7_IT_OU inType(final Class in1Class, final Class in2Class, final Class in3Class, final Class in4Class, final Class in5Class, final Class in6Class, final Class in7Class)
{
return inType(Nil.of(in1Class), Nil.of(in2Class), Nil.of(in3Class), Nil.of(in4Class), Nil.of(in5Class), Nil.of(in6Class), Nil.of(in7Class));
}
/** Specifies 7 input by generic type. */
public Arity7_IT_OU inType(final Nil in1Type, final Nil in2Type, final Nil in3Type, final Nil in4Type, final Nil in5Type, final Nil in6Type, final Nil in7Type)
{
return new Arity7_IT_OU<>(in1Type, in2Type, in3Type, in4Type, in5Type, in6Type, in7Type);
}
/** Specifies 8 input by value. */
public Arity8_IV_OU input(final I1 in1, final I2 in2, final I3 in3, final I4 in4, final I5 in5, final I6 in6, final I7 in7, final I8 in8)
{
return new Arity8_IV_OU<>(in1, in2, in3, in4, in5, in6, in7, in8);
}
/** Specifies 8 input by raw type. */
public Arity8_IT_OU inType(final Class in1Class, final Class in2Class, final Class in3Class, final Class in4Class, final Class in5Class, final Class in6Class, final Class in7Class, final Class in8Class)
{
return inType(Nil.of(in1Class), Nil.of(in2Class), Nil.of(in3Class), Nil.of(in4Class), Nil.of(in5Class), Nil.of(in6Class), Nil.of(in7Class), Nil.of(in8Class));
}
/** Specifies 8 input by generic type. */
public Arity8_IT_OU inType(final Nil in1Type, final Nil in2Type, final Nil in3Type, final Nil in4Type, final Nil in5Type, final Nil in6Type, final Nil in7Type, final Nil in8Type)
{
return new Arity8_IT_OU<>(in1Type, in2Type, in3Type, in4Type, in5Type, in6Type, in7Type, in8Type);
}
/** Specifies 9 input by value. */
public Arity9_IV_OU input(final I1 in1, final I2 in2, final I3 in3, final I4 in4, final I5 in5, final I6 in6, final I7 in7, final I8 in8, final I9 in9)
{
return new Arity9_IV_OU<>(in1, in2, in3, in4, in5, in6, in7, in8, in9);
}
/** Specifies 9 input by raw type. */
public Arity9_IT_OU inType(final Class in1Class, final Class in2Class, final Class in3Class, final Class in4Class, final Class in5Class, final Class in6Class, final Class in7Class, final Class in8Class, final Class in9Class)
{
return inType(Nil.of(in1Class), Nil.of(in2Class), Nil.of(in3Class), Nil.of(in4Class), Nil.of(in5Class), Nil.of(in6Class), Nil.of(in7Class), Nil.of(in8Class), Nil.of(in9Class));
}
/** Specifies 9 input by generic type. */
public Arity9_IT_OU inType(final Nil in1Type, final Nil in2Type, final Nil in3Type, final Nil in4Type, final Nil in5Type, final Nil in6Type, final Nil in7Type, final Nil in8Type, final Nil in9Type)
{
return new Arity9_IT_OU<>(in1Type, in2Type, in3Type, in4Type, in5Type, in6Type, in7Type, in8Type, in9Type);
}
/** Specifies 10 input by value. */
public Arity10_IV_OU input(final I1 in1, final I2 in2, final I3 in3, final I4 in4, final I5 in5, final I6 in6, final I7 in7, final I8 in8, final I9 in9, final I10 in10)
{
return new Arity10_IV_OU<>(in1, in2, in3, in4, in5, in6, in7, in8, in9, in10);
}
/** Specifies 10 input by raw type. */
public Arity10_IT_OU inType(final Class in1Class, final Class in2Class, final Class in3Class, final Class in4Class, final Class in5Class, final Class in6Class, final Class in7Class, final Class in8Class, final Class in9Class, final Class in10Class)
{
return inType(Nil.of(in1Class), Nil.of(in2Class), Nil.of(in3Class), Nil.of(in4Class), Nil.of(in5Class), Nil.of(in6Class), Nil.of(in7Class), Nil.of(in8Class), Nil.of(in9Class), Nil.of(in10Class));
}
/** Specifies 10 input by generic type. */
public Arity10_IT_OU inType(final Nil in1Type, final Nil in2Type, final Nil in3Type, final Nil in4Type, final Nil in5Type, final Nil in6Type, final Nil in7Type, final Nil in8Type, final Nil in9Type, final Nil in10Type)
{
return new Arity10_IT_OU<>(in1Type, in2Type, in3Type, in4Type, in5Type, in6Type, in7Type, in8Type, in9Type, in10Type);
}
/** Specifies 11 input by value. */
public Arity11_IV_OU input(final I1 in1, final I2 in2, final I3 in3, final I4 in4, final I5 in5, final I6 in6, final I7 in7, final I8 in8, final I9 in9, final I10 in10, final I11 in11)
{
return new Arity11_IV_OU<>(in1, in2, in3, in4, in5, in6, in7, in8, in9, in10, in11);
}
/** Specifies 11 input by raw type. */
public Arity11_IT_OU inType(final Class in1Class, final Class in2Class, final Class in3Class, final Class in4Class, final Class in5Class, final Class in6Class, final Class in7Class, final Class in8Class, final Class in9Class, final Class in10Class, final Class in11Class)
{
return inType(Nil.of(in1Class), Nil.of(in2Class), Nil.of(in3Class), Nil.of(in4Class), Nil.of(in5Class), Nil.of(in6Class), Nil.of(in7Class), Nil.of(in8Class), Nil.of(in9Class), Nil.of(in10Class), Nil.of(in11Class));
}
/** Specifies 11 input by generic type. */
public Arity11_IT_OU inType(final Nil in1Type, final Nil in2Type, final Nil in3Type, final Nil in4Type, final Nil in5Type, final Nil in6Type, final Nil in7Type, final Nil in8Type, final Nil in9Type, final Nil in10Type, final Nil in11Type)
{
return new Arity11_IT_OU<>(in1Type, in2Type, in3Type, in4Type, in5Type, in6Type, in7Type, in8Type, in9Type, in10Type, in11Type);
}
/** Specifies 12 input by value. */
public Arity12_IV_OU input(final I1 in1, final I2 in2, final I3 in3, final I4 in4, final I5 in5, final I6 in6, final I7 in7, final I8 in8, final I9 in9, final I10 in10, final I11 in11, final I12 in12)
{
return new Arity12_IV_OU<>(in1, in2, in3, in4, in5, in6, in7, in8, in9, in10, in11, in12);
}
/** Specifies 12 input by raw type. */
public Arity12_IT_OU inType(final Class in1Class, final Class in2Class, final Class in3Class, final Class in4Class, final Class in5Class, final Class in6Class, final Class in7Class, final Class in8Class, final Class in9Class, final Class in10Class, final Class in11Class, final Class in12Class)
{
return inType(Nil.of(in1Class), Nil.of(in2Class), Nil.of(in3Class), Nil.of(in4Class), Nil.of(in5Class), Nil.of(in6Class), Nil.of(in7Class), Nil.of(in8Class), Nil.of(in9Class), Nil.of(in10Class), Nil.of(in11Class), Nil.of(in12Class));
}
/** Specifies 12 input by generic type. */
public Arity12_IT_OU inType(final Nil in1Type, final Nil in2Type, final Nil in3Type, final Nil in4Type, final Nil in5Type, final Nil in6Type, final Nil in7Type, final Nil in8Type, final Nil in9Type, final Nil in10Type, final Nil in11Type, final Nil in12Type)
{
return new Arity12_IT_OU<>(in1Type, in2Type, in3Type, in4Type, in5Type, in6Type, in7Type, in8Type, in9Type, in10Type, in11Type, in12Type);
}
/** Specifies 13 input by value. */
public Arity13_IV_OU input(final I1 in1, final I2 in2, final I3 in3, final I4 in4, final I5 in5, final I6 in6, final I7 in7, final I8 in8, final I9 in9, final I10 in10, final I11 in11, final I12 in12, final I13 in13)
{
return new Arity13_IV_OU<>(in1, in2, in3, in4, in5, in6, in7, in8, in9, in10, in11, in12, in13);
}
/** Specifies 13 input by raw type. */
public Arity13_IT_OU inType(final Class in1Class, final Class in2Class, final Class in3Class, final Class in4Class, final Class in5Class, final Class in6Class, final Class in7Class, final Class in8Class, final Class in9Class, final Class