MultiMutationsPolicyHandler.java

1
package net.bmahe.genetics4j.core.mutation;
2
3
import java.util.List;
4
import java.util.Objects;
5
import java.util.random.RandomGenerator;
6
import java.util.stream.Collectors;
7
8
import org.apache.commons.lang3.Validate;
9
10
import net.bmahe.genetics4j.core.Genotype;
11
import net.bmahe.genetics4j.core.spec.AbstractEAConfiguration;
12
import net.bmahe.genetics4j.core.spec.AbstractEAExecutionContext;
13
import net.bmahe.genetics4j.core.spec.mutation.MultiMutations;
14
import net.bmahe.genetics4j.core.spec.mutation.MutationPolicy;
15
16
public class MultiMutationsPolicyHandler<T extends Comparable<T>> implements MutationPolicyHandler<T> {
17
18
	private final RandomGenerator randomGenerator;
19
20
	public MultiMutationsPolicyHandler(final RandomGenerator _randomGenerator) {
21
		Objects.requireNonNull(_randomGenerator);
22
23 1 1. <init> : Removed assignment to member variable randomGenerator → SURVIVED
		this.randomGenerator = _randomGenerator;
24
	}
25
26
	@Override
27
	public boolean canHandle(final MutationPolicyHandlerResolver<T> mutationPolicyHandlerResolver,
28
			final MutationPolicy mutationPolicy) {
29
		Objects.requireNonNull(mutationPolicyHandlerResolver);
30
		Objects.requireNonNull(mutationPolicy);
31
32 3 1. canHandle : removed conditional - replaced equality check with false → SURVIVED
2. canHandle : removed conditional - replaced equality check with true → KILLED
3. canHandle : negated conditional → KILLED
		if (mutationPolicy instanceof MultiMutations == false) {
33 2 1. canHandle : Substituted 0 with 1 → NO_COVERAGE
2. canHandle : replaced boolean return with true for net/bmahe/genetics4j/core/mutation/MultiMutationsPolicyHandler::canHandle → NO_COVERAGE
			return false;
34
		}
35
36
		final MultiMutations multiMutations = (MultiMutations) mutationPolicy;
37
38 8 1. lambda$canHandle$0 : replaced boolean return with true for net/bmahe/genetics4j/core/mutation/MultiMutationsPolicyHandler::lambda$canHandle$0 → SURVIVED
2. canHandle : replaced boolean return with true for net/bmahe/genetics4j/core/mutation/MultiMutationsPolicyHandler::canHandle → SURVIVED
3. lambda$canHandle$0 : removed call to net/bmahe/genetics4j/core/mutation/MutationPolicyHandlerResolver::canHandle → KILLED
4. canHandle : removed call to net/bmahe/genetics4j/core/spec/mutation/MultiMutations::mutationPolicies → KILLED
5. lambda$canHandle$0 : replaced boolean return with false for net/bmahe/genetics4j/core/mutation/MultiMutationsPolicyHandler::lambda$canHandle$0 → KILLED
6. canHandle : removed call to java/util/stream/Stream::allMatch → KILLED
7. canHandle : removed call to java/util/List::stream → KILLED
8. canHandle : replaced boolean return with false for net/bmahe/genetics4j/core/mutation/MultiMutationsPolicyHandler::canHandle → KILLED
		return multiMutations.mutationPolicies().stream().allMatch((mp) -> mutationPolicyHandlerResolver.canHandle(mp));
39
	}
40
41
	@Override
42
	public Mutator createMutator(final AbstractEAExecutionContext<T> eaExecutionContext,
43
			final AbstractEAConfiguration<T> eaConfiguration,
44
			final MutationPolicyHandlerResolver<T> mutationPolicyHandlerResolver, final MutationPolicy mutationPolicy) {
45
		Objects.requireNonNull(eaExecutionContext);
46
		Objects.requireNonNull(eaConfiguration);
47
		Objects.requireNonNull(mutationPolicyHandlerResolver);
48
		Objects.requireNonNull(mutationPolicy);
49
		Validate.isInstanceOf(MultiMutations.class, mutationPolicy);
50
51
		final MultiMutations multiMutations = (MultiMutations) mutationPolicy;
52
53 4 1. createMutator : replaced call to java/util/stream/Stream::map with receiver → SURVIVED
2. createMutator : removed call to java/util/stream/Stream::map → KILLED
3. createMutator : removed call to java/util/List::stream → KILLED
4. createMutator : removed call to net/bmahe/genetics4j/core/spec/mutation/MultiMutations::mutationPolicies → KILLED
		final List<Mutator> mutators = multiMutations.mutationPolicies().stream().map((mp) -> {
54
55 1 1. lambda$createMutator$1 : removed call to net/bmahe/genetics4j/core/mutation/MutationPolicyHandlerResolver::resolve → KILLED
			final MutationPolicyHandler<T> mutationPolicyHandler = mutationPolicyHandlerResolver.resolve(mp);
56
57 1 1. lambda$createMutator$1 : replaced return value with null for net/bmahe/genetics4j/core/mutation/MultiMutationsPolicyHandler::lambda$createMutator$1 → SURVIVED
			return mutationPolicyHandler
58 1 1. lambda$createMutator$1 : removed call to net/bmahe/genetics4j/core/mutation/MutationPolicyHandler::createMutator → SURVIVED
					.createMutator(eaExecutionContext, eaConfiguration, mutationPolicyHandlerResolver, mp);
59 2 1. createMutator : removed call to java/util/stream/Stream::collect → SURVIVED
2. createMutator : removed call to java/util/stream/Collectors::toList → KILLED
		}).collect(Collectors.toList());
60
61 4 1. createMutator : removed call to net/bmahe/genetics4j/core/mutation/MultiMutationsPolicyHandler$1::<init> → SURVIVED
2. <init> : Removed assignment to member variable val$mutators → SURVIVED
3. <init> : Removed assignment to member variable this$0 → SURVIVED
4. createMutator : replaced return value with null for net/bmahe/genetics4j/core/mutation/MultiMutationsPolicyHandler::createMutator → SURVIVED
		return new Mutator() {
62
63
			@Override
64
			public Genotype mutate(final long generation, final Genotype original) {
65
				Validate.isTrue(generation >= 0);
66
				Objects.requireNonNull(original);
67
68 3 1. mutate : removed call to java/util/List::size → NO_COVERAGE
2. mutate : replaced call to java/util/random/RandomGenerator::nextInt with argument → NO_COVERAGE
3. mutate : removed call to java/util/random/RandomGenerator::nextInt → NO_COVERAGE
				final int selectedMutatorIndex = randomGenerator.nextInt(mutators.size());
69
70 4 1. mutate : replaced call to net/bmahe/genetics4j/core/mutation/Mutator::mutate with argument → NO_COVERAGE
2. mutate : replaced return value with null for net/bmahe/genetics4j/core/mutation/MultiMutationsPolicyHandler$1::mutate → NO_COVERAGE
3. mutate : removed call to net/bmahe/genetics4j/core/mutation/Mutator::mutate → NO_COVERAGE
4. mutate : removed call to java/util/List::get → NO_COVERAGE
				return mutators.get(selectedMutatorIndex).mutate(generation, original);
71
			}
72
		};
73
	}
74
}

Mutations

23

1.1
Location : <init>
Killed by : none
Removed assignment to member variable randomGenerator → SURVIVED
Covering tests

32

1.1
Location : canHandle
Killed by : net.bmahe.genetics4j.core.mutation.SupersimpleTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.SupersimpleTest]/[method:simple()]
removed conditional - replaced equality check with true → KILLED

2.2
Location : canHandle
Killed by : none
removed conditional - replaced equality check with false → SURVIVED
Covering tests

3.3
Location : canHandle
Killed by : net.bmahe.genetics4j.core.mutation.SupersimpleTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.SupersimpleTest]/[method:simple()]
negated conditional → KILLED

33

1.1
Location : canHandle
Killed by : none
Substituted 0 with 1 → NO_COVERAGE

2.2
Location : canHandle
Killed by : none
replaced boolean return with true for net/bmahe/genetics4j/core/mutation/MultiMutationsPolicyHandler::canHandle → NO_COVERAGE

38

1.1
Location : lambda$canHandle$0
Killed by : net.bmahe.genetics4j.core.mutation.SupersimpleTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.SupersimpleTest]/[method:simple()]
removed call to net/bmahe/genetics4j/core/mutation/MutationPolicyHandlerResolver::canHandle → KILLED

2.2
Location : canHandle
Killed by : net.bmahe.genetics4j.core.mutation.SupersimpleTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.SupersimpleTest]/[method:simple()]
removed call to net/bmahe/genetics4j/core/spec/mutation/MultiMutations::mutationPolicies → KILLED

3.3
Location : lambda$canHandle$0
Killed by : net.bmahe.genetics4j.core.mutation.SupersimpleTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.SupersimpleTest]/[method:simple()]
replaced boolean return with false for net/bmahe/genetics4j/core/mutation/MultiMutationsPolicyHandler::lambda$canHandle$0 → KILLED

4.4
Location : canHandle
Killed by : net.bmahe.genetics4j.core.mutation.SupersimpleTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.SupersimpleTest]/[method:simple()]
removed call to java/util/stream/Stream::allMatch → KILLED

5.5
Location : lambda$canHandle$0
Killed by : none
replaced boolean return with true for net/bmahe/genetics4j/core/mutation/MultiMutationsPolicyHandler::lambda$canHandle$0 → SURVIVED
Covering tests

6.6
Location : canHandle
Killed by : none
replaced boolean return with true for net/bmahe/genetics4j/core/mutation/MultiMutationsPolicyHandler::canHandle → SURVIVED Covering tests

7.7
Location : canHandle
Killed by : net.bmahe.genetics4j.core.mutation.SupersimpleTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.SupersimpleTest]/[method:simple()]
removed call to java/util/List::stream → KILLED

8.8
Location : canHandle
Killed by : net.bmahe.genetics4j.core.mutation.SupersimpleTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.SupersimpleTest]/[method:simple()]
replaced boolean return with false for net/bmahe/genetics4j/core/mutation/MultiMutationsPolicyHandler::canHandle → KILLED

53

1.1
Location : createMutator
Killed by : net.bmahe.genetics4j.core.mutation.SupersimpleTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.SupersimpleTest]/[method:simple()]
removed call to java/util/stream/Stream::map → KILLED

2.2
Location : createMutator
Killed by : net.bmahe.genetics4j.core.mutation.SupersimpleTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.SupersimpleTest]/[method:simple()]
removed call to java/util/List::stream → KILLED

3.3
Location : createMutator
Killed by : none
replaced call to java/util/stream/Stream::map with receiver → SURVIVED
Covering tests

4.4
Location : createMutator
Killed by : net.bmahe.genetics4j.core.mutation.SupersimpleTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.SupersimpleTest]/[method:simple()]
removed call to net/bmahe/genetics4j/core/spec/mutation/MultiMutations::mutationPolicies → KILLED

55

1.1
Location : lambda$createMutator$1
Killed by : net.bmahe.genetics4j.core.mutation.SupersimpleTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.SupersimpleTest]/[method:simple()]
removed call to net/bmahe/genetics4j/core/mutation/MutationPolicyHandlerResolver::resolve → KILLED

57

1.1
Location : lambda$createMutator$1
Killed by : none
replaced return value with null for net/bmahe/genetics4j/core/mutation/MultiMutationsPolicyHandler::lambda$createMutator$1 → SURVIVED
Covering tests

58

1.1
Location : lambda$createMutator$1
Killed by : none
removed call to net/bmahe/genetics4j/core/mutation/MutationPolicyHandler::createMutator → SURVIVED
Covering tests

59

1.1
Location : createMutator
Killed by : none
removed call to java/util/stream/Stream::collect → SURVIVED
Covering tests

2.2
Location : createMutator
Killed by : net.bmahe.genetics4j.core.mutation.SupersimpleTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.SupersimpleTest]/[method:simple()]
removed call to java/util/stream/Collectors::toList → KILLED

61

1.1
Location : createMutator
Killed by : none
removed call to net/bmahe/genetics4j/core/mutation/MultiMutationsPolicyHandler$1::<init> → SURVIVED
Covering tests

2.2
Location : <init>
Killed by : none
Removed assignment to member variable val$mutators → SURVIVED Covering tests

3.3
Location : <init>
Killed by : none
Removed assignment to member variable this$0 → SURVIVED Covering tests

4.4
Location : createMutator
Killed by : none
replaced return value with null for net/bmahe/genetics4j/core/mutation/MultiMutationsPolicyHandler::createMutator → SURVIVED Covering tests

68

1.1
Location : mutate
Killed by : none
removed call to java/util/List::size → NO_COVERAGE

2.2
Location : mutate
Killed by : none
replaced call to java/util/random/RandomGenerator::nextInt with argument → NO_COVERAGE

3.3
Location : mutate
Killed by : none
removed call to java/util/random/RandomGenerator::nextInt → NO_COVERAGE

70

1.1
Location : mutate
Killed by : none
replaced call to net/bmahe/genetics4j/core/mutation/Mutator::mutate with argument → NO_COVERAGE

2.2
Location : mutate
Killed by : none
replaced return value with null for net/bmahe/genetics4j/core/mutation/MultiMutationsPolicyHandler$1::mutate → NO_COVERAGE

3.3
Location : mutate
Killed by : none
removed call to net/bmahe/genetics4j/core/mutation/Mutator::mutate → NO_COVERAGE

4.4
Location : mutate
Killed by : none
removed call to java/util/List::get → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.20.3