Skip to content

Commit dbcf542

Browse files
committed
Merge branch 'sequenceEquals' of https://github.com/valasatava/biojava into sequenceEquals
2 parents 3834d4b + 7e0559b commit dbcf542

File tree

9 files changed

+102
-39
lines changed

9 files changed

+102
-39
lines changed

biojava-core/src/main/java/org/biojava/nbio/core/alignment/SimpleAlignedSequence.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.biojava.nbio.core.sequence.location.template.Location;
3232
import org.biojava.nbio.core.sequence.location.template.Point;
3333
import org.biojava.nbio.core.sequence.template.*;
34+
import org.biojava.nbio.core.util.Equals;
3435

3536
import java.io.Serializable;
3637
import java.util.ArrayList;
@@ -269,6 +270,26 @@ public List<C> getAsList() {
269270
return compounds;
270271
}
271272

273+
274+
public boolean equals(Object o){
275+
276+
if(! Equals.classEqual(this, o)) {
277+
return false;
278+
}
279+
280+
Sequence<C> other = (Sequence<C>)o;
281+
282+
if ( original.getAsList().size() != other.getAsList().size())
283+
return false;
284+
285+
for ( int i = 0 ; i< original.getAsList().size() ; i++){
286+
if ( ! original.getAsList().get(i).equalsIgnoreCase(other.getAsList().get(i)))
287+
return false;
288+
}
289+
290+
return true;
291+
}
292+
272293
@Override
273294
public boolean equals(Sequence<C>other){
274295
if ( original.getAsList().size() != other.getAsList().size())

biojava-core/src/main/java/org/biojava/nbio/core/sequence/loader/SequenceFileProxyLoader.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.biojava.nbio.core.sequence.io.template.SequenceParserInterface;
3232
import org.biojava.nbio.core.sequence.storage.SequenceAsStringHelper;
3333
import org.biojava.nbio.core.sequence.template.*;
34+
import org.biojava.nbio.core.util.Equals;
3435

3536
import java.io.BufferedReader;
3637
import java.io.File;
@@ -219,7 +220,14 @@ public List<C> getAsList() {
219220
}
220221

221222
@Override
222-
public boolean equals(Sequence<C> other) {
223+
public boolean equals(Object o) {
224+
225+
if(! Equals.classEqual(this, o)) {
226+
return false;
227+
}
228+
229+
Sequence<C> other = (Sequence<C>)o;
230+
223231

224232
if ( other.getCompoundSet() != getCompoundSet())
225233
return false;
@@ -242,12 +250,6 @@ public boolean equals(Sequence<C> other) {
242250

243251
}
244252

245-
@Override
246-
public int hashCode(){
247-
String s = getSequenceAsString();
248-
return s.hashCode();
249-
}
250-
251253
/**
252254
*
253255
* @param bioBegin

biojava-core/src/main/java/org/biojava/nbio/core/sequence/loader/StringProxySequenceReader.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.biojava.nbio.core.sequence.Strand;
3131
import org.biojava.nbio.core.sequence.storage.SequenceAsStringHelper;
3232
import org.biojava.nbio.core.sequence.template.*;
33+
import org.biojava.nbio.core.util.Equals;
3334

3435
import java.util.ArrayList;
3536
import java.util.Iterator;
@@ -161,8 +162,15 @@ public SequenceView<C> getInverse() {
161162
return SequenceMixin.inverse(this);
162163
}
163164

164-
@Override
165-
public boolean equals(Sequence<C> other){
165+
166+
public boolean equals(Object o){
167+
168+
if(! Equals.classEqual(this, o)) {
169+
return false;
170+
}
171+
172+
Sequence<C> other = (Sequence<C>)o;
173+
166174
if ( other.getCompoundSet() != getCompoundSet())
167175
return false;
168176

biojava-core/src/main/java/org/biojava/nbio/core/sequence/loader/UniprotProxySequenceReader.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.biojava.nbio.core.sequence.features.FeaturesKeyWordInterface;
3737
import org.biojava.nbio.core.sequence.storage.SequenceAsStringHelper;
3838
import org.biojava.nbio.core.sequence.template.*;
39+
import org.biojava.nbio.core.util.Equals;
3940
import org.biojava.nbio.core.util.XMLHelper;
4041
import org.slf4j.Logger;
4142
import org.slf4j.LoggerFactory;
@@ -231,10 +232,15 @@ public List<C> getAsList() {
231232
}
232233

233234
@Override
234-
public boolean equals(Sequence<C> other){
235-
if ( other.getCompoundSet() != getCompoundSet())
235+
public boolean equals(Object o){
236+
237+
if(! Equals.classEqual(this, o)) {
236238
return false;
239+
}
237240

241+
Sequence<C> other = (Sequence<C>)o;
242+
if ( other.getCompoundSet() != getCompoundSet())
243+
return false;
238244

239245
List<C> rawCompounds = getAsList();
240246
List<C> otherCompounds = other.getAsList();
@@ -248,10 +254,7 @@ public boolean equals(Sequence<C> other){
248254
if ( ! myCompound.equalsIgnoreCase(otherCompound))
249255
return false;
250256
}
251-
252257
return true;
253-
254-
255258
}
256259

257260
/**

biojava-core/src/main/java/org/biojava/nbio/core/sequence/storage/ArrayListSequenceReader.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,6 @@ public String getSequenceAsString() {
8585
return getSequenceAsString(1, getLength(), Strand.POSITIVE);
8686
}
8787

88-
public boolean equals(Sequence<C>other){
89-
if ( parsedCompounds.size() != other.getAsList().size())
90-
return false;
91-
92-
for ( int i = 0 ; i< parsedCompounds.size() ; i++){
93-
if ( ! parsedCompounds.get(i).equalsIgnoreCase(other.getAsList().get(i)))
94-
return false;
95-
}
96-
97-
return true;
98-
}
9988

10089
/**
10190
*

biojava-core/src/main/java/org/biojava/nbio/core/sequence/storage/BitSequenceReader.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -199,18 +199,6 @@ public boolean equals(Object o) {
199199
return false;
200200
}
201201

202-
public boolean equals(Sequence<C> o){
203-
204-
if(Equals.classEqual(this, o)) {
205-
@SuppressWarnings("unchecked")
206-
BitSequenceReader<C> that = (BitSequenceReader<C>)o;
207-
return Equals.equal(this.accession, that.accession) &&
208-
Equals.equal(this.worker, that.worker);
209-
}
210-
return false;
211-
212-
}
213-
214202
/**
215203
* The logic of working with a bit has been separated out into this class
216204
* to help developers create the bit data structures without having to

biojava-core/src/main/java/org/biojava/nbio/core/sequence/storage/JoiningSequenceReader.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.biojava.nbio.core.exceptions.CompoundNotFoundException;
2424
import org.biojava.nbio.core.sequence.AccessionID;
2525
import org.biojava.nbio.core.sequence.template.*;
26+
import org.biojava.nbio.core.util.Equals;
2627

2728
import java.util.*;
2829

@@ -322,6 +323,37 @@ public boolean equals(Sequence<C> other) {
322323
}
323324

324325

326+
public boolean equals(Sequence<C> o) {
327+
328+
329+
if(! Equals.classEqual(this, o)) {
330+
return false;
331+
}
332+
333+
Sequence<C> other = (Sequence<C>)o;
334+
335+
336+
if ( other.getCompoundSet() != getCompoundSet())
337+
return false;
338+
339+
340+
List<C> rawCompounds = getAsList();
341+
List<C> otherCompounds = other.getAsList();
342+
343+
if ( rawCompounds.size() != otherCompounds.size())
344+
return false;
345+
346+
for (int i = 0 ; i < rawCompounds.size() ; i++){
347+
Compound myCompound = rawCompounds.get(i);
348+
Compound otherCompound = otherCompounds.get(i);
349+
if ( ! myCompound.equalsIgnoreCase(otherCompound))
350+
return false;
351+
}
352+
353+
return true;
354+
}
355+
356+
325357
@Override
326358
public int getIndexOf(C compound) {
327359
return SequenceMixin.indexOf(this, compound);

biojava-core/src/main/java/org/biojava/nbio/core/sequence/template/AbstractSequence.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.biojava.nbio.core.sequence.location.SimpleLocation;
3838
import org.biojava.nbio.core.sequence.location.template.Location;
3939
import org.biojava.nbio.core.sequence.storage.ArrayListSequenceReader;
40+
import org.biojava.nbio.core.util.Equals;
4041
import org.slf4j.Logger;
4142
import org.slf4j.LoggerFactory;
4243

@@ -519,8 +520,14 @@ public void setCompoundSet(CompoundSet<C> compoundSet) {
519520
this.compoundSet = compoundSet;
520521
}
521522

523+
public boolean equals(Object o){
524+
525+
if(! Equals.classEqual(this, o)) {
526+
return false;
527+
}
528+
529+
Sequence<C> other = (Sequence<C>)o;
522530

523-
public boolean equals(Sequence<C> other){
524531
if ( other.getCompoundSet() != getCompoundSet())
525532
return false;
526533

@@ -537,7 +544,6 @@ public boolean equals(Sequence<C> other){
537544
if ( ! myCompound.equalsIgnoreCase(otherCompound))
538545
return false;
539546
}
540-
541547
return true;
542548
}
543549

biojava-core/src/main/java/org/biojava/nbio/core/sequence/template/SequenceProxyView.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
package org.biojava.nbio.core.sequence.template;
2727

2828
import org.biojava.nbio.core.sequence.AccessionID;
29+
import org.biojava.nbio.core.util.Equals;
2930

3031
import java.util.Iterator;
3132
import java.util.List;
@@ -71,6 +72,19 @@ public List<C> getAsList() {
7172
return SequenceMixin.toList(this);
7273
}
7374

75+
76+
public boolean equals(Object o) {
77+
78+
if(! Equals.classEqual(this, o)) {
79+
return false;
80+
}
81+
82+
Sequence<C> other = (Sequence<C>)o;
83+
84+
85+
return sequence.equals(other);
86+
}
87+
7488
@Override
7589
public boolean equals(Sequence<C> other) {
7690
return sequence.equals(other);

0 commit comments

Comments
 (0)