Skip to content

Commit

Permalink
Properly implemented Isotope.compare() for data and silent
Browse files Browse the repository at this point in the history
Change-Id: Iff60038106b126062f2566749c5e719f4672bc7a
Signed-off-by: John May <john.wilkinsonmay@gmail.com>
  • Loading branch information
egonw committed Dec 13, 2012
1 parent 2e62bde commit 09868f4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
22 changes: 19 additions & 3 deletions src/main/org/openscience/cdk/Isotope.java
Expand Up @@ -288,9 +288,25 @@ public boolean compare(Object object) {
return false;
}
Isotope isotope = (Isotope)object;
return massNumber == isotope.massNumber &&
exactMass == isotope.exactMass &&
naturalAbundance == isotope.naturalAbundance;
if (isotope.getMassNumber() != null && massNumber != null &&
isotope.getMassNumber().intValue() != this.getMassNumber().intValue())
return false;
if (isotope.getMassNumber() == null && massNumber != null)
return false;
if (isotope.getExactMass() != null && exactMass != null) {
double diff = Math.abs(isotope.getExactMass().doubleValue() - this.getExactMass().doubleValue());
if (diff > 0.0000001) return false;
}
if (isotope.getExactMass() == null && exactMass != null)
return false;
if (isotope.getNaturalAbundance() != null && naturalAbundance != null) {
double diff = Math.abs(isotope.getNaturalAbundance().doubleValue() - this.getNaturalAbundance().doubleValue());
if (diff > 0.0000001) return false;
}
if (isotope.getNaturalAbundance() == null && naturalAbundance != null)
return false;

return true;
}

public Object clone() throws CloneNotSupportedException {
Expand Down
22 changes: 19 additions & 3 deletions src/main/org/openscience/cdk/silent/Isotope.java
Expand Up @@ -280,9 +280,25 @@ public boolean compare(Object object) {
return false;
}
Isotope isotope = (Isotope)object;
return massNumber == isotope.massNumber &&
exactMass == isotope.exactMass &&
naturalAbundance == isotope.naturalAbundance;
if (isotope.getMassNumber() != null && massNumber != null &&
isotope.getMassNumber().intValue() != this.getMassNumber().intValue())
return false;
if (isotope.getMassNumber() == null && massNumber != null)
return false;
if (isotope.getExactMass() != null && exactMass != null) {
double diff = Math.abs(isotope.getExactMass().doubleValue() - this.getExactMass().doubleValue());
if (diff > 0.0000001) return false;
}
if (isotope.getExactMass() == null && exactMass != null)
return false;
if (isotope.getNaturalAbundance() != null && naturalAbundance != null) {
double diff = Math.abs(isotope.getNaturalAbundance().doubleValue() - this.getNaturalAbundance().doubleValue());
if (diff > 0.0000001) return false;
}
if (isotope.getNaturalAbundance() == null && naturalAbundance != null)
return false;

return true;
}

public Object clone() throws CloneNotSupportedException {
Expand Down

0 comments on commit 09868f4

Please sign in to comment.