Align.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.annotation;
17
18
import org.apache.commons.lang3.StringUtils;
19
20
/**
21
 * Capable of pad or chop data in a given direction
22
 *
23
 * @author Jacob von Eyben - <a href="https://eybenconsult.com">https://eybenconsult.com</a>
24
 * @since 1.0.0
25
 */
26
public enum Align {
27
28
  /**
29
   * Pad or chop data to the left, so the text is aligned to the right
30
   */
31
  RIGHT {
32
    /** {@inheritDoc} */
33
    public String apply(String data, int length, char paddingChar) {
34
      String result;
35 1 1. apply : negated conditional → KILLED
      if (data == null) {
36
        data = "";
37
      }
38
      int dataLength = data.length();
39 2 1. apply : changed conditional boundary → SURVIVED
2. apply : negated conditional → KILLED
      if (dataLength > length) {
40 1 1. apply : Replaced integer subtraction with addition → KILLED
        result = StringUtils.substring(data, dataLength - length, dataLength);
41
      } else {
42
        result = StringUtils.leftPad(data, length, paddingChar);
43
      }
44 1 1. apply : replaced return value with "" for com/ancientprogramming/fixedformat4j/annotation/Align$1::apply → KILLED
      return result;
45
    }
46
    /** {@inheritDoc} */
47
    public String remove(String data, char paddingChar) {
48
      String result = data;
49 1 1. remove : negated conditional → KILLED
      if (data == null) {
50
        result = "";
51
      }
52 1 1. remove : negated conditional → KILLED
      while (result.startsWith(String.valueOf(paddingChar))) {
53
        result = result.substring(1, result.length());
54
      }
55 1 1. remove : replaced return value with "" for com/ancientprogramming/fixedformat4j/annotation/Align$1::remove → KILLED
      return result;
56
    }},
57
58
59
  /**
60
   * Pad or chop data to the right, so the text is aligned to the left
61
   */
62
  LEFT {
63
    /** {@inheritDoc} */
64
    public String apply(String data, int length, char paddingChar) {
65
      String result;
66 1 1. apply : negated conditional → KILLED
      if (data == null) {
67
        data = "";
68
      }
69
      int dataLength = data.length();
70 2 1. apply : changed conditional boundary → SURVIVED
2. apply : negated conditional → KILLED
      if (dataLength > length) {
71
        result = StringUtils.substring(data, 0, length);
72
      } else {
73
        result = StringUtils.rightPad(data, length, paddingChar);
74
      }
75 1 1. apply : replaced return value with "" for com/ancientprogramming/fixedformat4j/annotation/Align$2::apply → KILLED
      return result;
76
    }
77
78
    /** {@inheritDoc} */
79
    public String remove(String data, char paddingChar) {
80
      String result = data;
81 1 1. remove : negated conditional → KILLED
      if (data == null) {
82
        result = "";
83
      }
84 1 1. remove : negated conditional → KILLED
      while (result.endsWith(String.valueOf(paddingChar))) {
85 1 1. remove : Replaced integer subtraction with addition → KILLED
        result = result.substring(0, result.length()-1);
86
      }
87 1 1. remove : replaced return value with "" for com/ancientprogramming/fixedformat4j/annotation/Align$2::remove → KILLED
      return result;
88
    }};
89
90
  /**
91
   * Pads the data in the length specified with the given padding char.
92
   * No padding will be applied if the length of the data is longer than the given length.
93
   *
94
   * @param data        the data to pad.
95
   * @param length      the minimum length after the padding is applied.
96
   * @param paddingChar the char the data is padded with.
97
   * @return the data after padding is applied.
98
   */
99
  public abstract String apply(String data, int length, char paddingChar);
100
101
  /**
102
   * Remove the padding chars from the data.
103
   *
104
   * @param data        the data including padding chars
105
   * @param paddingChar the padding char to remove
106
   * @return the data after padding is removed.
107
   */
108
  public abstract String remove(String data, char paddingChar);
109
}

Mutations

35

1.1
Location : apply
Killed by : com.ancientprogramming.fixedformat4j.annotation.TestAlign.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.annotation.TestAlign]/[method:testStringExactlyAtBoundary()]
negated conditional → KILLED

39

1.1
Location : apply
Killed by : com.ancientprogramming.fixedformat4j.annotation.TestAlign.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.annotation.TestAlign]/[method:testLeftPadding()]
negated conditional → KILLED

2.2
Location : apply
Killed by : none
changed conditional boundary → SURVIVED
Covering tests

40

1.1
Location : apply
Killed by : com.ancientprogramming.fixedformat4j.annotation.TestAlign.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.annotation.TestAlign]/[method:testLeftPadding()]
Replaced integer subtraction with addition → KILLED

44

1.1
Location : apply
Killed by : com.ancientprogramming.fixedformat4j.annotation.TestAlign.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.annotation.TestAlign]/[method:testStringExactlyAtBoundary()]
replaced return value with "" for com/ancientprogramming/fixedformat4j/annotation/Align$1::apply → KILLED

49

1.1
Location : remove
Killed by : com.ancientprogramming.fixedformat4j.annotation.TestAlign.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.annotation.TestAlign]/[method:testLeftRemove()]
negated conditional → KILLED

52

1.1
Location : remove
Killed by : com.ancientprogramming.fixedformat4j.annotation.TestAlign.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.annotation.TestAlign]/[method:testLeftRemove()]
negated conditional → KILLED

55

1.1
Location : remove
Killed by : com.ancientprogramming.fixedformat4j.annotation.TestAlign.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.annotation.TestAlign]/[method:testLeftRemove()]
replaced return value with "" for com/ancientprogramming/fixedformat4j/annotation/Align$1::remove → KILLED

66

1.1
Location : apply
Killed by : com.ancientprogramming.fixedformat4j.annotation.TestAlign.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.annotation.TestAlign]/[method:testStringExactlyAtBoundary()]
negated conditional → KILLED

70

1.1
Location : apply
Killed by : none
changed conditional boundary → SURVIVED
Covering tests

2.2
Location : apply
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestLocalDateTimeFormatter]/[method:testNullFormatReturnsSpaces()]
negated conditional → KILLED

75

1.1
Location : apply
Killed by : com.ancientprogramming.fixedformat4j.annotation.TestAlign.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.annotation.TestAlign]/[method:testStringExactlyAtBoundary()]
replaced return value with "" for com/ancientprogramming/fixedformat4j/annotation/Align$2::apply → KILLED

81

1.1
Location : remove
Killed by : com.ancientprogramming.fixedformat4j.annotation.TestAlign.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.annotation.TestAlign]/[method:testRightRemove()]
negated conditional → KILLED

84

1.1
Location : remove
Killed by : com.ancientprogramming.fixedformat4j.annotation.TestAlign.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.annotation.TestAlign]/[method:testRightRemove()]
negated conditional → KILLED

85

1.1
Location : remove
Killed by : com.ancientprogramming.fixedformat4j.annotation.TestAlign.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.annotation.TestAlign]/[method:testRightRemove()]
Replaced integer subtraction with addition → KILLED

87

1.1
Location : remove
Killed by : com.ancientprogramming.fixedformat4j.annotation.TestAlign.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.annotation.TestAlign]/[method:testRightRemove()]
replaced return value with "" for com/ancientprogramming/fixedformat4j/annotation/Align$2::remove → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.1