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 @Value.Immutable
16 public interface TrimTree extends MutationPolicy {
17
18
19
20
21
22
23 @Value.Parameter
24 @Value.Default
25 public default Optional<Integer> maxDepth() {
26 return Optional.empty();
27 }
28
29 @Value.Check
30 default void check() {
31 maxDepth().ifPresent(maxDepth -> Validate.isTrue(maxDepth > 0));
32 }
33
34
35
36
37
38
39
40 public static TrimTree of(final int maxDepth) {
41 return ImmutableTrimTree.of(Optional.of(maxDepth));
42 }
43
44
45
46
47
48
49 public static TrimTree build() {
50 return ImmutableTrimTree.builder()
51 .build();
52 }
53 }