1 package net.bmahe.genetics4j.gp; 2 3 import java.util.List; 4 import java.util.function.BiFunction; 5 6 import org.immutables.value.Value; 7 import org.immutables.value.Value.Parameter; 8 9 @Value.Immutable 10 public abstract class Operation<T> { 11 12 @Parameter 13 public abstract String getName(); 14 15 @SuppressWarnings("rawtypes") 16 @Parameter 17 public abstract List<Class> acceptedTypes(); 18 19 @SuppressWarnings("rawtypes") 20 @Parameter 21 public abstract Class returnedType(); 22 23 @Parameter 24 @Value.Auxiliary 25 public abstract BiFunction<T[], Object[], Object> compute(); 26 27 @Value.Default 28 public String getPrettyName() { 29 return getName(); 30 } 31 32 public Object apply(final T[] input, final Object[] parameters) { 33 final BiFunction<T[], Object[], Object> function = compute(); 34 return function.apply(input, parameters); 35 } 36 37 public int getArity() { 38 return acceptedTypes().size(); 39 } 40 41 public boolean isTerminal() { 42 return getArity() == 0; 43 } 44 }