View Javadoc
1   package net.bmahe.genetics4j.gp.spec.mutation;
2   
3   import java.util.function.BiFunction;
4   import java.util.function.Predicate;
5   
6   import org.apache.commons.lang3.Validate;
7   import org.immutables.value.Value;
8   
9   import net.bmahe.genetics4j.core.chromosomes.TreeNode;
10  import net.bmahe.genetics4j.gp.Operation;
11  import net.bmahe.genetics4j.gp.program.Program;
12  
13  @Value.Immutable
14  public interface Rule {
15  
16  	@Value.Parameter
17  	Predicate<TreeNode<Operation<?>>> predicate();
18  
19  	@Value.Parameter
20  	BiFunction<Program, TreeNode<Operation<?>>, TreeNode<Operation<?>>> applicator();
21  
22  	default boolean test(final TreeNode<Operation<?>> root) {
23  		Validate.notNull(root);
24  
25  		return predicate().test(root);
26  	}
27  
28  	default TreeNode<Operation<?>> apply(final Program program, final TreeNode<Operation<?>> root) {
29  		Validate.notNull(program);
30  		Validate.notNull(root);
31  
32  		return applicator().apply(program, root);
33  	}
34  }