| 1 | package net.bmahe.genetics4j.core.spec.mutation; | |
| 2 | ||
| 3 | import java.util.Objects; | |
| 4 | ||
| 5 | import org.apache.commons.lang3.Validate; | |
| 6 | import org.immutables.value.Value; | |
| 7 | ||
| 8 | /** | |
| 9 | * Applies another mutation policy repeatedly. | |
| 10 | * | |
| 11 | * <p>The number of repetitions is selected uniformly between {@link #minRepetitions()} and | |
| 12 | * {@link #maxRepetitions()}, inclusive, for each genotype. Equal bounds define a fixed number of repetitions. | |
| 13 | */ | |
| 14 | @Value.Immutable | |
| 15 | public abstract class RepeatedMutation implements MutationPolicy { | |
| 16 | ||
| 17 | @Value.Parameter | |
| 18 | public abstract int minRepetitions(); | |
| 19 | ||
| 20 | @Value.Parameter | |
| 21 | public abstract int maxRepetitions(); | |
| 22 | ||
| 23 | @Value.Parameter | |
| 24 | public abstract MutationPolicy mutationPolicy(); | |
| 25 | ||
| 26 | @Value.Check | |
| 27 | protected void check() { | |
| 28 | Validate.isTrue(minRepetitions() > 0); | |
| 29 | Validate.isTrue(maxRepetitions() >= minRepetitions()); | |
| 30 | Objects.requireNonNull(mutationPolicy()); | |
| 31 | } | |
| 32 | ||
| 33 | public static class Builder extends ImmutableRepeatedMutation.Builder { | |
| 34 | } | |
| 35 | ||
| 36 | public static Builder builder() { | |
| 37 |
2
1. builder : removed call to net/bmahe/genetics4j/core/spec/mutation/RepeatedMutation$Builder::<init> → KILLED 2. builder : replaced return value with null for net/bmahe/genetics4j/core/spec/mutation/RepeatedMutation::builder → KILLED |
return new Builder(); |
| 38 | } | |
| 39 | ||
| 40 | /** | |
| 41 | * Creates a mutation policy with a fixed number of repetitions. | |
| 42 | * | |
| 43 | * @param repetitions number of times to apply the mutation policy | |
| 44 | * @param mutationPolicy mutation policy to repeat | |
| 45 | * @return a repeated mutation policy | |
| 46 | */ | |
| 47 | public static RepeatedMutation ofExactly(final int repetitions, final MutationPolicy mutationPolicy) { | |
| 48 |
2
1. ofExactly : removed call to net/bmahe/genetics4j/core/spec/mutation/ImmutableRepeatedMutation::of → KILLED 2. ofExactly : replaced return value with null for net/bmahe/genetics4j/core/spec/mutation/RepeatedMutation::ofExactly → KILLED |
return ImmutableRepeatedMutation.of(repetitions, repetitions, mutationPolicy); |
| 49 | } | |
| 50 | ||
| 51 | /** | |
| 52 | * Creates a mutation policy with a number of repetitions selected uniformly between one and the specified maximum, | |
| 53 | * inclusive. | |
| 54 | * | |
| 55 | * @param maxRepetitions maximum number of repetitions, inclusive | |
| 56 | * @param mutationPolicy mutation policy to repeat | |
| 57 | * @return a repeated mutation policy | |
| 58 | */ | |
| 59 | public static RepeatedMutation ofUpTo(final int maxRepetitions, final MutationPolicy mutationPolicy) { | |
| 60 |
3
1. ofUpTo : Substituted 1 with 0 → KILLED 2. ofUpTo : replaced return value with null for net/bmahe/genetics4j/core/spec/mutation/RepeatedMutation::ofUpTo → KILLED 3. ofUpTo : removed call to net/bmahe/genetics4j/core/spec/mutation/ImmutableRepeatedMutation::of → KILLED |
return ImmutableRepeatedMutation.of(1, maxRepetitions, mutationPolicy); |
| 61 | } | |
| 62 | ||
| 63 | /** | |
| 64 | * Creates a mutation policy with a variable number of repetitions. | |
| 65 | * | |
| 66 | * @param minRepetitions minimum number of repetitions, inclusive | |
| 67 | * @param maxRepetitions maximum number of repetitions, inclusive | |
| 68 | * @param mutationPolicy mutation policy to repeat | |
| 69 | * @return a repeated mutation policy | |
| 70 | */ | |
| 71 | public static RepeatedMutation of(final int minRepetitions, final int maxRepetitions, | |
| 72 | final MutationPolicy mutationPolicy) { | |
| 73 |
2
1. of : replaced return value with null for net/bmahe/genetics4j/core/spec/mutation/RepeatedMutation::of → KILLED 2. of : removed call to net/bmahe/genetics4j/core/spec/mutation/ImmutableRepeatedMutation::of → KILLED |
return ImmutableRepeatedMutation.of(minRepetitions, maxRepetitions, mutationPolicy); |
| 74 | } | |
| 75 | } | |
Mutations | ||
| 37 |
1.1 2.2 |
|
| 48 |
1.1 2.2 |
|
| 60 |
1.1 2.2 3.3 |
|
| 73 |
1.1 2.2 |