| 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 | import com.ancientprogramming.fixedformat4j.annotation.Align; | |
| 19 | import com.ancientprogramming.fixedformat4j.format.data.FixedFormatBooleanData; | |
| 20 | import com.ancientprogramming.fixedformat4j.format.data.FixedFormatDecimalData; | |
| 21 | import com.ancientprogramming.fixedformat4j.format.data.FixedFormatEnumData; | |
| 22 | import com.ancientprogramming.fixedformat4j.format.data.FixedFormatNumberData; | |
| 23 | import com.ancientprogramming.fixedformat4j.format.data.FixedFormatPatternData; | |
| 24 | ||
| 25 | /** | |
| 26 | * Contains instructions on how to export and load fixed formatted data. | |
| 27 | * | |
| 28 | * @author Jacob von Eyben - <a href="https://eybenconsult.com">https://eybenconsult.com</a> | |
| 29 | * @since 1.0.0 | |
| 30 | */ | |
| 31 | public class FormatInstructions { | |
| 32 | ||
| 33 | private int length; | |
| 34 | private Align alignment; | |
| 35 | private char paddingChar; | |
| 36 | private char nullChar; | |
| 37 | private FixedFormatPatternData fixedFormatPatternData; | |
| 38 | private FixedFormatBooleanData fixedFormatBooleanData; | |
| 39 | private FixedFormatNumberData fixedFormatNumberData; | |
| 40 | private FixedFormatDecimalData fixedFormatDecimalData; | |
| 41 | private FixedFormatEnumData fixedFormatEnumData; | |
| 42 | ||
| 43 | /** | |
| 44 | * Creates format instructions with enum data defaulting to {@link FixedFormatEnumData#DEFAULT} | |
| 45 | * and null-char detection disabled ({@code nullChar == paddingChar}). | |
| 46 | * | |
| 47 | * @param length the fixed width of the field in characters | |
| 48 | * @param alignment the alignment strategy used to pad and strip the field | |
| 49 | * @param paddingChar the character used for padding | |
| 50 | * @param fixedFormatPatternData date/time pattern configuration, or {@code null} if unused | |
| 51 | * @param fixedFormatBooleanData boolean value configuration, or {@code null} if unused | |
| 52 | * @param fixedFormatNumberData number sign configuration, or {@code null} if unused | |
| 53 | * @param fixedFormatDecimalData decimal precision configuration, or {@code null} if unused | |
| 54 | */ | |
| 55 | public FormatInstructions(int length, Align alignment, char paddingChar, FixedFormatPatternData fixedFormatPatternData, FixedFormatBooleanData fixedFormatBooleanData, FixedFormatNumberData fixedFormatNumberData, FixedFormatDecimalData fixedFormatDecimalData) { | |
| 56 | this(length, alignment, paddingChar, paddingChar, fixedFormatPatternData, fixedFormatBooleanData, fixedFormatNumberData, fixedFormatDecimalData, FixedFormatEnumData.DEFAULT); | |
| 57 | } | |
| 58 | ||
| 59 | /** | |
| 60 | * Creates a fully-populated set of format instructions including enum configuration, with | |
| 61 | * null-char detection disabled ({@code nullChar == paddingChar}). | |
| 62 | * | |
| 63 | * @param length the fixed width of the field in characters | |
| 64 | * @param alignment the alignment strategy used to pad and strip the field | |
| 65 | * @param paddingChar the character used for padding | |
| 66 | * @param fixedFormatPatternData date/time pattern configuration, or {@code null} if unused | |
| 67 | * @param fixedFormatBooleanData boolean value configuration, or {@code null} if unused | |
| 68 | * @param fixedFormatNumberData number sign configuration, or {@code null} if unused | |
| 69 | * @param fixedFormatDecimalData decimal precision configuration, or {@code null} if unused | |
| 70 | * @param fixedFormatEnumData enum serialization configuration, or {@code null} if unused | |
| 71 | */ | |
| 72 | public FormatInstructions(int length, Align alignment, char paddingChar, FixedFormatPatternData fixedFormatPatternData, FixedFormatBooleanData fixedFormatBooleanData, FixedFormatNumberData fixedFormatNumberData, FixedFormatDecimalData fixedFormatDecimalData, FixedFormatEnumData fixedFormatEnumData) { | |
| 73 | this(length, alignment, paddingChar, paddingChar, fixedFormatPatternData, fixedFormatBooleanData, fixedFormatNumberData, fixedFormatDecimalData, fixedFormatEnumData); | |
| 74 | } | |
| 75 | ||
| 76 | /** | |
| 77 | * Creates a fully-populated set of format instructions including a {@code nullChar} sentinel | |
| 78 | * used to represent a {@code null} field value on load and export. When | |
| 79 | * {@code nullChar == paddingChar} the detection is disabled and existing behavior is preserved. | |
| 80 | * | |
| 81 | * @param length the fixed width of the field in characters | |
| 82 | * @param alignment the alignment strategy used to pad and strip the field | |
| 83 | * @param paddingChar the character used for padding | |
| 84 | * @param nullChar the sentinel character signalling a {@code null} field | |
| 85 | * @param fixedFormatPatternData date/time pattern configuration, or {@code null} if unused | |
| 86 | * @param fixedFormatBooleanData boolean value configuration, or {@code null} if unused | |
| 87 | * @param fixedFormatNumberData number sign configuration, or {@code null} if unused | |
| 88 | * @param fixedFormatDecimalData decimal precision configuration, or {@code null} if unused | |
| 89 | * @param fixedFormatEnumData enum serialization configuration, or {@code null} if unused | |
| 90 | * @since 1.7.1 | |
| 91 | */ | |
| 92 | public FormatInstructions(int length, Align alignment, char paddingChar, char nullChar, FixedFormatPatternData fixedFormatPatternData, FixedFormatBooleanData fixedFormatBooleanData, FixedFormatNumberData fixedFormatNumberData, FixedFormatDecimalData fixedFormatDecimalData, FixedFormatEnumData fixedFormatEnumData) { | |
| 93 |
1
1. <init> : Removed assignment to member variable length → KILLED |
this.length = length; |
| 94 |
1
1. <init> : Removed assignment to member variable alignment → KILLED |
this.alignment = alignment; |
| 95 |
1
1. <init> : Removed assignment to member variable paddingChar → KILLED |
this.paddingChar = paddingChar; |
| 96 |
1
1. <init> : Removed assignment to member variable nullChar → KILLED |
this.nullChar = nullChar; |
| 97 |
1
1. <init> : Removed assignment to member variable fixedFormatPatternData → KILLED |
this.fixedFormatPatternData = fixedFormatPatternData; |
| 98 |
1
1. <init> : Removed assignment to member variable fixedFormatBooleanData → KILLED |
this.fixedFormatBooleanData = fixedFormatBooleanData; |
| 99 |
1
1. <init> : Removed assignment to member variable fixedFormatNumberData → KILLED |
this.fixedFormatNumberData = fixedFormatNumberData; |
| 100 |
1
1. <init> : Removed assignment to member variable fixedFormatDecimalData → KILLED |
this.fixedFormatDecimalData = fixedFormatDecimalData; |
| 101 |
1
1. <init> : Removed assignment to member variable fixedFormatEnumData → KILLED |
this.fixedFormatEnumData = fixedFormatEnumData; |
| 102 | } | |
| 103 | ||
| 104 | /** | |
| 105 | * Returns the fixed character width of the field. | |
| 106 | * | |
| 107 | * @return the field length in characters | |
| 108 | */ | |
| 109 | public int getLength() { | |
| 110 |
1
1. getLength : replaced int return with 0 for com/ancientprogramming/fixedformat4j/format/FormatInstructions::getLength → KILLED |
return length; |
| 111 | } | |
| 112 | ||
| 113 | /** | |
| 114 | * Returns the alignment strategy used to pad and strip the field value. | |
| 115 | * | |
| 116 | * @return the {@link Align} constant for this field | |
| 117 | */ | |
| 118 | public Align getAlignment() { | |
| 119 |
1
1. getAlignment : replaced return value with null for com/ancientprogramming/fixedformat4j/format/FormatInstructions::getAlignment → KILLED |
return alignment; |
| 120 | } | |
| 121 | ||
| 122 | /** | |
| 123 | * Returns the character used to pad the field to its full length. | |
| 124 | * | |
| 125 | * @return the padding character | |
| 126 | */ | |
| 127 | public char getPaddingChar() { | |
| 128 |
1
1. getPaddingChar : replaced char return with 0 for com/ancientprogramming/fixedformat4j/format/FormatInstructions::getPaddingChar → KILLED |
return paddingChar; |
| 129 | } | |
| 130 | ||
| 131 | /** | |
| 132 | * Returns the sentinel character that signals a {@code null} field value. When it equals | |
| 133 | * {@link #getPaddingChar()} the null-char detection is disabled and existing behavior is | |
| 134 | * preserved. | |
| 135 | * | |
| 136 | * @return the null sentinel character | |
| 137 | * @since 1.7.1 | |
| 138 | */ | |
| 139 | public char getNullChar() { | |
| 140 |
1
1. getNullChar : replaced char return with 0 for com/ancientprogramming/fixedformat4j/format/FormatInstructions::getNullChar → KILLED |
return nullChar; |
| 141 | } | |
| 142 | ||
| 143 | /** | |
| 144 | * Returns the date/time pattern configuration for this field. | |
| 145 | * | |
| 146 | * @return the {@link FixedFormatPatternData}, or {@code null} if no pattern annotation is present | |
| 147 | */ | |
| 148 | public FixedFormatPatternData getFixedFormatPatternData() { | |
| 149 |
1
1. getFixedFormatPatternData : replaced return value with null for com/ancientprogramming/fixedformat4j/format/FormatInstructions::getFixedFormatPatternData → KILLED |
return fixedFormatPatternData; |
| 150 | } | |
| 151 | ||
| 152 | /** | |
| 153 | * Returns the boolean value configuration for this field. | |
| 154 | * | |
| 155 | * @return the {@link FixedFormatBooleanData}, or {@code null} if no boolean annotation is present | |
| 156 | */ | |
| 157 | public FixedFormatBooleanData getFixedFormatBooleanData() { | |
| 158 |
1
1. getFixedFormatBooleanData : replaced return value with null for com/ancientprogramming/fixedformat4j/format/FormatInstructions::getFixedFormatBooleanData → KILLED |
return fixedFormatBooleanData; |
| 159 | } | |
| 160 | ||
| 161 | /** | |
| 162 | * Returns the decimal precision configuration for this field. | |
| 163 | * | |
| 164 | * @return the {@link FixedFormatDecimalData}, or {@code null} if no decimal annotation is present | |
| 165 | */ | |
| 166 | public FixedFormatDecimalData getFixedFormatDecimalData() { | |
| 167 |
1
1. getFixedFormatDecimalData : replaced return value with null for com/ancientprogramming/fixedformat4j/format/FormatInstructions::getFixedFormatDecimalData → KILLED |
return fixedFormatDecimalData; |
| 168 | } | |
| 169 | ||
| 170 | /** | |
| 171 | * Returns the number sign configuration for this field. | |
| 172 | * | |
| 173 | * @return the {@link FixedFormatNumberData}, or {@code null} if no number annotation is present | |
| 174 | */ | |
| 175 | public FixedFormatNumberData getFixedFormatNumberData() { | |
| 176 |
1
1. getFixedFormatNumberData : replaced return value with null for com/ancientprogramming/fixedformat4j/format/FormatInstructions::getFixedFormatNumberData → KILLED |
return fixedFormatNumberData; |
| 177 | } | |
| 178 | ||
| 179 | /** | |
| 180 | * Returns the enum format configuration for this field. | |
| 181 | * | |
| 182 | * @return the {@link FixedFormatEnumData}; never {@code null} | |
| 183 | */ | |
| 184 | public FixedFormatEnumData getFixedFormatEnumData() { | |
| 185 |
1
1. getFixedFormatEnumData : replaced return value with null for com/ancientprogramming/fixedformat4j/format/FormatInstructions::getFixedFormatEnumData → KILLED |
return fixedFormatEnumData; |
| 186 | } | |
| 187 | ||
| 188 | public String toString() { | |
| 189 |
5
1. toString : Substituted 9 with 10 → SURVIVED 2. toString : replaced return value with "" for com/ancientprogramming/fixedformat4j/format/FormatInstructions::toString → SURVIVED 3. toString : removed call to java/lang/String::format → SURVIVED 4. toString : replaced call to java/lang/String::format with argument → SURVIVED 5. toString : Substituted 0 with 1 → SURVIVED |
return String.format("FormatInstructions{length=%d, alignment=%s, paddingChar='%c', nullChar='%c', fixedFormatPatternData=%s, fixedFormatBooleanData=%s, fixedFormatNumberData=%s, fixedFormatDecimalData=%s, fixedFormatEnumData=%s}", |
| 190 |
11
1. toString : removed call to java/lang/Integer::valueOf → SURVIVED 2. toString : Substituted 5 with 6 → SURVIVED 3. toString : Substituted 7 with 8 → SURVIVED 4. toString : Substituted 2 with 3 → SURVIVED 5. toString : removed call to java/lang/Character::valueOf → SURVIVED 6. toString : Substituted 3 with 4 → SURVIVED 7. toString : Substituted 4 with 5 → SURVIVED 8. toString : removed call to java/lang/Character::valueOf → SURVIVED 9. toString : Substituted 6 with 7 → SURVIVED 10. toString : Substituted 1 with 0 → KILLED 11. toString : Substituted 8 with 9 → KILLED |
length, alignment, paddingChar, nullChar, fixedFormatPatternData, fixedFormatBooleanData, fixedFormatNumberData, fixedFormatDecimalData, fixedFormatEnumData); |
| 191 | } | |
| 192 | } | |
Mutations | ||
| 93 |
1.1 |
|
| 94 |
1.1 |
|
| 95 |
1.1 |
|
| 96 |
1.1 |
|
| 97 |
1.1 |
|
| 98 |
1.1 |
|
| 99 |
1.1 |
|
| 100 |
1.1 |
|
| 101 |
1.1 |
|
| 110 |
1.1 |
|
| 119 |
1.1 |
|
| 128 |
1.1 |
|
| 140 |
1.1 |
|
| 149 |
1.1 |
|
| 158 |
1.1 |
|
| 167 |
1.1 |
|
| 176 |
1.1 |
|
| 185 |
1.1 |
|
| 189 |
1.1 2.2 3.3 4.4 5.5 |
|
| 190 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9 10.10 11.11 |