|
1
|
|
/* |
|
2
|
|
* Copyright 2004 the original author or authors. |
|
3
|
|
* |
|
4
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
5
|
|
* you may not use this file except in compliance with the License. |
|
6
|
|
* You may obtain a copy of the License at |
|
7
|
|
* |
|
8
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
9
|
|
* |
|
10
|
|
* Unless required by applicable law or agreed to in writing, software |
|
11
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
12
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13
|
|
* See the License for the specific language governing permissions and |
|
14
|
|
* limitations under the License. |
|
15
|
|
*/ |
|
16
|
|
package com.ancientprogramming.fixedformat4j.io.read; |
|
17
|
|
|
|
18
|
|
import java.util.Collections; |
|
19
|
|
import java.util.List; |
|
20
|
|
import java.util.Map; |
|
21
|
|
import java.util.Set; |
|
22
|
|
|
|
23
|
|
/** |
|
24
|
|
* The result of a {@link com.ancientprogramming.fixedformat4j.io.read.FixedFormatReader#read} |
|
25
|
|
* call: an immutable, class-keyed container of parsed records that provides type-safe retrieval |
|
26
|
|
* without casts at the call site. |
|
27
|
|
* |
|
28
|
|
* <p>The type safety relies on the invariant that every record stored under key {@code K} |
|
29
|
|
* is an instance of {@code K}. The package-private constructor ensures this is maintained |
|
30
|
|
* automatically by {@link com.ancientprogramming.fixedformat4j.io.read.FixedFormatReader#read}.</p> |
|
31
|
|
* |
|
32
|
|
* <pre>{@code |
|
33
|
|
* ReadResult result = reader.read(path); |
|
34
|
|
* List<HeaderRecord> headers = result.get(HeaderRecord.class); // no cast |
|
35
|
|
* List<DetailRecord> details = result.get(DetailRecord.class); // no cast |
|
36
|
|
* }</pre> |
|
37
|
|
* |
|
38
|
|
* @author Jacob von Eyben - <a href="https://eybenconsult.com">https://eybenconsult.com</a> |
|
39
|
|
* @since 1.8.0 |
|
40
|
|
*/ |
|
41
|
|
public final class ReadResult { |
|
42
|
|
|
|
43
|
|
private final Map<Class<?>, List<Object>> data; |
|
44
|
|
private final List<Object> all; |
|
45
|
|
|
|
46
|
|
ReadResult(Map<Class<?>, List<Object>> data, List<Object> all) { |
|
47
|
3
1. <init> : replaced call to java/util/Collections::unmodifiableMap with argument → SURVIVED
2. <init> : removed call to java/util/Collections::unmodifiableMap → KILLED
3. <init> : Removed assignment to member variable data → KILLED
|
this.data = Collections.unmodifiableMap(data); |
|
48
|
3
1. <init> : replaced call to java/util/Collections::unmodifiableList with argument → SURVIVED
2. <init> : removed call to java/util/Collections::unmodifiableList → KILLED
3. <init> : Removed assignment to member variable all → KILLED
|
this.all = Collections.unmodifiableList(all); |
|
49
|
|
} |
|
50
|
|
|
|
51
|
|
/** |
|
52
|
|
* Returns all records stored under {@code clazz} as a correctly typed list. |
|
53
|
|
* |
|
54
|
|
* <p>Safe by invariant: every entry stored under key {@code K} was produced by |
|
55
|
|
* {@code manager.load(K, line)} and is therefore an instance of {@code K}.</p> |
|
56
|
|
* |
|
57
|
|
* @param <R> the record type |
|
58
|
|
* @param clazz the class to retrieve records for |
|
59
|
|
* @return an unmodifiable list of {@code R} instances; empty if no records matched {@code clazz} |
|
60
|
|
*/ |
|
61
|
|
@SuppressWarnings("unchecked") |
|
62
|
|
public <R> List<R> get(Class<R> clazz) { |
|
63
|
2
1. get : removed call to java/util/Map::get → KILLED
2. get : replaced call to java/util/Map::get with argument → KILLED
|
List<Object> records = data.get(clazz); |
|
64
|
3
1. get : negated conditional → KILLED
2. get : removed conditional - replaced equality check with true → KILLED
3. get : removed conditional - replaced equality check with false → KILLED
|
if (records == null) { |
|
65
|
1
1. get : removed call to java/util/Collections::emptyList → KILLED
|
return Collections.emptyList(); |
|
66
|
|
} |
|
67
|
3
1. get : replaced return value with Collections.emptyList for com/ancientprogramming/fixedformat4j/io/read/ReadResult::get → KILLED
2. get : replaced call to java/util/Collections::unmodifiableList with argument → KILLED
3. get : removed call to java/util/Collections::unmodifiableList → KILLED
|
return Collections.unmodifiableList((List<R>) records); |
|
68
|
|
} |
|
69
|
|
|
|
70
|
|
/** |
|
71
|
|
* Returns all records from all classes in encounter order. |
|
72
|
|
* |
|
73
|
|
* @return an unmodifiable flat list of all parsed records; never {@code null} |
|
74
|
|
*/ |
|
75
|
|
public List<Object> getAll() { |
|
76
|
1
1. getAll : replaced return value with Collections.emptyList for com/ancientprogramming/fixedformat4j/io/read/ReadResult::getAll → KILLED
|
return all; |
|
77
|
|
} |
|
78
|
|
|
|
79
|
|
/** |
|
80
|
|
* Returns {@code true} if at least one record was matched for {@code clazz}. |
|
81
|
|
* |
|
82
|
|
* @param clazz the class to check |
|
83
|
|
* @return {@code true} if records exist for {@code clazz} |
|
84
|
|
*/ |
|
85
|
|
public boolean contains(Class<?> clazz) { |
|
86
|
3
1. contains : removed call to java/util/Map::containsKey → KILLED
2. contains : replaced boolean return with false for com/ancientprogramming/fixedformat4j/io/read/ReadResult::contains → KILLED
3. contains : replaced boolean return with true for com/ancientprogramming/fixedformat4j/io/read/ReadResult::contains → KILLED
|
return data.containsKey(clazz); |
|
87
|
|
} |
|
88
|
|
|
|
89
|
|
/** |
|
90
|
|
* Returns the set of classes that produced at least one record. |
|
91
|
|
* |
|
92
|
|
* @return an unmodifiable set; never {@code null} |
|
93
|
|
*/ |
|
94
|
|
public Set<Class<?>> classes() { |
|
95
|
2
1. classes : replaced return value with Collections.emptySet for com/ancientprogramming/fixedformat4j/io/read/ReadResult::classes → KILLED
2. classes : removed call to java/util/Map::keySet → KILLED
|
return data.keySet(); |
|
96
|
|
} |
|
97
|
|
} |
| | Mutations |
| 47 |
|
1.1 Location : <init> Killed by : com.ancientprogramming.fixedformat4j.io.read.TestReadResult.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.io.read.TestReadResult]/[method:getReturnsEmptyListForUnregisteredClass()] removed call to java/util/Collections::unmodifiableMap → KILLED
2.2 Location : <init> Killed by : com.ancientprogramming.fixedformat4j.io.read.TestReadResult.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.io.read.TestReadResult]/[method:getReturnsEmptyListForUnregisteredClass()] Removed assignment to member variable data → KILLED
3.3 Location : <init> Killed by : none replaced call to java/util/Collections::unmodifiableMap with argument → SURVIVED
Covering tests
|
| 48 |
|
1.1 Location : <init> Killed by : com.ancientprogramming.fixedformat4j.io.read.TestReadResult.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.io.read.TestReadResult]/[method:getAllReturnsFlatListInEncounterOrder()] removed call to java/util/Collections::unmodifiableList → KILLED
2.2 Location : <init> Killed by : com.ancientprogramming.fixedformat4j.io.read.TestReadResult.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.io.read.TestReadResult]/[method:getAllReturnsFlatListInEncounterOrder()] Removed assignment to member variable all → KILLED
3.3 Location : <init> Killed by : none replaced call to java/util/Collections::unmodifiableList with argument → SURVIVED
Covering tests
|
| 63 |
|
1.1 Location : get Killed by : com.ancientprogramming.fixedformat4j.io.read.TestReadResult.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.io.read.TestReadResult]/[method:getReturnsTypedListForRegisteredClass()] removed call to java/util/Map::get → KILLED
2.2 Location : get Killed by : com.ancientprogramming.fixedformat4j.io.read.TestReadResult.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.io.read.TestReadResult]/[method:getReturnsEmptyListForUnregisteredClass()] replaced call to java/util/Map::get with argument → KILLED
|
| 64 |
|
1.1 Location : get Killed by : com.ancientprogramming.fixedformat4j.io.read.TestReadResult.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.io.read.TestReadResult]/[method:getReturnsEmptyListForUnregisteredClass()] negated conditional → KILLED
2.2 Location : get Killed by : com.ancientprogramming.fixedformat4j.io.read.TestReadResult.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.io.read.TestReadResult]/[method:getReturnsTypedListForRegisteredClass()] removed conditional - replaced equality check with true → KILLED
3.3 Location : get Killed by : com.ancientprogramming.fixedformat4j.io.read.TestReadResult.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.io.read.TestReadResult]/[method:getReturnsEmptyListForUnregisteredClass()] removed conditional - replaced equality check with false → KILLED
|
| 65 |
|
1.1 Location : get Killed by : com.ancientprogramming.fixedformat4j.io.read.TestReadResult.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.io.read.TestReadResult]/[method:getReturnsEmptyListForUnregisteredClass()] removed call to java/util/Collections::emptyList → KILLED
|
| 67 |
|
1.1 Location : get Killed by : com.ancientprogramming.fixedformat4j.io.read.TestReadResult.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.io.read.TestReadResult]/[method:getReturnsTypedListForRegisteredClass()] replaced return value with Collections.emptyList for com/ancientprogramming/fixedformat4j/io/read/ReadResult::get → KILLED
2.2 Location : get Killed by : com.ancientprogramming.fixedformat4j.io.read.TestReadResult.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.io.read.TestReadResult]/[method:getReturnedListIsUnmodifiable()] replaced call to java/util/Collections::unmodifiableList with argument → KILLED
3.3 Location : get Killed by : com.ancientprogramming.fixedformat4j.io.read.TestReadResult.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.io.read.TestReadResult]/[method:getReturnsTypedListForRegisteredClass()] removed call to java/util/Collections::unmodifiableList → KILLED
|
| 76 |
|
1.1 Location : getAll Killed by : com.ancientprogramming.fixedformat4j.io.read.TestReadResult.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.io.read.TestReadResult]/[method:getAllReturnsFlatListInEncounterOrder()] replaced return value with Collections.emptyList for com/ancientprogramming/fixedformat4j/io/read/ReadResult::getAll → KILLED
|
| 86 |
|
1.1 Location : contains Killed by : com.ancientprogramming.fixedformat4j.io.read.TestReadResult.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.io.read.TestReadResult]/[method:containsReturnsTrueForClassWithRecords()] removed call to java/util/Map::containsKey → KILLED
2.2 Location : contains Killed by : com.ancientprogramming.fixedformat4j.io.read.TestReadResult.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.io.read.TestReadResult]/[method:containsReturnsTrueForClassWithRecords()] replaced boolean return with false for com/ancientprogramming/fixedformat4j/io/read/ReadResult::contains → KILLED
3.3 Location : contains Killed by : com.ancientprogramming.fixedformat4j.io.read.TestReadResult.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.io.read.TestReadResult]/[method:containsReturnsTrueForClassWithRecords()] replaced boolean return with true for com/ancientprogramming/fixedformat4j/io/read/ReadResult::contains → KILLED
|
| 95 |
|
1.1 Location : classes Killed by : com.ancientprogramming.fixedformat4j.io.read.TestReadResult.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.io.read.TestReadResult]/[method:classesReturnsOnlyClassesThatProducedRecords()] replaced return value with Collections.emptySet for com/ancientprogramming/fixedformat4j/io/read/ReadResult::classes → KILLED
2.2 Location : classes Killed by : com.ancientprogramming.fixedformat4j.io.read.TestReadResult.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.io.read.TestReadResult]/[method:classesReturnsOnlyClassesThatProducedRecords()] removed call to java/util/Map::keySet → KILLED
|