| 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 com.ancientprogramming.fixedformat4j.annotation.Record; | |
| 19 | ||
| 20 | import java.util.Objects; | |
| 21 | ||
| 22 | import static java.lang.String.format; | |
| 23 | ||
| 24 | /** | |
| 25 | * Immutable pair of a {@link LinePattern} and the | |
| 26 | * {@link com.ancientprogramming.fixedformat4j.annotation.Record}-annotated class to | |
| 27 | * instantiate when the pattern matches a line. | |
| 28 | * | |
| 29 | * <p>The constructor validates that {@code recordClass} carries the {@code @Record} annotation | |
| 30 | * so that misconfigured mappings fail fast at reader-build time rather than at parse time.</p> | |
| 31 | * | |
| 32 | * @param <T> the type of record produced by this mapping | |
| 33 | * @author Jacob von Eyben - <a href="https://eybenconsult.com">https://eybenconsult.com</a> | |
| 34 | * @since 1.8.0 | |
| 35 | */ | |
| 36 | public final class RecordMapping<T> { | |
| 37 | ||
| 38 | private final Class<T> recordClass; | |
| 39 | private final LinePattern pattern; | |
| 40 | ||
| 41 | /** | |
| 42 | * Creates a new mapping. Package-private: instances are produced by | |
| 43 | * {@link FixedFormatReaderBuilder#addMapping(Class, LinePattern)} and surface to user code only | |
| 44 | * through {@link MultiMatchStrategy#resolve(java.util.List, long)}. | |
| 45 | * | |
| 46 | * @param recordClass the class to instantiate when {@code pattern} matches; must be | |
| 47 | * annotated with {@link com.ancientprogramming.fixedformat4j.annotation.Record} | |
| 48 | * @param pattern the line pattern that decides which lines are parsed as {@code recordClass} | |
| 49 | * @throws IllegalArgumentException if {@code recordClass} is not annotated with {@code @Record} | |
| 50 | * @throws NullPointerException if {@code recordClass} or {@code pattern} is null | |
| 51 | */ | |
| 52 | RecordMapping(Class<T> recordClass, LinePattern pattern) { | |
| 53 |
2
1. <init> : removed call to java/util/Objects::requireNonNull → SURVIVED 2. <init> : replaced call to java/util/Objects::requireNonNull with argument → SURVIVED |
Objects.requireNonNull(recordClass, "recordClass must not be null"); |
| 54 |
2
1. <init> : removed call to java/util/Objects::requireNonNull → KILLED 2. <init> : replaced call to java/util/Objects::requireNonNull with argument → KILLED |
Objects.requireNonNull(pattern, "pattern must not be null"); |
| 55 |
4
1. <init> : removed conditional - replaced equality check with true → KILLED 2. <init> : removed call to java/lang/Class::getAnnotation → KILLED 3. <init> : removed conditional - replaced equality check with false → KILLED 4. <init> : negated conditional → KILLED |
if (recordClass.getAnnotation(Record.class) == null) { |
| 56 |
2
1. <init> : Substituted 0 with 1 → KILLED 2. <init> : Substituted 1 with 0 → KILLED |
throw new IllegalArgumentException( |
| 57 |
4
1. <init> : removed call to java/lang/IllegalArgumentException::<init> → KILLED 2. <init> : replaced call to java/lang/String::format with argument → KILLED 3. <init> : removed call to java/lang/String::format → KILLED 4. <init> : removed call to java/lang/Class::getSimpleName → KILLED |
format("%s is not annotated with @Record", recordClass.getSimpleName())); |
| 58 | } | |
| 59 |
1
1. <init> : Removed assignment to member variable recordClass → KILLED |
this.recordClass = recordClass; |
| 60 |
1
1. <init> : Removed assignment to member variable pattern → KILLED |
this.pattern = pattern; |
| 61 | } | |
| 62 | ||
| 63 | /** | |
| 64 | * Returns the {@code @Record}-annotated class associated with this mapping. | |
| 65 | * | |
| 66 | * @return the record class; never {@code null} | |
| 67 | */ | |
| 68 | public Class<T> getRecordClass() { | |
| 69 |
1
1. getRecordClass : replaced return value with null for com/ancientprogramming/fixedformat4j/io/read/RecordMapping::getRecordClass → KILLED |
return recordClass; |
| 70 | } | |
| 71 | ||
| 72 | /** | |
| 73 | * Returns the line pattern used to decide whether a line should be parsed as | |
| 74 | * {@link #getRecordClass()}. | |
| 75 | * | |
| 76 | * @return the line pattern; never {@code null} | |
| 77 | */ | |
| 78 | public LinePattern getPattern() { | |
| 79 |
1
1. getPattern : replaced return value with null for com/ancientprogramming/fixedformat4j/io/read/RecordMapping::getPattern → KILLED |
return pattern; |
| 80 | } | |
| 81 | } | |
Mutations | ||
| 53 |
1.1 2.2 |
|
| 54 |
1.1 2.2 |
|
| 55 |
1.1 2.2 3.3 4.4 |
|
| 56 |
1.1 2.2 |
|
| 57 |
1.1 2.2 3.3 4.4 |
|
| 59 |
1.1 |
|
| 60 |
1.1 |
|
| 69 |
1.1 |
|
| 79 |
1.1 |