FormatContext.java

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
 * Contains context for loading and exporting fixedformat data.
20
 * The context describes what kind of formatter to use, what datatype to convert and what offset to fetch data from.
21
 *
22
 * @author Jacob von Eyben - <a href="https://eybenconsult.com">https://eybenconsult.com</a>
23
 * @since 1.0.0
24
 */
25
public class FormatContext<T> {
26
27
  private final int offset;
28
  private final Class<T> dataType;
29
  private final Class<? extends FixedFormatter<T>> formatter;
30
31
  /**
32
   * Creates a new format context.
33
   *
34
   * @param offset    the 1-based character offset of the field within the record
35
   * @param dataType  the Java type of the field value
36
   * @param formatter the formatter class to use for this field
37
   */
38
  public FormatContext(int offset, Class<T> dataType, Class<? extends FixedFormatter<T>> formatter) {
39 1 1. <init> : Removed assignment to member variable offset → KILLED
    this.offset = offset;
40 1 1. <init> : Removed assignment to member variable dataType → KILLED
    this.dataType = dataType;
41 1 1. <init> : Removed assignment to member variable formatter → KILLED
    this.formatter = formatter;
42
  }
43
44
  /**
45
   * Returns the 1-based character offset of the field within the record.
46
   *
47
   * @return the field offset
48
   */
49
  public int getOffset() {
50 1 1. getOffset : replaced int return with 0 for com/ancientprogramming/fixedformat4j/format/FormatContext::getOffset → KILLED
    return offset;
51
  }
52
53
  /**
54
   * Returns the Java type of the field value.
55
   *
56
   * @return the data type class
57
   */
58
  public Class<T> getDataType() {
59 1 1. getDataType : replaced return value with null for com/ancientprogramming/fixedformat4j/format/FormatContext::getDataType → KILLED
    return dataType;
60
  }
61
62
  /**
63
   * Returns the formatter class responsible for parsing and formatting this field.
64
   *
65
   * @return the formatter class
66
   */
67
  public Class<? extends FixedFormatter<T>> getFormatter() {
68 1 1. getFormatter : replaced return value with null for com/ancientprogramming/fixedformat4j/format/FormatContext::getFormatter → KILLED
    return formatter;
69
  }
70
71
72
  public String toString() {
73 10 1. toString : removed call to java/lang/Integer::valueOf → SURVIVED
2. toString : Substituted 0 with 1 → SURVIVED
3. toString : Substituted 3 with 4 → SURVIVED
4. toString : replaced return value with "" for com/ancientprogramming/fixedformat4j/format/FormatContext::toString → SURVIVED
5. toString : removed call to java/lang/Class::getName → SURVIVED
6. toString : removed call to java/lang/Class::getName → SURVIVED
7. toString : replaced call to java/lang/String::format with argument → SURVIVED
8. toString : removed call to java/lang/String::format → SURVIVED
9. toString : Substituted 1 with 0 → KILLED
10. toString : Substituted 2 with 3 → KILLED
    return String.format("FormatContext{offset=%d, dataType=%s, formatter=%s}", offset, dataType.getName(), formatter.getName());
74
  }
75
}

Mutations

39

1.1
Location : <init>
Killed by : com.ancientprogramming.fixedformat4j.format.TestFixedFormatUtilExtended.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.TestFixedFormatUtilExtended]/[method:fetchData_fieldExactlyFillsRecord()]
Removed assignment to member variable offset → KILLED

40

1.1
Location : <init>
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestFormatInstructionsBuilder.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestFormatInstructionsBuilder]/[method:context_fromFieldAnnotation_hasCorrectOffsetAndType()]
Removed assignment to member variable dataType → KILLED

41

1.1
Location : <init>
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestFormatInstructionsBuilder.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestFormatInstructionsBuilder]/[method:context_fromFieldAnnotation_capturesFormatterClass()]
Removed assignment to member variable formatter → KILLED

50

1.1
Location : getOffset
Killed by : com.ancientprogramming.fixedformat4j.format.TestFixedFormatUtilExtended.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.TestFixedFormatUtilExtended]/[method:fetchData_firstField_offset1()]
replaced int return with 0 for com/ancientprogramming/fixedformat4j/format/FormatContext::getOffset → KILLED

59

1.1
Location : getDataType
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestFormatInstructionsBuilder.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestFormatInstructionsBuilder]/[method:context_fromFieldAnnotation_hasCorrectOffsetAndType()]
replaced return value with null for com/ancientprogramming/fixedformat4j/format/FormatContext::getDataType → KILLED

68

1.1
Location : getFormatter
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestFormatInstructionsBuilder.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestFormatInstructionsBuilder]/[method:context_fromFieldAnnotation_capturesFormatterClass()]
replaced return value with null for com/ancientprogramming/fixedformat4j/format/FormatContext::getFormatter → KILLED

73

1.1
Location : toString
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImplErrors.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImplErrors]/[method:load_unparsableData_throwsParseException()]
Substituted 1 with 0 → KILLED

2.2
Location : toString
Killed by : none
removed call to java/lang/Integer::valueOf → SURVIVED
Covering tests

3.3
Location : toString
Killed by : none
Substituted 0 with 1 → SURVIVED Covering tests

4.4
Location : toString
Killed by : none
Substituted 3 with 4 → SURVIVED Covering tests

5.5
Location : toString
Killed by : none
replaced return value with "" for com/ancientprogramming/fixedformat4j/format/FormatContext::toString → SURVIVED Covering tests

6.6
Location : toString
Killed by : none
removed call to java/lang/Class::getName → SURVIVED Covering tests

7.7
Location : toString
Killed by : none
removed call to java/lang/Class::getName → SURVIVED Covering tests

8.8
Location : toString
Killed by : none
replaced call to java/lang/String::format with argument → SURVIVED Covering tests

9.9
Location : toString
Killed by : none
removed call to java/lang/String::format → SURVIVED Covering tests

10.10
Location : toString
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImplErrors.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImplErrors]/[method:load_unparsableData_throwsParseException()]
Substituted 2 with 3 → KILLED

Active mutators

Tests examined


Report generated by PIT 1.23.1 support