From c72eca0b2e35667bbabf907253d1976a60498061 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Fri, 13 Mar 2015 17:02:56 +0000 Subject: [PATCH] JAL-1686 @Override and/or TODO added to equals(Object) methods --- src/ext/vamsas/ServiceHandle.java | 6 +++--- src/ext/vamsas/ServiceHandles.java | 6 +++--- src/jalview/analysis/SequenceIdMatcher.java | 13 +++++++++++-- src/jalview/datamodel/DBRefEntry.java | 16 +++++++++++++--- src/jalview/datamodel/Mapping.java | 4 +++- src/jalview/util/MapList.java | 2 ++ src/jalview/ws/rest/RestServiceDescription.java | 1 + src/uk/ac/ebi/picr/model/CrossReference.java | 16 ++++++++++++++-- src/uk/ac/ebi/picr/model/UPEntry.java | 12 ++++++++++-- src/uk/ac/ebi/www/Data.java | 8 +++++--- src/uk/ac/ebi/www/InputParams.java | 8 +++++--- src/uk/ac/ebi/www/WSFile.java | 8 +++++--- src/vamsas/objects/simple/Alignment.java | 12 ++++++++++-- src/vamsas/objects/simple/JpredResult.java | 8 +++++--- src/vamsas/objects/simple/MsaResult.java | 11 ++++++----- src/vamsas/objects/simple/Msfalignment.java | 8 +++++--- src/vamsas/objects/simple/Object.java | 13 ++++++++++--- src/vamsas/objects/simple/Result.java | 12 ++++++++++-- src/vamsas/objects/simple/Secstructpred.java | 6 +++--- src/vamsas/objects/simple/SeqSearchResult.java | 12 ++++++++++-- src/vamsas/objects/simple/Sequence.java | 12 ++++++++++-- src/vamsas/objects/simple/SequenceSet.java | 12 ++++++++++-- src/vamsas/objects/simple/WsJobId.java | 12 ++++++++++-- 23 files changed, 164 insertions(+), 54 deletions(-) diff --git a/src/ext/vamsas/ServiceHandle.java b/src/ext/vamsas/ServiceHandle.java index 442e5f7..83412ea 100755 --- a/src/ext/vamsas/ServiceHandle.java +++ b/src/ext/vamsas/ServiceHandle.java @@ -128,15 +128,15 @@ public class ServiceHandle implements java.io.Serializable public synchronized boolean equals(java.lang.Object obj) { - if (!(obj instanceof ServiceHandle)) + if (obj == null) { return false; } - ServiceHandle other = (ServiceHandle) obj; - if (obj == null) + if (!(obj instanceof ServiceHandle)) { return false; } + ServiceHandle other = (ServiceHandle) obj; if (this == obj) { return true; diff --git a/src/ext/vamsas/ServiceHandles.java b/src/ext/vamsas/ServiceHandles.java index 45c49d8..5ed466f 100755 --- a/src/ext/vamsas/ServiceHandles.java +++ b/src/ext/vamsas/ServiceHandles.java @@ -57,15 +57,15 @@ public class ServiceHandles implements java.io.Serializable public synchronized boolean equals(java.lang.Object obj) { - if (!(obj instanceof ServiceHandles)) + if (obj == null) { return false; } - ServiceHandles other = (ServiceHandles) obj; - if (obj == null) + if (!(obj instanceof ServiceHandles)) { return false; } + ServiceHandles other = (ServiceHandles) obj; if (this == obj) { return true; diff --git a/src/jalview/analysis/SequenceIdMatcher.java b/src/jalview/analysis/SequenceIdMatcher.java index c3d7ac1..e6a4853 100755 --- a/src/jalview/analysis/SequenceIdMatcher.java +++ b/src/jalview/analysis/SequenceIdMatcher.java @@ -20,9 +20,12 @@ */ package jalview.analysis; -import java.util.*; +import jalview.datamodel.DBRefEntry; +import jalview.datamodel.SequenceI; -import jalview.datamodel.*; +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.Vector; /** * Routines for approximate Sequence Id resolution by name using string @@ -258,14 +261,20 @@ public class SequenceIdMatcher } } + @Override public int hashCode() { return ((id.length() >= 4) ? id.substring(0, 4).hashCode() : id .hashCode()); } + @Override public boolean equals(Object s) { + if (s == null) + { + return false; + } if (s instanceof SeqIdName) { return this.equals((SeqIdName) s); diff --git a/src/jalview/datamodel/DBRefEntry.java b/src/jalview/datamodel/DBRefEntry.java index bc1d610..54bdf20 100755 --- a/src/jalview/datamodel/DBRefEntry.java +++ b/src/jalview/datamodel/DBRefEntry.java @@ -69,12 +69,20 @@ public class DBRefEntry (entry.map == null ? null : new Mapping(entry.map))); } - public boolean equals(DBRefEntry entry) + @Override + public boolean equals(Object o) { + // TODO should also override hashCode to ensure equal objects have equal + // hashcodes + if (o == null || !(o instanceof DBRefEntry)) + { + return false; + } + DBRefEntry entry = (DBRefEntry) o; if (entry == this) + { return true; - if (entry == null) - return false; + } if (equalRef(entry) && ((map == null && entry.map == null) || (map != null && entry.map != null && map.equals(entry.map)))) @@ -97,7 +105,9 @@ public class DBRefEntry return false; } if (entry == this) + { return true; + } if ((source != null && entry.source != null && source .equalsIgnoreCase(entry.source)) && (accessionId != null && entry.accessionId != null && accessionId diff --git a/src/jalview/datamodel/Mapping.java b/src/jalview/datamodel/Mapping.java index 59dc8ff..559ae4c 100644 --- a/src/jalview/datamodel/Mapping.java +++ b/src/jalview/datamodel/Mapping.java @@ -348,6 +348,8 @@ public class Mapping @Override public boolean equals(Object o) { + // TODO should override Object.hashCode() to ensure that equal objects have + // equal hashcodes if (o == null || !(o instanceof Mapping)) { return false; @@ -366,7 +368,7 @@ public class Mapping { return false; } - if (map.equals(other.map)) + if ((map == null && other.map == null) || map.equals(other.map)) { return true; } diff --git a/src/jalview/util/MapList.java b/src/jalview/util/MapList.java index be52600..2641659 100644 --- a/src/jalview/util/MapList.java +++ b/src/jalview/util/MapList.java @@ -79,6 +79,8 @@ public class MapList @Override public boolean equals(Object o) { + // TODO should also override hashCode to ensure equal objects have equal + // hashcodes if (o == null || !(o instanceof MapList)) { return false; diff --git a/src/jalview/ws/rest/RestServiceDescription.java b/src/jalview/ws/rest/RestServiceDescription.java index e972068..bbe131d 100644 --- a/src/jalview/ws/rest/RestServiceDescription.java +++ b/src/jalview/ws/rest/RestServiceDescription.java @@ -77,6 +77,7 @@ public class RestServiceDescription this.gapCharacter = gapCharacter; } + @Override public boolean equals(Object o) { if (o == null || !(o instanceof RestServiceDescription)) diff --git a/src/uk/ac/ebi/picr/model/CrossReference.java b/src/uk/ac/ebi/picr/model/CrossReference.java index aef2ca9..498a47b 100644 --- a/src/uk/ac/ebi/picr/model/CrossReference.java +++ b/src/uk/ac/ebi/picr/model/CrossReference.java @@ -244,15 +244,22 @@ public class CrossReference implements java.io.Serializable private java.lang.Object __equalsCalc = null; + @Override public synchronized boolean equals(java.lang.Object obj) { + if (obj == null) + { + return false; + } if (!(obj instanceof CrossReference)) + { return false; + } CrossReference other = (CrossReference) obj; - if (obj == null) - return false; if (this == obj) + { return true; + } if (__equalsCalc != null) { return (__equalsCalc == obj); @@ -285,6 +292,11 @@ public class CrossReference implements java.io.Serializable private boolean __hashCodeCalc = false; + /** + * hashCode designed to ensure that if two instances satisfy o1.equals(o2) + * then they have the same hashcode. + */ + @Override public synchronized int hashCode() { if (__hashCodeCalc) diff --git a/src/uk/ac/ebi/picr/model/UPEntry.java b/src/uk/ac/ebi/picr/model/UPEntry.java index 0390d48..c94bf15 100644 --- a/src/uk/ac/ebi/picr/model/UPEntry.java +++ b/src/uk/ac/ebi/picr/model/UPEntry.java @@ -198,15 +198,22 @@ public class UPEntry implements java.io.Serializable private java.lang.Object __equalsCalc = null; + @Override public synchronized boolean equals(java.lang.Object obj) { + if (obj == null) + { + return false; + } if (!(obj instanceof UPEntry)) + { return false; + } UPEntry other = (UPEntry) obj; - if (obj == null) - return false; if (this == obj) + { return true; + } if (__equalsCalc != null) { return (__equalsCalc == obj); @@ -236,6 +243,7 @@ public class UPEntry implements java.io.Serializable private boolean __hashCodeCalc = false; + @Override public synchronized int hashCode() { if (__hashCodeCalc) diff --git a/src/uk/ac/ebi/www/Data.java b/src/uk/ac/ebi/www/Data.java index b12de70..2020fc9 100755 --- a/src/uk/ac/ebi/www/Data.java +++ b/src/uk/ac/ebi/www/Data.java @@ -52,17 +52,18 @@ public class Data implements java.io.Serializable private java.lang.Object __equalsCalc = null; + @Override public synchronized boolean equals(java.lang.Object obj) { - if (!(obj instanceof Data)) + if (obj == null) { return false; } - Data other = (Data) obj; - if (obj == null) + if (!(obj instanceof Data)) { return false; } + Data other = (Data) obj; if (this == obj) { return true; @@ -84,6 +85,7 @@ public class Data implements java.io.Serializable private boolean __hashCodeCalc = false; + @Override public synchronized int hashCode() { if (__hashCodeCalc) diff --git a/src/uk/ac/ebi/www/InputParams.java b/src/uk/ac/ebi/www/InputParams.java index 189c7f6..fe1c70c 100755 --- a/src/uk/ac/ebi/www/InputParams.java +++ b/src/uk/ac/ebi/www/InputParams.java @@ -220,17 +220,18 @@ public class InputParams implements java.io.Serializable private java.lang.Object __equalsCalc = null; + @Override public synchronized boolean equals(java.lang.Object obj) { - if (!(obj instanceof InputParams)) + if (obj == null) { return false; } - InputParams other = (InputParams) obj; - if (obj == null) + if (!(obj instanceof InputParams)) { return false; } + InputParams other = (InputParams) obj; if (this == obj) { return true; @@ -274,6 +275,7 @@ public class InputParams implements java.io.Serializable private boolean __hashCodeCalc = false; + @Override public synchronized int hashCode() { if (__hashCodeCalc) diff --git a/src/uk/ac/ebi/www/WSFile.java b/src/uk/ac/ebi/www/WSFile.java index 9199353..210de76 100755 --- a/src/uk/ac/ebi/www/WSFile.java +++ b/src/uk/ac/ebi/www/WSFile.java @@ -52,17 +52,18 @@ public class WSFile implements java.io.Serializable private java.lang.Object __equalsCalc = null; + @Override public synchronized boolean equals(java.lang.Object obj) { - if (!(obj instanceof WSFile)) + if (obj == null) { return false; } - WSFile other = (WSFile) obj; - if (obj == null) + if (!(obj instanceof WSFile)) { return false; } + WSFile other = (WSFile) obj; if (this == obj) { return true; @@ -84,6 +85,7 @@ public class WSFile implements java.io.Serializable private boolean __hashCodeCalc = false; + @Override public synchronized int hashCode() { if (__hashCodeCalc) diff --git a/src/vamsas/objects/simple/Alignment.java b/src/vamsas/objects/simple/Alignment.java index 9bff9cf..9d47b6a 100755 --- a/src/vamsas/objects/simple/Alignment.java +++ b/src/vamsas/objects/simple/Alignment.java @@ -103,15 +103,22 @@ public class Alignment extends vamsas.objects.simple.Object implements private java.lang.Object __equalsCalc = null; + @Override public synchronized boolean equals(java.lang.Object obj) { + if (obj == null) + { + return false; + } if (!(obj instanceof Alignment)) + { return false; + } Alignment other = (Alignment) obj; - if (obj == null) - return false; if (this == obj) + { return true; + } if (__equalsCalc != null) { return (__equalsCalc == obj); @@ -131,6 +138,7 @@ public class Alignment extends vamsas.objects.simple.Object implements private boolean __hashCodeCalc = false; + @Override public synchronized int hashCode() { if (__hashCodeCalc) diff --git a/src/vamsas/objects/simple/JpredResult.java b/src/vamsas/objects/simple/JpredResult.java index 9db8cfe..cc7cc67 100755 --- a/src/vamsas/objects/simple/JpredResult.java +++ b/src/vamsas/objects/simple/JpredResult.java @@ -79,17 +79,18 @@ public class JpredResult extends vamsas.objects.simple.Result implements private java.lang.Object __equalsCalc = null; + @Override public synchronized boolean equals(java.lang.Object obj) { - if (!(obj instanceof JpredResult)) + if (obj == null) { return false; } - JpredResult other = (JpredResult) obj; - if (obj == null) + if (!(obj instanceof JpredResult)) { return false; } + JpredResult other = (JpredResult) obj; if (this == obj) { return true; @@ -111,6 +112,7 @@ public class JpredResult extends vamsas.objects.simple.Result implements private boolean __hashCodeCalc = false; + @Override public synchronized int hashCode() { if (__hashCodeCalc) diff --git a/src/vamsas/objects/simple/MsaResult.java b/src/vamsas/objects/simple/MsaResult.java index 30a5414..49fa4a7 100755 --- a/src/vamsas/objects/simple/MsaResult.java +++ b/src/vamsas/objects/simple/MsaResult.java @@ -58,20 +58,20 @@ public class MsaResult extends vamsas.objects.simple.Result implements this.msa = msa; } + @Override public synchronized boolean equals(java.lang.Object obj) { - if (!(obj instanceof MsaResult)) + if (obj == null) { return false; } - - MsaResult other = (MsaResult) obj; - - if (obj == null) + if (!(obj instanceof MsaResult)) { return false; } + MsaResult other = (MsaResult) obj; + if (this == obj) { return true; @@ -93,6 +93,7 @@ public class MsaResult extends vamsas.objects.simple.Result implements return _equals; } + @Override public synchronized int hashCode() { if (__hashCodeCalc) diff --git a/src/vamsas/objects/simple/Msfalignment.java b/src/vamsas/objects/simple/Msfalignment.java index 573eb96..90370f0 100755 --- a/src/vamsas/objects/simple/Msfalignment.java +++ b/src/vamsas/objects/simple/Msfalignment.java @@ -78,17 +78,18 @@ public class Msfalignment implements java.io.Serializable private java.lang.Object __equalsCalc = null; + @Override public synchronized boolean equals(java.lang.Object obj) { - if (!(obj instanceof Msfalignment)) + if (obj == null) { return false; } - Msfalignment other = (Msfalignment) obj; - if (obj == null) + if (!(obj instanceof Msfalignment)) { return false; } + Msfalignment other = (Msfalignment) obj; if (this == obj) { return true; @@ -110,6 +111,7 @@ public class Msfalignment implements java.io.Serializable private boolean __hashCodeCalc = false; + @Override public synchronized int hashCode() { if (__hashCodeCalc) diff --git a/src/vamsas/objects/simple/Object.java b/src/vamsas/objects/simple/Object.java index 23eedec..7e79e6a 100755 --- a/src/vamsas/objects/simple/Object.java +++ b/src/vamsas/objects/simple/Object.java @@ -29,15 +29,21 @@ public abstract class Object implements java.io.Serializable private java.lang.Object __equalsCalc = null; + @Override public synchronized boolean equals(java.lang.Object obj) { - if (!(obj instanceof Object)) - return false; - Object other = (Object) obj; if (obj == null) + { + return false; + } + if (!(obj instanceof Object)) + { return false; + } if (this == obj) + { return true; + } if (__equalsCalc != null) { return (__equalsCalc == obj); @@ -51,6 +57,7 @@ public abstract class Object implements java.io.Serializable private boolean __hashCodeCalc = false; + @Override public synchronized int hashCode() { if (__hashCodeCalc) diff --git a/src/vamsas/objects/simple/Result.java b/src/vamsas/objects/simple/Result.java index 18293f5..87f0a48 100755 --- a/src/vamsas/objects/simple/Result.java +++ b/src/vamsas/objects/simple/Result.java @@ -288,15 +288,22 @@ public class Result implements java.io.Serializable private java.lang.Object __equalsCalc = null; + @Override public synchronized boolean equals(java.lang.Object obj) { + if (obj == null) + { + return false; + } if (!(obj instanceof Result)) + { return false; + } Result other = (Result) obj; - if (obj == null) - return false; if (this == obj) + { return true; + } if (__equalsCalc != null) { return (__equalsCalc == obj); @@ -322,6 +329,7 @@ public class Result implements java.io.Serializable private boolean __hashCodeCalc = false; + @Override public synchronized int hashCode() { if (__hashCodeCalc) diff --git a/src/vamsas/objects/simple/Secstructpred.java b/src/vamsas/objects/simple/Secstructpred.java index 77fdd34..349c21e 100755 --- a/src/vamsas/objects/simple/Secstructpred.java +++ b/src/vamsas/objects/simple/Secstructpred.java @@ -57,15 +57,15 @@ public class Secstructpred implements java.io.Serializable public synchronized boolean equals(java.lang.Object obj) { - if (!(obj instanceof Secstructpred)) + if (obj == null) { return false; } - Secstructpred other = (Secstructpred) obj; - if (obj == null) + if (!(obj instanceof Secstructpred)) { return false; } + Secstructpred other = (Secstructpred) obj; if (this == obj) { return true; diff --git a/src/vamsas/objects/simple/SeqSearchResult.java b/src/vamsas/objects/simple/SeqSearchResult.java index 98d1d21..8ef8f7c 100644 --- a/src/vamsas/objects/simple/SeqSearchResult.java +++ b/src/vamsas/objects/simple/SeqSearchResult.java @@ -127,15 +127,22 @@ public class SeqSearchResult extends vamsas.objects.simple.Result implements private java.lang.Object __equalsCalc = null; + @Override public synchronized boolean equals(java.lang.Object obj) { + if (obj == null) + { + return false; + } if (!(obj instanceof SeqSearchResult)) + { return false; + } SeqSearchResult other = (SeqSearchResult) obj; - if (obj == null) - return false; if (this == obj) + { return true; + } if (__equalsCalc != null) { return (__equalsCalc == obj); @@ -157,6 +164,7 @@ public class SeqSearchResult extends vamsas.objects.simple.Result implements private boolean __hashCodeCalc = false; + @Override public synchronized int hashCode() { if (__hashCodeCalc) diff --git a/src/vamsas/objects/simple/Sequence.java b/src/vamsas/objects/simple/Sequence.java index 28dc9eb..8eb7208 100755 --- a/src/vamsas/objects/simple/Sequence.java +++ b/src/vamsas/objects/simple/Sequence.java @@ -78,15 +78,22 @@ public class Sequence implements java.io.Serializable private java.lang.Object __equalsCalc = null; + @Override public synchronized boolean equals(java.lang.Object obj) { + if (obj == null) + { + return false; + } if (!(obj instanceof Sequence)) + { return false; + } Sequence other = (Sequence) obj; - if (obj == null) - return false; if (this == obj) + { return true; + } if (__equalsCalc != null) { return (__equalsCalc == obj); @@ -104,6 +111,7 @@ public class Sequence implements java.io.Serializable private boolean __hashCodeCalc = false; + @Override public synchronized int hashCode() { if (__hashCodeCalc) diff --git a/src/vamsas/objects/simple/SequenceSet.java b/src/vamsas/objects/simple/SequenceSet.java index 2c43f96..d5a269b 100755 --- a/src/vamsas/objects/simple/SequenceSet.java +++ b/src/vamsas/objects/simple/SequenceSet.java @@ -55,15 +55,22 @@ public class SequenceSet implements java.io.Serializable private java.lang.Object __equalsCalc = null; + @Override public synchronized boolean equals(java.lang.Object obj) { + if (obj == null) + { + return false; + } if (!(obj instanceof SequenceSet)) + { return false; + } SequenceSet other = (SequenceSet) obj; - if (obj == null) - return false; if (this == obj) + { return true; + } if (__equalsCalc != null) { return (__equalsCalc == obj); @@ -78,6 +85,7 @@ public class SequenceSet implements java.io.Serializable private boolean __hashCodeCalc = false; + @Override public synchronized int hashCode() { if (__hashCodeCalc) diff --git a/src/vamsas/objects/simple/WsJobId.java b/src/vamsas/objects/simple/WsJobId.java index 3419899..eb04dcf 100755 --- a/src/vamsas/objects/simple/WsJobId.java +++ b/src/vamsas/objects/simple/WsJobId.java @@ -78,15 +78,22 @@ public class WsJobId implements java.io.Serializable private java.lang.Object __equalsCalc = null; + @Override public synchronized boolean equals(java.lang.Object obj) { + if (obj == null) + { + return false; + } if (!(obj instanceof WsJobId)) + { return false; + } WsJobId other = (WsJobId) obj; - if (obj == null) - return false; if (this == obj) + { return true; + } if (__equalsCalc != null) { return (__equalsCalc == obj); @@ -103,6 +110,7 @@ public class WsJobId implements java.io.Serializable private boolean __hashCodeCalc = false; + @Override public synchronized int hashCode() { if (__hashCodeCalc) -- 1.7.10.2