Skip to content

Commit 2d90038

Browse files
committed
hashCode() added for all the classes where added an equals()
1 parent dbcf542 commit 2d90038

File tree

8 files changed

+33
-59
lines changed

8 files changed

+33
-59
lines changed

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

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -270,37 +270,28 @@ public List<C> getAsList() {
270270
return compounds;
271271
}
272272

273-
273+
@Override
274274
public boolean equals(Object o){
275275

276276
if(! Equals.classEqual(this, o)) {
277277
return false;
278278
}
279279

280280
Sequence<C> other = (Sequence<C>)o;
281-
282281
if ( original.getAsList().size() != other.getAsList().size())
283282
return false;
284283

285284
for ( int i = 0 ; i< original.getAsList().size() ; i++){
286285
if ( ! original.getAsList().get(i).equalsIgnoreCase(other.getAsList().get(i)))
287286
return false;
288287
}
289-
290288
return true;
291289
}
292290

293291
@Override
294-
public boolean equals(Sequence<C>other){
295-
if ( original.getAsList().size() != other.getAsList().size())
296-
return false;
297-
298-
for ( int i = 0 ; i< original.getAsList().size() ; i++){
299-
if ( ! original.getAsList().get(i).equalsIgnoreCase(other.getAsList().get(i)))
300-
return false;
301-
}
302-
303-
return true;
292+
public int hashCode(){
293+
String s = getSequenceAsString();
294+
return s.hashCode();
304295
}
305296

306297
@Override

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,9 @@ public boolean equals(Object o) {
227227
}
228228

229229
Sequence<C> other = (Sequence<C>)o;
230-
231-
232230
if ( other.getCompoundSet() != getCompoundSet())
233231
return false;
234232

235-
236233
List<C> rawCompounds = getAsList();
237234
List<C> otherCompounds = other.getAsList();
238235

@@ -245,9 +242,13 @@ public boolean equals(Object o) {
245242
if ( ! myCompound.equalsIgnoreCase(otherCompound))
246243
return false;
247244
}
248-
249245
return true;
246+
}
250247

248+
@Override
249+
public int hashCode(){
250+
String s = getSequenceAsString();
251+
return s.hashCode();
251252
}
252253

253254
/**

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,19 +162,17 @@ public SequenceView<C> getInverse() {
162162
return SequenceMixin.inverse(this);
163163
}
164164

165-
165+
@Override
166166
public boolean equals(Object o){
167167

168168
if(! Equals.classEqual(this, o)) {
169169
return false;
170170
}
171171

172172
Sequence<C> other = (Sequence<C>)o;
173-
174173
if ( other.getCompoundSet() != getCompoundSet())
175174
return false;
176175

177-
178176
List<C> rawCompounds = getAsList();
179177
List<C> otherCompounds = other.getAsList();
180178

@@ -187,9 +185,12 @@ public boolean equals(Object o){
187185
if ( ! myCompound.equalsIgnoreCase(otherCompound))
188186
return false;
189187
}
190-
191188
return true;
189+
}
192190

193-
191+
@Override
192+
public int hashCode(){
193+
String s = getSequenceAsString();
194+
return s.hashCode();
194195
}
195196
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,12 @@ public boolean equals(Object o){
257257
return true;
258258
}
259259

260+
@Override
261+
public int hashCode(){
262+
String s = getSequenceAsString();
263+
return s.hashCode();
264+
}
265+
260266
/**
261267
*
262268
* @return

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

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -300,43 +300,16 @@ public List<C> getAsList() {
300300
}
301301

302302
@Override
303-
public boolean equals(Sequence<C> other) {
304-
305-
if ( other.getCompoundSet() != getCompoundSet())
306-
return false;
307-
308-
309-
List<C> rawCompounds = getAsList();
310-
List<C> otherCompounds = other.getAsList();
311-
312-
if ( rawCompounds.size() != otherCompounds.size())
313-
return false;
314-
315-
for (int i = 0 ; i < rawCompounds.size() ; i++){
316-
Compound myCompound = rawCompounds.get(i);
317-
Compound otherCompound = otherCompounds.get(i);
318-
if ( ! myCompound.equalsIgnoreCase(otherCompound))
319-
return false;
320-
}
321-
322-
return true;
323-
}
324-
325-
326-
public boolean equals(Sequence<C> o) {
327-
303+
public boolean equals(Object o) {
328304

329305
if(! Equals.classEqual(this, o)) {
330306
return false;
331307
}
332308

333309
Sequence<C> other = (Sequence<C>)o;
334-
335-
336310
if ( other.getCompoundSet() != getCompoundSet())
337311
return false;
338312

339-
340313
List<C> rawCompounds = getAsList();
341314
List<C> otherCompounds = other.getAsList();
342315

@@ -349,10 +322,14 @@ public boolean equals(Sequence<C> o) {
349322
if ( ! myCompound.equalsIgnoreCase(otherCompound))
350323
return false;
351324
}
352-
353325
return true;
354326
}
355327

328+
@Override
329+
public int hashCode(){
330+
String s = getSequenceAsString();
331+
return s.hashCode();
332+
}
356333

357334
@Override
358335
public int getIndexOf(C compound) {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,7 @@ public void setCompoundSet(CompoundSet<C> compoundSet) {
520520
this.compoundSet = compoundSet;
521521
}
522522

523+
@Override
523524
public boolean equals(Object o){
524525

525526
if(! Equals.classEqual(this, o)) {
@@ -547,6 +548,7 @@ public boolean equals(Object o){
547548
return true;
548549
}
549550

551+
@Override
550552
public int hashCode(){
551553
String s = getSequenceAsString();
552554
return s.hashCode();

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@ public interface Sequence<C extends Compound> extends Iterable<C>, Accessioned {
7979
*/
8080
public List<C> getAsList();
8181

82-
public boolean equals(Sequence<C> other);
83-
84-
public int hashCode();
85-
8682
/**
8783
* Returns a portion of the sequence from the different positions. This is
8884
* indexed from 1

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public List<C> getAsList() {
7272
return SequenceMixin.toList(this);
7373
}
7474

75-
75+
@Override
7676
public boolean equals(Object o) {
7777

7878
if(! Equals.classEqual(this, o)) {
@@ -81,13 +81,13 @@ public boolean equals(Object o) {
8181

8282
Sequence<C> other = (Sequence<C>)o;
8383

84-
8584
return sequence.equals(other);
8685
}
8786

8887
@Override
89-
public boolean equals(Sequence<C> other) {
90-
return sequence.equals(other);
88+
public int hashCode(){
89+
String s = getSequenceAsString();
90+
return s.hashCode();
9191
}
9292

9393
@Override

0 commit comments

Comments
 (0)