1 package net.bmahe.genetics4j.gp.spec.mutation;
2
3 import java.util.Optional;
4
5 import org.apache.commons.lang3.Validate;
6 import org.immutables.value.Value;
7
8 import net.bmahe.genetics4j.core.spec.mutation.MutationPolicy;
9
10
11
12
13
14
15
16
17 @Value.Immutable
18 public interface TrimTree extends MutationPolicy {
19
20
21
22
23
24
25 @Value.Parameter
26 @Value.Default
27 public default Optional<Integer> maxDepth() {
28 return Optional.empty();
29 }
30
31 @Value.Check
32 default void check() {
33 maxDepth().ifPresent(maxDepth -> Validate.isTrue(maxDepth > 0));
34 }
35
36
37
38
39
40
41
42 public static TrimTree of(final int maxDepth) {
43 return ImmutableTrimTree.of(Optional.of(maxDepth));
44 }
45
46
47
48
49
50
51 public static TrimTree build() {
52 return ImmutableTrimTree.builder().build();
53 }
54 }