|
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.format; |
|
17
|
|
|
|
18
|
|
/** |
|
19
|
|
* Handles default formatting and parsing based on FixedFormatAnnotation values. |
|
20
|
|
* |
|
21
|
|
* @author Jacob von Eyben - <a href="https://eybenconsult.com">https://eybenconsult.com</a> |
|
22
|
|
* @since 1.0.0 |
|
23
|
|
*/ |
|
24
|
|
public abstract class AbstractFixedFormatter<T> implements FixedFormatter<T> { |
|
25
|
|
/** |
|
26
|
|
* {@inheritDoc} |
|
27
|
|
* <p> |
|
28
|
|
* Strips padding from {@code value} according to the alignment and padding char defined in |
|
29
|
|
* {@code instructions}, then delegates to {@link #asObject(String, FormatInstructions)}. |
|
30
|
|
* Returns {@code null} when {@code value} is {@code null}. |
|
31
|
|
*/ |
|
32
|
|
public T parse(String value, FormatInstructions instructions) { |
|
33
|
|
T result = null; |
|
34
|
3
1. parse : removed conditional - replaced equality check with true → KILLED
2. parse : removed conditional - replaced equality check with false → KILLED
3. parse : negated conditional → KILLED
|
if (value != null) { |
|
35
|
5
1. parse : negated conditional → KILLED
2. parse : removed conditional - replaced equality check with true → KILLED
3. parse : removed call to com/ancientprogramming/fixedformat4j/format/FormatInstructions::getLength → KILLED
4. parse : Substituted -1 with 0 → KILLED
5. parse : removed conditional - replaced equality check with false → KILLED
|
if (instructions.getLength() == -1) { |
|
36
|
1
1. parse : removed call to com/ancientprogramming/fixedformat4j/format/AbstractFixedFormatter::asObject → KILLED
|
result = asObject(value, instructions); |
|
37
|
|
} else { |
|
38
|
3
1. parse : removed call to com/ancientprogramming/fixedformat4j/format/AbstractFixedFormatter::stripPadding → KILLED
2. parse : removed call to com/ancientprogramming/fixedformat4j/format/AbstractFixedFormatter::asObject → KILLED
3. parse : replaced call to com/ancientprogramming/fixedformat4j/format/AbstractFixedFormatter::stripPadding with argument → KILLED
|
result = asObject(stripPadding(value, instructions), instructions); |
|
39
|
|
} |
|
40
|
|
} |
|
41
|
1
1. parse : replaced return value with null for com/ancientprogramming/fixedformat4j/format/AbstractFixedFormatter::parse → KILLED
|
return result; |
|
42
|
|
} |
|
43
|
|
|
|
44
|
|
/** |
|
45
|
|
* Strips padding characters from {@code value} before it is passed to {@link #asObject}. |
|
46
|
|
* |
|
47
|
|
* <p>This is the extension point for subclasses that need to customise pre-parse |
|
48
|
|
* padding removal. |
|
49
|
|
* |
|
50
|
|
* @param value the raw field string extracted from the fixed-width record |
|
51
|
|
* @param instructions formatting metadata (alignment, padding character, length, …) |
|
52
|
|
* @return the value with padding removed, ready to be converted by {@link #asObject} |
|
53
|
|
*/ |
|
54
|
|
protected String stripPadding(String value, FormatInstructions instructions) { |
|
55
|
5
1. stripPadding : removed call to com/ancientprogramming/fixedformat4j/format/FormatInstructions::getPaddingChar → KILLED
2. stripPadding : removed call to com/ancientprogramming/fixedformat4j/annotation/Align::remove → KILLED
3. stripPadding : removed call to com/ancientprogramming/fixedformat4j/format/FormatInstructions::getAlignment → KILLED
4. stripPadding : replaced call to com/ancientprogramming/fixedformat4j/annotation/Align::remove with argument → KILLED
5. stripPadding : replaced return value with "" for com/ancientprogramming/fixedformat4j/format/AbstractFixedFormatter::stripPadding → KILLED
|
return instructions.getAlignment().remove(value, instructions.getPaddingChar()); |
|
56
|
|
} |
|
57
|
|
|
|
58
|
|
/** |
|
59
|
|
* {@inheritDoc} |
|
60
|
|
* <p> |
|
61
|
|
* Converts {@code value} to its string representation via |
|
62
|
|
* {@link #asString(Object, FormatInstructions)}, then applies padding and alignment as defined |
|
63
|
|
* in {@code instructions}. |
|
64
|
|
*/ |
|
65
|
|
public String format(T value, FormatInstructions instructions) { |
|
66
|
5
1. format : removed call to com/ancientprogramming/fixedformat4j/format/FormatInstructions::getLength → KILLED
2. format : removed conditional - replaced equality check with true → KILLED
3. format : Substituted -1 with 0 → KILLED
4. format : negated conditional → KILLED
5. format : removed conditional - replaced equality check with false → KILLED
|
if (instructions.getLength() == -1) { |
|
67
|
1
1. format : removed call to com/ancientprogramming/fixedformat4j/format/AbstractFixedFormatter::asString → KILLED
|
String raw = asString(value, instructions); |
|
68
|
3
1. format : removed conditional - replaced equality check with false → KILLED
2. format : removed conditional - replaced equality check with true → KILLED
3. format : negated conditional → KILLED
|
return raw != null ? raw : ""; |
|
69
|
|
} |
|
70
|
7
1. format : replaced call to com/ancientprogramming/fixedformat4j/annotation/Align::apply with argument → KILLED
2. format : removed call to com/ancientprogramming/fixedformat4j/annotation/Align::apply → KILLED
3. format : removed call to com/ancientprogramming/fixedformat4j/format/AbstractFixedFormatter::asString → KILLED
4. format : removed call to com/ancientprogramming/fixedformat4j/format/FormatInstructions::getAlignment → KILLED
5. format : removed call to com/ancientprogramming/fixedformat4j/format/FormatInstructions::getPaddingChar → KILLED
6. format : removed call to com/ancientprogramming/fixedformat4j/format/FormatInstructions::getLength → KILLED
7. format : replaced return value with "" for com/ancientprogramming/fixedformat4j/format/AbstractFixedFormatter::format → KILLED
|
return instructions.getAlignment().apply(asString(value, instructions), instructions.getLength(), instructions.getPaddingChar()); |
|
71
|
|
} |
|
72
|
|
|
|
73
|
|
/** |
|
74
|
|
* Converts the trimmed string {@code string} to an instance of {@code T}. |
|
75
|
|
* Padding has already been removed from {@code string} before this method is called. |
|
76
|
|
* |
|
77
|
|
* @param string the raw (padding-stripped) field value |
|
78
|
|
* @param instructions formatting instructions for the field |
|
79
|
|
* @return the parsed value, or {@code null} if the field is empty |
|
80
|
|
*/ |
|
81
|
|
public abstract T asObject(String string, FormatInstructions instructions); |
|
82
|
|
|
|
83
|
|
/** |
|
84
|
|
* Converts {@code obj} to its raw string representation before padding is applied. |
|
85
|
|
* |
|
86
|
|
* @param obj the value to convert; may be {@code null} |
|
87
|
|
* @param instructions formatting instructions for the field |
|
88
|
|
* @return the string representation of {@code obj} |
|
89
|
|
*/ |
|
90
|
|
public abstract String asString(T obj, FormatInstructions instructions); |
|
91
|
|
} |
| | Mutations |
| 34 |
|
1.1 Location : parse Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestRepeatingField.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestRepeatingField]/[method:testLoadPartialRecord()] removed conditional - replaced equality check with true → KILLED
2.2 Location : parse Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestBooleanFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestBooleanFormatter]/[method:testAllSpaceStringReturnsFalse()] removed conditional - replaced equality check with false → KILLED
3.3 Location : parse Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestBooleanFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestBooleanFormatter]/[method:testAllSpaceStringReturnsFalse()] negated conditional → KILLED
|
| 35 |
|
1.1 Location : parse Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter]/[method:allZeroFieldWithZeroPaddingParsesToNull()] negated conditional → KILLED
2.2 Location : parse Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter]/[method:allZeroFieldWithZeroPaddingParsesToNull()] removed conditional - replaced equality check with true → KILLED
3.3 Location : parse Killed by : com.ancientprogramming.fixedformat4j.issues.TestIssue97RestOfLine.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.issues.TestIssue97RestOfLine]/[method:roundTrip_fullLine_preservesValueExactly()] removed call to com/ancientprogramming/fixedformat4j/format/FormatInstructions::getLength → KILLED
4.4 Location : parse Killed by : com.ancientprogramming.fixedformat4j.issues.TestIssue97RestOfLine.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.issues.TestIssue97RestOfLine]/[method:roundTrip_fullLine_preservesValueExactly()] Substituted -1 with 0 → KILLED
5.5 Location : parse Killed by : com.ancientprogramming.fixedformat4j.issues.TestIssue97RestOfLine.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.issues.TestIssue97RestOfLine]/[method:roundTrip_fullLine_preservesValueExactly()] removed conditional - replaced equality check with false → KILLED
|
| 36 |
|
1.1 Location : parse Killed by : com.ancientprogramming.fixedformat4j.issues.TestIssue97RestOfLine.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.issues.TestIssue97RestOfLine]/[method:load_restOfLineFromOffset1_emptyLineYieldsEmptyString()] removed call to com/ancientprogramming/fixedformat4j/format/AbstractFixedFormatter::asObject → KILLED
|
| 38 |
|
1.1 Location : parse Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestStringFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestStringFormatter]/[method:testParse()] removed call to com/ancientprogramming/fixedformat4j/format/AbstractFixedFormatter::stripPadding → KILLED
2.2 Location : parse Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestBooleanFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestBooleanFormatter]/[method:testAllSpaceStringReturnsFalse()] removed call to com/ancientprogramming/fixedformat4j/format/AbstractFixedFormatter::asObject → KILLED
3.3 Location : parse Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateFormatter]/[method:allZeroFieldWithZeroPaddingParsesToNull()] replaced call to com/ancientprogramming/fixedformat4j/format/AbstractFixedFormatter::stripPadding with argument → KILLED
|
| 41 |
|
1.1 Location : parse Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestBooleanFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestBooleanFormatter]/[method:testAllSpaceStringReturnsFalse()] replaced return value with null for com/ancientprogramming/fixedformat4j/format/AbstractFixedFormatter::parse → KILLED
|
| 55 |
|
1.1 Location : stripPadding Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestBooleanFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestBooleanFormatter]/[method:testAllSpaceStringReturnsFalse()] removed call to com/ancientprogramming/fixedformat4j/format/FormatInstructions::getPaddingChar → KILLED
2.2 Location : stripPadding Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestStringFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestStringFormatter]/[method:testParse()] removed call to com/ancientprogramming/fixedformat4j/annotation/Align::remove → KILLED
3.3 Location : stripPadding Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestBooleanFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestBooleanFormatter]/[method:testAllSpaceStringReturnsFalse()] removed call to com/ancientprogramming/fixedformat4j/format/FormatInstructions::getAlignment → KILLED
4.4 Location : stripPadding Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestBooleanFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestBooleanFormatter]/[method:testAllSpaceStringReturnsFalse()] replaced call to com/ancientprogramming/fixedformat4j/annotation/Align::remove with argument → KILLED
5.5 Location : stripPadding Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestStringFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestStringFormatter]/[method:testParse()] replaced return value with "" for com/ancientprogramming/fixedformat4j/format/AbstractFixedFormatter::stripPadding → KILLED
|
| 66 |
|
1.1 Location : format Killed by : com.ancientprogramming.fixedformat4j.issues.TestIssue97RestOfLine.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.issues.TestIssue97RestOfLine]/[method:export_restOfLine_writesVerbatim()] removed call to com/ancientprogramming/fixedformat4j/format/FormatInstructions::getLength → KILLED
2.2 Location : format Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestCharacterFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestCharacterFormatter]/[method:testFormat()] removed conditional - replaced equality check with true → KILLED
3.3 Location : format Killed by : com.ancientprogramming.fixedformat4j.issues.TestIssue97RestOfLine.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.issues.TestIssue97RestOfLine]/[method:export_restOfLine_writesVerbatim()] Substituted -1 with 0 → KILLED
4.4 Location : format Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestCharacterFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestCharacterFormatter]/[method:testFormat()] negated conditional → KILLED
5.5 Location : format Killed by : com.ancientprogramming.fixedformat4j.issues.TestIssue97RestOfLine.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.issues.TestIssue97RestOfLine]/[method:export_restOfLine_writesVerbatim()] removed conditional - replaced equality check with false → KILLED
|
| 67 |
|
1.1 Location : format Killed by : com.ancientprogramming.fixedformat4j.issues.TestIssue97RestOfLine.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.issues.TestIssue97RestOfLine]/[method:export_restOfLine_writesVerbatim()] removed call to com/ancientprogramming/fixedformat4j/format/AbstractFixedFormatter::asString → KILLED
|
| 68 |
|
1.1 Location : format Killed by : com.ancientprogramming.fixedformat4j.issues.TestIssue97RestOfLine.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.issues.TestIssue97RestOfLine]/[method:export_restOfLine_writesVerbatim()] removed conditional - replaced equality check with false → KILLED
2.2 Location : format Killed by : com.ancientprogramming.fixedformat4j.issues.TestIssue97RestOfLine.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.issues.TestIssue97RestOfLine]/[method:export_restOfLine_nullValueExportsAsEmpty()] removed conditional - replaced equality check with true → KILLED
3.3 Location : format Killed by : com.ancientprogramming.fixedformat4j.issues.TestIssue97RestOfLine.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.issues.TestIssue97RestOfLine]/[method:export_restOfLine_writesVerbatim()] negated conditional → KILLED
|
| 70 |
|
1.1 Location : format Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter]/[method:testNullFormatReturnsSpaces()] replaced call to com/ancientprogramming/fixedformat4j/annotation/Align::apply with argument → KILLED
2.2 Location : format Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter]/[method:testNullFormatReturnsSpaces()] removed call to com/ancientprogramming/fixedformat4j/annotation/Align::apply → KILLED
3.3 Location : format Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter]/[method:testFormatCompactPattern()] removed call to com/ancientprogramming/fixedformat4j/format/AbstractFixedFormatter::asString → KILLED
4.4 Location : format Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter]/[method:testNullFormatReturnsSpaces()] removed call to com/ancientprogramming/fixedformat4j/format/FormatInstructions::getAlignment → KILLED
5.5 Location : format Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter]/[method:testNullFormatReturnsSpaces()] removed call to com/ancientprogramming/fixedformat4j/format/FormatInstructions::getPaddingChar → KILLED
6.6 Location : format Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter]/[method:testNullFormatReturnsSpaces()] removed call to com/ancientprogramming/fixedformat4j/format/FormatInstructions::getLength → KILLED
7.7 Location : format Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter]/[method:testNullFormatReturnsSpaces()] replaced return value with "" for com/ancientprogramming/fixedformat4j/format/AbstractFixedFormatter::format → KILLED
|