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 int offset;
28
  private Class<T> dataType;
29
  private 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
    this.offset = offset;
40
    this.dataType = dataType;
41
    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 1 1. toString : replaced return value with "" for com/ancientprogramming/fixedformat4j/format/FormatContext::toString → SURVIVED
    return String.format("FormatContext{offset=%d, dataType=%s, formatter=%s}", offset, dataType.getName(), formatter.getName());
74
  }
75
}

Mutations

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.TestRepeatingFieldSupport.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestRepeatingFieldSupport]/[method:read_repeatingField_parsesAllElements()]
replaced return value with null for com/ancientprogramming/fixedformat4j/format/FormatContext::getFormatter → KILLED

73

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

Active mutators

Tests examined


Report generated by PIT 1.17.1