| 1 | /*- | |
| 2 | * #%L | |
| 3 | * io.earcam.utilitarian.charstar | |
| 4 | * %% | |
| 5 | * Copyright (C) 2017 - 2018 earcam | |
| 6 | * %% | |
| 7 | * SPDX-License-Identifier: (BSD-3-Clause OR EPL-1.0 OR Apache-2.0 OR MIT) | |
| 8 | * | |
| 9 | * You <b>must</b> choose to accept, in full - any individual or combination of | |
| 10 | * the following licenses: | |
| 11 | * <ul> | |
| 12 | * <li><a href="https://opensource.org/licenses/BSD-3-Clause">BSD-3-Clause</a></li> | |
| 13 | * <li><a href="https://www.eclipse.org/legal/epl-v10.html">EPL-1.0</a></li> | |
| 14 | * <li><a href="https://www.apache.org/licenses/LICENSE-2.0">Apache-2.0</a></li> | |
| 15 | * <li><a href="https://opensource.org/licenses/MIT">MIT</a></li> | |
| 16 | * </ul> | |
| 17 | * #L% | |
| 18 | */ | |
| 19 | package io.earcam.utilitarian.charstar; | |
| 20 | ||
| 21 | import java.io.Externalizable; | |
| 22 | import java.io.IOException; | |
| 23 | import java.io.ObjectInput; | |
| 24 | import java.io.ObjectOutput; | |
| 25 | import java.util.Arrays; | |
| 26 | ||
| 27 | final class CharStar implements CharSequence, Comparable<CharSequence>, Externalizable { | |
| 28 | ||
| 29 | private static final long serialVersionUID = 42L; | |
| 30 | ||
| 31 | private char[] sequence; | |
| 32 | private int offset; | |
| 33 | private int length; | |
| 34 | ||
| 35 | ||
| 36 | public CharStar() | |
| 37 | {} | |
| 38 | ||
| 39 | ||
| 40 | private CharStar(char[] sequence) | |
| 41 | { | |
| 42 | this(sequence, 0, sequence.length); | |
| 43 | } | |
| 44 | ||
| 45 | ||
| 46 | private CharStar(char[] sequence, int offset, int length) | |
| 47 | { | |
| 48 | this.sequence = sequence; | |
| 49 | this.offset = offset; | |
| 50 | this.length = length; | |
| 51 | } | |
| 52 | ||
| 53 | ||
| 54 | static CharStar backedCharSequence(char[] sequence) | |
| 55 | { | |
| 56 |
1
1. backedCharSequence : mutated return of Object value for io/earcam/utilitarian/charstar/CharStar::backedCharSequence to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return new CharStar(sequence); |
| 57 | } | |
| 58 | ||
| 59 | ||
| 60 | static CharStar charSequence(char[] sequence) | |
| 61 | { | |
| 62 | char[] encapsulated = Arrays.copyOf(sequence, sequence.length); | |
| 63 |
1
1. charSequence : mutated return of Object value for io/earcam/utilitarian/charstar/CharStar::charSequence to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return new CharStar(encapsulated); |
| 64 | } | |
| 65 | ||
| 66 | ||
| 67 | @Override | |
| 68 | public boolean equals(Object other) | |
| 69 | { | |
| 70 |
3
1. equals : negated conditional → KILLED 2. equals : negated conditional → KILLED 3. equals : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return other instanceof CharStar && equals((CharStar) other); |
| 71 | } | |
| 72 | ||
| 73 | ||
| 74 | public boolean equals(CharStar that) | |
| 75 | { | |
| 76 |
3
1. equals : negated conditional → KILLED 2. equals : negated conditional → KILLED 3. equals : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return that != null && CharSequences.same(this, that); |
| 77 | } | |
| 78 | ||
| 79 | ||
| 80 | @Override | |
| 81 | public int hashCode() | |
| 82 | { | |
| 83 |
1
1. hashCode : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return CharSequences.hashCode(this); |
| 84 | } | |
| 85 | ||
| 86 | ||
| 87 | @Override | |
| 88 | public String toString() | |
| 89 | { | |
| 90 |
1
1. toString : mutated return of Object value for io/earcam/utilitarian/charstar/CharStar::toString to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return String.valueOf(sequence, offset, length); |
| 91 | } | |
| 92 | ||
| 93 | ||
| 94 | @Override | |
| 95 | public int length() | |
| 96 | { | |
| 97 |
1
1. length : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return length; |
| 98 | } | |
| 99 | ||
| 100 | ||
| 101 | @Override | |
| 102 | public char charAt(int index) | |
| 103 | { | |
| 104 |
2
1. charAt : Replaced integer addition with subtraction → KILLED 2. charAt : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return sequence[offset + index]; |
| 105 | } | |
| 106 | ||
| 107 | ||
| 108 | @Override | |
| 109 | public CharStar subSequence(int start, int end) | |
| 110 | { | |
| 111 |
1
1. subSequence : removed call to io/earcam/utilitarian/charstar/CharStar::requireValidIndices → KILLED |
requireValidIndices(start, end); |
| 112 |
2
1. subSequence : Replaced integer subtraction with addition → KILLED 2. subSequence : mutated return of Object value for io/earcam/utilitarian/charstar/CharStar::subSequence to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return new CharStar(sequence, start, end - start); |
| 113 | } | |
| 114 | ||
| 115 | ||
| 116 | private void requireValidIndices(int start, int end) | |
| 117 | { | |
| 118 |
1
1. requireValidIndices : removed call to io/earcam/utilitarian/charstar/CharStar::requireNonNegative → KILLED |
requireNonNegative("start", start); |
| 119 |
1
1. requireValidIndices : removed call to io/earcam/utilitarian/charstar/CharStar::requireNonNegative → SURVIVED |
requireNonNegative("end", end); |
| 120 |
1
1. requireValidIndices : removed call to io/earcam/utilitarian/charstar/CharStar::requireLessThanOrEqualTo → SURVIVED |
requireLessThanOrEqualTo("end", end, "length", length); |
| 121 |
1
1. requireValidIndices : removed call to io/earcam/utilitarian/charstar/CharStar::requireLessThanOrEqualTo → KILLED |
requireLessThanOrEqualTo("start", start, "end", end); |
| 122 | } | |
| 123 | ||
| 124 | ||
| 125 | private void requireNonNegative(String name, int value) | |
| 126 | { | |
| 127 |
2
1. requireNonNegative : changed conditional boundary → SURVIVED 2. requireNonNegative : negated conditional → KILLED |
if(value < 0) { |
| 128 | throw new IndexOutOfBoundsException(name + " is less than zero: " + value); | |
| 129 | } | |
| 130 | } | |
| 131 | ||
| 132 | ||
| 133 | private void requireLessThanOrEqualTo(String lhs, int lhsValue, String rhs, int rhsValue) | |
| 134 | { | |
| 135 |
2
1. requireLessThanOrEqualTo : changed conditional boundary → KILLED 2. requireLessThanOrEqualTo : negated conditional → KILLED |
if(lhsValue > rhsValue) { |
| 136 | throw new IndexOutOfBoundsException(lhs + " > " + rhs + ": " + lhsValue + " > " + rhsValue); | |
| 137 | } | |
| 138 | } | |
| 139 | ||
| 140 | ||
| 141 | public int compareTo(CharSequence that) | |
| 142 | { | |
| 143 | int max = Math.min(this.length, that.length()); | |
| 144 | int i = 0; | |
| 145 |
2
1. compareTo : changed conditional boundary → KILLED 2. compareTo : negated conditional → KILLED |
while(i < max) { |
| 146 |
1
1. compareTo : Replaced integer addition with subtraction → KILLED |
char c1 = sequence[offset + i]; |
| 147 | char c2 = that.charAt(i); | |
| 148 |
1
1. compareTo : negated conditional → KILLED |
if(c1 != c2) { |
| 149 |
2
1. compareTo : Replaced integer subtraction with addition → KILLED 2. compareTo : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return c1 - c2; |
| 150 | } | |
| 151 |
1
1. compareTo : Changed increment from 1 to -1 → KILLED |
i++; |
| 152 | } | |
| 153 |
2
1. compareTo : Replaced integer subtraction with addition → KILLED 2. compareTo : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return this.length - that.length(); |
| 154 | } | |
| 155 | ||
| 156 | ||
| 157 | @Override | |
| 158 | public void writeExternal(ObjectOutput out) throws IOException | |
| 159 | { | |
| 160 |
1
1. writeExternal : removed call to java/io/ObjectOutput::writeInt → KILLED |
out.writeInt(length); |
| 161 |
4
1. writeExternal : changed conditional boundary → SURVIVED 2. writeExternal : Changed increment from 1 to -1 → KILLED 3. writeExternal : Replaced integer addition with subtraction → KILLED 4. writeExternal : negated conditional → KILLED |
for(int i = offset; i < offset + length; i++) { |
| 162 |
1
1. writeExternal : removed call to java/io/ObjectOutput::writeChar → KILLED |
out.writeChar(sequence[i]); |
| 163 | } | |
| 164 | } | |
| 165 | ||
| 166 | ||
| 167 | @Override | |
| 168 | public void readExternal(ObjectInput in) throws IOException | |
| 169 | { | |
| 170 | length = in.readInt(); | |
| 171 | sequence = new char[length]; | |
| 172 |
3
1. readExternal : changed conditional boundary → KILLED 2. readExternal : Changed increment from 1 to -1 → KILLED 3. readExternal : negated conditional → KILLED |
for(int i = 0; i < length; i++) { |
| 173 | sequence[i] = in.readChar(); | |
| 174 | } | |
| 175 | } | |
| 176 | ||
| 177 | ||
| 178 | public char[] toArray() | |
| 179 | { | |
| 180 | char[] dest = new char[length]; | |
| 181 |
1
1. toArray : removed call to java/lang/System::arraycopy → KILLED |
System.arraycopy(sequence, offset, dest, 0, length); |
| 182 |
1
1. toArray : mutated return of Object value for io/earcam/utilitarian/charstar/CharStar::toArray to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return dest; |
| 183 | } | |
| 184 | } | |
Mutations | ||
| 56 |
1.1 |
|
| 63 |
1.1 |
|
| 70 |
1.1 2.2 3.3 |
|
| 76 |
1.1 2.2 3.3 |
|
| 83 |
1.1 |
|
| 90 |
1.1 |
|
| 97 |
1.1 |
|
| 104 |
1.1 2.2 |
|
| 111 |
1.1 |
|
| 112 |
1.1 2.2 |
|
| 118 |
1.1 |
|
| 119 |
1.1 |
|
| 120 |
1.1 |
|
| 121 |
1.1 |
|
| 127 |
1.1 2.2 |
|
| 135 |
1.1 2.2 |
|
| 145 |
1.1 2.2 |
|
| 146 |
1.1 |
|
| 148 |
1.1 |
|
| 149 |
1.1 2.2 |
|
| 151 |
1.1 |
|
| 153 |
1.1 2.2 |
|
| 160 |
1.1 |
|
| 161 |
1.1 2.2 3.3 4.4 |
|
| 162 |
1.1 |
|
| 172 |
1.1 2.2 3.3 |
|
| 181 |
1.1 |
|
| 182 |
1.1 |