Skip to content

Commit 08628f5

Browse files
authored
Rename ByteArrayAlelle to SimpleAllele and make it public (#1576)
* Rename ByteArrayAlelle to SimpleAllele and make it public * When we refactored Allele into an interface we made the implementation package protected which broke downstream code which previously subclasseed Allele. Now code can subclass SimpleAllele instead.
1 parent b2b31ab commit 08628f5

2 files changed

Lines changed: 33 additions & 27 deletions

File tree

src/main/java/htsjdk/variant/variantcontext/Allele.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
package htsjdk.variant.variantcontext;
2727

2828
import java.io.Serializable;
29-
import java.util.Collection;
3029

3130
/**
3231
* Immutable representation of an allele.
@@ -128,20 +127,20 @@ public interface Allele extends Comparable<Allele>, Serializable {
128127

129128
String NON_REF_STRING = "<NON_REF>";
130129
String UNSPECIFIED_ALTERNATE_ALLELE_STRING = "<*>";
131-
Allele REF_A = new ByteArrayAllele("A", true);
132-
Allele ALT_A = new ByteArrayAllele("A", false);
133-
Allele REF_C = new ByteArrayAllele("C", true);
134-
Allele ALT_C = new ByteArrayAllele("C", false);
135-
Allele REF_G = new ByteArrayAllele("G", true);
136-
Allele ALT_G = new ByteArrayAllele("G", false);
137-
Allele REF_T = new ByteArrayAllele("T", true);
138-
Allele ALT_T = new ByteArrayAllele("T", false);
139-
Allele REF_N = new ByteArrayAllele("N", true);
140-
Allele ALT_N = new ByteArrayAllele("N", false);
141-
Allele SPAN_DEL = new ByteArrayAllele(SPAN_DEL_STRING, false);
142-
Allele NO_CALL = new ByteArrayAllele(NO_CALL_STRING, false);
143-
Allele NON_REF_ALLELE = new ByteArrayAllele(NON_REF_STRING, false);
144-
Allele UNSPECIFIED_ALTERNATE_ALLELE = new ByteArrayAllele(UNSPECIFIED_ALTERNATE_ALLELE_STRING, false);
130+
Allele REF_A = new SimpleAllele("A", true);
131+
Allele ALT_A = new SimpleAllele("A", false);
132+
Allele REF_C = new SimpleAllele("C", true);
133+
Allele ALT_C = new SimpleAllele("C", false);
134+
Allele REF_G = new SimpleAllele("G", true);
135+
Allele ALT_G = new SimpleAllele("G", false);
136+
Allele REF_T = new SimpleAllele("T", true);
137+
Allele ALT_T = new SimpleAllele("T", false);
138+
Allele REF_N = new SimpleAllele("N", true);
139+
Allele ALT_N = new SimpleAllele("N", false);
140+
Allele SPAN_DEL = new SimpleAllele(SPAN_DEL_STRING, false);
141+
Allele NO_CALL = new SimpleAllele(NO_CALL_STRING, false);
142+
Allele NON_REF_ALLELE = new SimpleAllele(NON_REF_STRING, false);
143+
Allele UNSPECIFIED_ALTERNATE_ALLELE = new SimpleAllele(UNSPECIFIED_ALTERNATE_ALLELE_STRING, false);
145144

146145
// for simple deletion, e.g. "ALT==<DEL>" (note that the spec allows, for now at least, alt alleles like <DEL:ME>)
147146
@SuppressWarnings("unused")
@@ -188,7 +187,7 @@ static Allele create(byte[] bases, boolean isRef) {
188187
default: throw new IllegalArgumentException("Illegal base [" + (char)bases[0] + "] seen in the allele");
189188
}
190189
} else {
191-
return new ByteArrayAllele(bases.clone(), isRef);
190+
return new SimpleAllele(bases.clone(), isRef);
192191
}
193192
}
194193

@@ -372,12 +371,13 @@ static Allele create(byte[] bases) {
372371
* (in which case the returned allele will be non-Ref).
373372
*
374373
* This method is efficient because it can skip the validation of the bases (since the original allele was already validated)
374+
375375
*
376376
* @param allele the allele from which to copy the bases
377377
* @param ignoreRefState should we ignore the reference state of the input allele and use the default ref state?
378378
*/
379379
static Allele create(Allele allele, boolean ignoreRefState) {
380-
return new ByteArrayAllele(allele.getBases(), allele.isReference() && !ignoreRefState);
380+
return new SimpleAllele(allele.getBases(), allele.isReference() && !ignoreRefState);
381381
}
382382

383383
static boolean oneIsPrefixOfOther(final Allele a1, final Allele a2) {

src/main/java/htsjdk/variant/variantcontext/ByteArrayAllele.java renamed to src/main/java/htsjdk/variant/variantcontext/SimpleAllele.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,19 @@
2727

2828
import htsjdk.samtools.util.StringUtil;
2929

30-
import java.nio.charset.Charset;
3130
import java.nio.charset.StandardCharsets;
3231
import java.util.Arrays;
3332

34-
class ByteArrayAllele implements Allele {
33+
/**
34+
* An implementation of {@link Allele} which includes a byte[] of the bases in the allele or the symbolic name.
35+
*
36+
* This has been made public as a base for classes which need to subclass Allele.
37+
*
38+
* Most users should create alleles using {@link Allele#create(byte[])} instead of interacting with this class directly.
39+
*/
40+
public class SimpleAllele implements Allele {
3541

36-
private static long serialVersionUID = 1L;
42+
private static final long serialVersionUID = 1L;
3743

3844
private static final byte[] EMPTY_ALLELE_BASES = new byte[0];
3945

@@ -44,7 +50,7 @@ class ByteArrayAllele implements Allele {
4450
private byte[] bases = null;
4551

4652
// no public way to create an allele
47-
protected ByteArrayAllele(final byte[] bases, final boolean isRef) {
53+
protected SimpleAllele(final byte[] bases, final boolean isRef) {
4854
// null alleles are no longer allowed
4955
if ( Allele.wouldBeNullAllele(bases) ) {
5056
throw new IllegalArgumentException("Null alleles are not supported");
@@ -73,7 +79,7 @@ protected ByteArrayAllele(final byte[] bases, final boolean isRef) {
7379
throw new IllegalArgumentException("Unexpected base in allele bases \'" + new String(bases)+"\'");
7480
}
7581

76-
protected ByteArrayAllele(final String bases, final boolean isRef) {
82+
protected SimpleAllele(final String bases, final boolean isRef) {
7783
this(bases.getBytes(), isRef);
7884
}
7985

@@ -86,7 +92,7 @@ protected ByteArrayAllele(final String bases, final boolean isRef) {
8692
* @param allele the allele from which to copy the bases
8793
* @param ignoreRefState should we ignore the reference state of the input allele and use the default ref state?
8894
*/
89-
protected ByteArrayAllele(final ByteArrayAllele allele, final boolean ignoreRefState) {
95+
protected SimpleAllele(final SimpleAllele allele, final boolean ignoreRefState) {
9096
this.bases = allele.bases;
9197
this.isRef = ignoreRefState ? false : allele.isRef;
9298
this.isNoCall = allele.isNoCall;
@@ -97,8 +103,8 @@ protected ByteArrayAllele(final ByteArrayAllele allele, final boolean ignoreRefS
97103
public boolean isPrefixOf(final Allele other) {
98104
if (other.length() < this.length()) {
99105
return false;
100-
} else if (other instanceof ByteArrayAllele) {
101-
final ByteArrayAllele baOther = (ByteArrayAllele) other;
106+
} else if (other instanceof SimpleAllele) {
107+
final SimpleAllele baOther = (SimpleAllele) other;
102108
return isPrefixOfBytes(baOther.bases);
103109
} else {
104110
return isPrefixOfBytes(other.getBases());
@@ -255,8 +261,8 @@ public int compareTo(final Allele other) {
255261
return -1;
256262
else if ( isNonReference() && other.isReference() )
257263
return 1;
258-
else if (other instanceof ByteArrayAllele) {
259-
final ByteArrayAllele baOther = (ByteArrayAllele) other;
264+
else if (other instanceof SimpleAllele) {
265+
final SimpleAllele baOther = (SimpleAllele) other;
260266
return compareBases(baOther.bases);
261267
} else {
262268
return compareBases(other.getBases());

0 commit comments

Comments
 (0)