Package io.jenetics.prog.op
Interface Op<T>
-
- Type Parameters:
T- the argument type of the operation
public interface Op<T> extends Function<T[],T>, Supplier<Op<T>>
Operation interface. An operation is a function which maps some argument type with a given arity to a result object of the same type:T[] -> T.Implementations of thefinal Op<Double> add = Op.of("add", 2, v -> v[0] + v[1]); final Op<Double> add3 = Op.of("add3", 3, v -> v[0] + v[1] + v[2]); final Op<Double> sub = Op.of("sub", 2, v -> v[0] - v[1]); final Op<Double> sin = Op.of("sin", 1, v -> Math.sin(v[0]));Opinterface are usually immutable and doesn't maintain internal state. But some instance are ephemeral with changing state. This classes must override theget()method inherited from theSupplierinterface and return a new instance.- Since:
- 3.9
- Version:
- 3.9
- Author:
- Franz Wilhelmstötter
- See Also:
Var,Const,EphemeralConst
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description intarity()Return the arity of the operation function.default Op<T>get()Returnthisoperation, or a new instance from the same type, if the operation needs to maintain internal state.default booleanisTerminal()Determines if the operation is a terminal operation.Stringname()Return the name of the operation.static <T> Op<T>of(String name, int arity, Function<T[],T> function)Create a new operation from the given parameter.static <T> Op<T>of(String name, BinaryOperator<T> function)Create a new operation with the given name and binary operation.static <T> Op<T>of(String name, UnaryOperator<T> function)Create a new operation with the given name and unary operation.
-
-
-
Method Detail
-
arity
int arity()
Return the arity of the operation function. If the arity is zero, the operation is terminal operation.- Returns:
- the arity of the operation
-
isTerminal
default boolean isTerminal()
Determines if the operation is a terminal operation.- Returns:
trueif the operation is a terminal operation,falseotherwise
-
get
default Op<T> get()
Returnthisoperation, or a new instance from the same type, if the operation needs to maintain internal state. This is essentially the case for ephemeral constants.- Specified by:
getin interfaceSupplier<T>- Returns:
thisoperation, or a new instance- See Also:
EphemeralConst
-
of
static <T> Op<T> of(String name, int arity, Function<T[],T> function)
Create a new operation from the given parameter.- Type Parameters:
T- the operation type- Parameters:
name- the operation namearity- the arity of the operationfunction- the function executed by the operation. In order to work properly, the given function should be stateless and must not have side effects.- Returns:
- a new operation from the given parameter
- Throws:
NullPointerException- if the givennameorfunctionisnullIllegalArgumentException- if the givenarityis smaller than zero
-
of
static <T> Op<T> of(String name, UnaryOperator<T> function)
Create a new operation with the given name and unary operation. The returnedOpwill have arity one.- Type Parameters:
T- the operation type- Parameters:
name- the name of the returned operationfunction- the used function of the operation- Returns:
- a new operation with the given name and unary operation
- Throws:
NullPointerException- if the givennameorfunctionisnull- Since:
- 4.0
-
of
static <T> Op<T> of(String name, BinaryOperator<T> function)
Create a new operation with the given name and binary operation. The returnedOpwill have arity two.- Type Parameters:
T- the operation type- Parameters:
name- the name of the returned operationfunction- the used function of the operation- Returns:
- a new operation with the given name and unary operation
- Throws:
NullPointerException- if the givennameorfunctionisnull- Since:
- 4.0
-
-