1 | package net.bmahe.genetics4j.core.mutation; | |
2 | ||
3 | import java.util.Arrays; | |
4 | ||
5 | import org.apache.commons.lang3.Validate; | |
6 | ||
7 | import net.bmahe.genetics4j.core.Genotype; | |
8 | import net.bmahe.genetics4j.core.chromosomes.Chromosome; | |
9 | import net.bmahe.genetics4j.core.spec.AbstractEAConfiguration; | |
10 | import net.bmahe.genetics4j.core.spec.AbstractEAExecutionContext; | |
11 | import net.bmahe.genetics4j.core.spec.mutation.MutationPolicy; | |
12 | import net.bmahe.genetics4j.core.spec.mutation.PartialMutation; | |
13 | ||
14 | public class PartialMutationPolicyHandler<T extends Comparable<T>> implements MutationPolicyHandler<T> { | |
15 | ||
16 | @Override | |
17 | public boolean canHandle(final MutationPolicyHandlerResolver<T> mutationPolicyHandlerResolver, | |
18 | final MutationPolicy mutationPolicy) { | |
19 | Validate.notNull(mutationPolicyHandlerResolver); | |
20 | Validate.notNull(mutationPolicy); | |
21 | ||
22 |
3
1. canHandle : negated conditional → NO_COVERAGE 2. canHandle : removed conditional - replaced equality check with true → NO_COVERAGE 3. canHandle : removed conditional - replaced equality check with false → NO_COVERAGE |
if (mutationPolicy instanceof PartialMutation == false) { |
23 |
2
1. canHandle : replaced boolean return with true for net/bmahe/genetics4j/core/mutation/PartialMutationPolicyHandler::canHandle → NO_COVERAGE 2. canHandle : Substituted 0 with 1 → NO_COVERAGE |
return false; |
24 | } | |
25 | ||
26 | final PartialMutation partialMutation = (PartialMutation) mutationPolicy; | |
27 | ||
28 |
1
1. canHandle : removed call to net/bmahe/genetics4j/core/spec/mutation/PartialMutation::mutationPolicy → NO_COVERAGE |
final MutationPolicy childMutationPolicy = partialMutation.mutationPolicy(); |
29 |
3
1. canHandle : removed call to net/bmahe/genetics4j/core/mutation/MutationPolicyHandlerResolver::canHandle → NO_COVERAGE 2. canHandle : replaced boolean return with false for net/bmahe/genetics4j/core/mutation/PartialMutationPolicyHandler::canHandle → NO_COVERAGE 3. canHandle : replaced boolean return with true for net/bmahe/genetics4j/core/mutation/PartialMutationPolicyHandler::canHandle → NO_COVERAGE |
return mutationPolicyHandlerResolver.canHandle(childMutationPolicy); |
30 | } | |
31 | ||
32 | @Override | |
33 | public Mutator createMutator(final AbstractEAExecutionContext<T> eaExecutionContext, | |
34 | final AbstractEAConfiguration<T> eaConfiguration, | |
35 | final MutationPolicyHandlerResolver<T> mutationPolicyHandlerResolver, final MutationPolicy mutationPolicy) { | |
36 | Validate.notNull(eaExecutionContext); | |
37 | Validate.notNull(eaConfiguration); | |
38 | Validate.notNull(mutationPolicyHandlerResolver); | |
39 | Validate.notNull(mutationPolicy); | |
40 | Validate.isInstanceOf(PartialMutation.class, mutationPolicy); | |
41 | ||
42 | final PartialMutation partialMutation = (PartialMutation) mutationPolicy; | |
43 | ||
44 |
1
1. createMutator : removed call to net/bmahe/genetics4j/core/spec/mutation/PartialMutation::chromosomeIndex → NO_COVERAGE |
final int mutatedChromosomeIndex = partialMutation.chromosomeIndex(); |
45 |
1
1. createMutator : removed call to net/bmahe/genetics4j/core/spec/mutation/PartialMutation::mutationPolicy → NO_COVERAGE |
final MutationPolicy childMutationPolicy = partialMutation.mutationPolicy(); |
46 |
1
1. createMutator : removed call to net/bmahe/genetics4j/core/mutation/MutationPolicyHandlerResolver::resolve → NO_COVERAGE |
final MutationPolicyHandler<T> mutationPolicyHandler = mutationPolicyHandlerResolver.resolve(childMutationPolicy); |
47 | ||
48 | final Mutator childMutator = mutationPolicyHandler | |
49 |
1
1. createMutator : removed call to net/bmahe/genetics4j/core/mutation/MutationPolicyHandler::createMutator → NO_COVERAGE |
.createMutator(eaExecutionContext, eaConfiguration, mutationPolicyHandlerResolver, childMutationPolicy); |
50 | ||
51 |
4
1. createMutator : removed call to net/bmahe/genetics4j/core/mutation/PartialMutationPolicyHandler$1::<init> → NO_COVERAGE 2. <init> : Removed assignment to member variable val$childMutator → NO_COVERAGE 3. createMutator : replaced return value with null for net/bmahe/genetics4j/core/mutation/PartialMutationPolicyHandler::createMutator → NO_COVERAGE 4. <init> : Removed assignment to member variable val$mutatedChromosomeIndex → NO_COVERAGE |
return new Mutator() { |
52 | ||
53 | @Override | |
54 | public Genotype mutate(final Genotype original) { | |
55 | Validate.notNull(original); | |
56 | ||
57 |
4
1. mutate : replaced call to java/util/Arrays::copyOf with argument → NO_COVERAGE 2. mutate : removed call to java/util/Arrays::copyOf → NO_COVERAGE 3. mutate : removed call to net/bmahe/genetics4j/core/Genotype::getChromosomes → NO_COVERAGE 4. mutate : removed call to net/bmahe/genetics4j/core/Genotype::getChromosomes → NO_COVERAGE |
final Chromosome[] chromosomes = Arrays.copyOf(original.getChromosomes(), original.getChromosomes().length); |
58 |
2
1. mutate : replaced call to net/bmahe/genetics4j/core/mutation/Mutator::mutate with argument → NO_COVERAGE 2. mutate : removed call to net/bmahe/genetics4j/core/mutation/Mutator::mutate → NO_COVERAGE |
final Genotype mutated = childMutator.mutate(original); |
59 | ||
60 |
1
1. mutate : removed call to net/bmahe/genetics4j/core/Genotype::getChromosome → NO_COVERAGE |
chromosomes[mutatedChromosomeIndex] = mutated.getChromosome(mutatedChromosomeIndex); |
61 | ||
62 |
2
1. mutate : replaced return value with null for net/bmahe/genetics4j/core/mutation/PartialMutationPolicyHandler$1::mutate → NO_COVERAGE 2. mutate : removed call to net/bmahe/genetics4j/core/Genotype::<init> → NO_COVERAGE |
return new Genotype(chromosomes); |
63 | } | |
64 | }; | |
65 | } | |
66 | } | |
Mutations | ||
22 |
1.1 2.2 3.3 |
|
23 |
1.1 2.2 |
|
28 |
1.1 |
|
29 |
1.1 2.2 3.3 |
|
44 |
1.1 |
|
45 |
1.1 |
|
46 |
1.1 |
|
49 |
1.1 |
|
51 |
1.1 2.2 3.3 4.4 |
|
57 |
1.1 2.2 3.3 4.4 |
|
58 |
1.1 2.2 |
|
60 |
1.1 |
|
62 |
1.1 2.2 |