Browse files

Used return covariance on clone() to provide cleaner front-end API

  • Loading branch information...
1 parent cec0d68 commit fed46c8263a419b4014723454893b58a4d88a0c5 @johnmay committed Nov 1, 2012
Showing with 172 additions and 46 deletions.
  1. +1 −1 src/main/org/openscience/cdk/AminoAcid.java
  2. +1 −1 src/main/org/openscience/cdk/AtomContainer.java
  3. +1 −1 src/main/org/openscience/cdk/BioPolymer.java
  4. +1 −1 src/main/org/openscience/cdk/Crystal.java
  5. +2 −2 src/main/org/openscience/cdk/Molecule.java
  6. +9 −1 src/main/org/openscience/cdk/Monomer.java
  7. +1 −1 src/main/org/openscience/cdk/Polymer.java
  8. +10 −2 src/main/org/openscience/cdk/Ring.java
  9. +1 −1 src/main/org/openscience/cdk/Strand.java
  10. +2 −2 src/main/org/openscience/cdk/debug/DebugAminoAcid.java
  11. +2 −2 src/main/org/openscience/cdk/debug/DebugAtomContainer.java
  12. +2 −2 src/main/org/openscience/cdk/debug/DebugBioPolymer.java
  13. +2 −2 src/main/org/openscience/cdk/debug/DebugCrystal.java
  14. +2 −2 src/main/org/openscience/cdk/debug/DebugMolecule.java
  15. +3 −3 src/main/org/openscience/cdk/debug/DebugMonomer.java
  16. +2 −2 src/main/org/openscience/cdk/debug/DebugPolymer.java
  17. +2 −2 src/main/org/openscience/cdk/debug/DebugRing.java
  18. +2 −2 src/main/org/openscience/cdk/debug/DebugStrand.java
  19. +6 −0 src/main/org/openscience/cdk/interfaces/IAminoAcid.java
  20. +6 −0 src/main/org/openscience/cdk/interfaces/IAtomContainer.java
  21. +6 −1 src/main/org/openscience/cdk/interfaces/IBioPolymer.java
  22. +7 −0 src/main/org/openscience/cdk/interfaces/ICrystal.java
  23. +5 −0 src/main/org/openscience/cdk/interfaces/IMolecule.java
  24. +6 −0 src/main/org/openscience/cdk/interfaces/IMonomer.java
  25. +5 −0 src/main/org/openscience/cdk/interfaces/IPDBMonomer.java
  26. +6 −1 src/main/org/openscience/cdk/interfaces/IPDBPolymer.java
  27. +5 −0 src/main/org/openscience/cdk/interfaces/IPolymer.java
  28. +6 −1 src/main/org/openscience/cdk/interfaces/IRing.java
  29. +6 −0 src/main/org/openscience/cdk/interfaces/IStrand.java
  30. +8 −0 src/main/org/openscience/cdk/protein/data/PDBMonomer.java
  31. +10 −2 src/main/org/openscience/cdk/protein/data/PDBPolymer.java
  32. +1 −1 src/main/org/openscience/cdk/silent/AminoAcid.java
  33. +1 −1 src/main/org/openscience/cdk/silent/AtomContainer.java
  34. +1 −1 src/main/org/openscience/cdk/silent/BioPolymer.java
  35. +1 −1 src/main/org/openscience/cdk/silent/Crystal.java
  36. +2 −2 src/main/org/openscience/cdk/silent/Molecule.java
  37. +8 −0 src/main/org/openscience/cdk/silent/Monomer.java
  38. +8 −0 src/main/org/openscience/cdk/silent/PDBMonomer.java
  39. +9 −1 src/main/org/openscience/cdk/silent/PDBPolymer.java
  40. +1 −1 src/main/org/openscience/cdk/silent/Polymer.java
  41. +11 −2 src/main/org/openscience/cdk/silent/Ring.java
  42. +1 −1 src/main/org/openscience/cdk/silent/Strand.java
View
2 src/main/org/openscience/cdk/AminoAcid.java
@@ -139,7 +139,7 @@ private void setCTerminus(IAtom atom) {
*
* @return The cloned object
*/
- public Object clone() throws CloneNotSupportedException {
+ public IAminoAcid clone() throws CloneNotSupportedException {
AminoAcid clone = (AminoAcid) super.clone();
// copying the new N-terminus and C-terminus pointers
if (getNTerminus() != null)
View
2 src/main/org/openscience/cdk/AtomContainer.java
@@ -1578,7 +1578,7 @@ public String toString()
* @return The cloned object
* @see #shallowCopy
*/
- public Object clone() throws CloneNotSupportedException {
+ public IAtomContainer clone() throws CloneNotSupportedException {
// this is pretty wasteful as we need to delete most the data
// we can't simply create an empty instance as the sub classes (e.g. AminoAcid)
View
2 src/main/org/openscience/cdk/BioPolymer.java
@@ -270,7 +270,7 @@ public String toString() {
return stringContent.toString();
}
- public Object clone() throws CloneNotSupportedException {
+ public IBioPolymer clone() throws CloneNotSupportedException {
BioPolymer clone = (BioPolymer)super.clone();
clone.strands.clear();
for (Iterator<String> strands = clone.getStrandNames().iterator(); strands.hasNext();) {
View
2 src/main/org/openscience/cdk/Crystal.java
@@ -213,7 +213,7 @@ public void setZ(Integer value) {
*
* @return The cloned crystal.
*/
- public Object clone() throws CloneNotSupportedException {
+ public ICrystal clone() throws CloneNotSupportedException {
Crystal clone = (Crystal)super.clone();
// clone the axes
clone.setA(new Vector3d(this.aAxis));
View
4 src/main/org/openscience/cdk/Molecule.java
@@ -101,8 +101,8 @@ public String toString() {
return description.toString();
}
- public Object clone() throws CloneNotSupportedException {
- return super.clone();
+ public IMolecule clone() throws CloneNotSupportedException {
+ return (IMolecule) super.clone();
}
}
View
10 src/main/org/openscience/cdk/Monomer.java
@@ -118,7 +118,15 @@ public void setMonomerType(String cMonomerType) {
notifyChanged();
}
- public String toString() {
+ /**
+ * @inheritDoc
+ */
+ @Override
+ public IMonomer clone() throws CloneNotSupportedException {
+ return (IMonomer) super.clone();
+ }
+
+ public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append("Monomer{").append(this.hashCode());
if (getMonomerName() != null) {
View
2 src/main/org/openscience/cdk/Polymer.java
@@ -150,7 +150,7 @@ public String toString() {
TODO it's not clear why we need to remove all elements after the clone
Looks like we should only clone the monomer related stuff
*/
- public Object clone() throws CloneNotSupportedException {
+ public IPolymer clone() throws CloneNotSupportedException {
Polymer clone = (Polymer)super.clone();
clone.removeAllElements();
clone.monomers = new Hashtable<String, IMonomer>();
View
12 src/main/org/openscience/cdk/Ring.java
@@ -151,8 +151,16 @@ public int getBondOrderSum()
}
return orderSum;
}
-
- public String toString() {
+
+ /**
+ * @inheritDoc
+ */
+ @Override
+ public IRing clone() throws CloneNotSupportedException {
+ return (IRing) super.clone();
+ }
+
+ public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append("Ring(");
buffer.append(super.toString());
View
2 src/main/org/openscience/cdk/Strand.java
@@ -243,7 +243,7 @@ public String toString() {
return stringContent.toString();
}
- public Object clone() throws CloneNotSupportedException {
+ public IStrand clone() throws CloneNotSupportedException {
Strand clone = (Strand)super.clone();
clone.monomers.clear();
for (Iterator<String> iter = clone.getMonomerNames().iterator(); iter.hasNext();) {
View
4 src/main/org/openscience/cdk/debug/DebugAminoAcid.java
@@ -521,8 +521,8 @@ public void setFlags(boolean[] flagsNew) {
return super.getFlags();
}
- public Object clone() throws CloneNotSupportedException {
- Object clone = null;
+ public IAminoAcid clone() throws CloneNotSupportedException {
+ IAminoAcid clone = null;
try {
clone = super.clone();
} catch (Exception exception) {
View
4 src/main/org/openscience/cdk/debug/DebugAtomContainer.java
@@ -542,8 +542,8 @@ public void setFlags(boolean[] flagsNew) {
return super.getFlags();
}
- public Object clone() throws CloneNotSupportedException {
- Object clone = null;
+ public IAtomContainer clone() throws CloneNotSupportedException {
+ IAtomContainer clone = null;
try {
clone = super.clone();
} catch (Exception exception) {
View
4 src/main/org/openscience/cdk/debug/DebugBioPolymer.java
@@ -524,8 +524,8 @@ public void setFlags(boolean[] flagsNew) {
return super.getFlags();
}
- public Object clone() throws CloneNotSupportedException {
- Object clone = null;
+ public IBioPolymer clone() throws CloneNotSupportedException {
+ IBioPolymer clone = null;
try {
clone = super.clone();
} catch (Exception exception) {
View
4 src/main/org/openscience/cdk/debug/DebugCrystal.java
@@ -531,8 +531,8 @@ public void setFlags(boolean[] flagsNew) {
return super.getFlags();
}
- public Object clone() throws CloneNotSupportedException {
- Object clone = null;
+ public ICrystal clone() throws CloneNotSupportedException {
+ ICrystal clone = null;
try {
clone = super.clone();
} catch (Exception exception) {
View
4 src/main/org/openscience/cdk/debug/DebugMolecule.java
@@ -533,8 +533,8 @@ public void setFlags(boolean[] flagsNew) {
return super.getFlags();
}
- public Object clone() throws CloneNotSupportedException {
- Object clone = null;
+ public IMolecule clone() throws CloneNotSupportedException {
+ IMolecule clone = null;
try {
clone = super.clone();
} catch (Exception exception) {
View
6 src/main/org/openscience/cdk/debug/DebugMonomer.java
@@ -521,10 +521,10 @@ public void setFlags(boolean[] flagsNew) {
return super.getFlags();
}
- public Object clone() throws CloneNotSupportedException {
- Object clone = null;
+ public IMonomer clone() throws CloneNotSupportedException {
+ IMonomer clone = null;
try {
- clone = super.clone();
+ clone = (IMonomer) super.clone();
} catch (Exception exception) {
logger.error("Could not clone DebugAtom: " + exception.getMessage(), exception);
logger.debug(exception);
View
4 src/main/org/openscience/cdk/debug/DebugPolymer.java
@@ -523,8 +523,8 @@ public void setFlags(boolean[] flagsNew) {
return super.getFlags();
}
- public Object clone() throws CloneNotSupportedException {
- Object clone = null;
+ public IPolymer clone() throws CloneNotSupportedException {
+ IPolymer clone = null;
try {
clone = super.clone();
} catch (Exception exception) {
View
4 src/main/org/openscience/cdk/debug/DebugRing.java
@@ -546,8 +546,8 @@ public void setFlags(boolean[] flagsNew) {
return super.getFlags();
}
- public Object clone() throws CloneNotSupportedException {
- Object clone = null;
+ public IRing clone() throws CloneNotSupportedException {
+ IRing clone = null;
try {
clone = super.clone();
} catch (Exception exception) {
View
4 src/main/org/openscience/cdk/debug/DebugStrand.java
@@ -523,8 +523,8 @@ public void setFlags(boolean[] flagsNew) {
return super.getFlags();
}
- public Object clone() throws CloneNotSupportedException {
- Object clone = null;
+ public IStrand clone() throws CloneNotSupportedException {
+ IStrand clone = null;
try {
clone = super.clone();
} catch (Exception exception) {
View
6 src/main/org/openscience/cdk/interfaces/IAminoAcid.java
@@ -73,4 +73,10 @@
*/
public void addCTerminus(IAtom atom);
+
+ /**
+ * @inheritDoc
+ */
+ @Override
+ public IAminoAcid clone() throws CloneNotSupportedException;
@egonw
egonw added a note Nov 2, 2012

Oh, that is interesting... I'm sure I tried that in the past... must be new?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
}
View
6 src/main/org/openscience/cdk/interfaces/IAtomContainer.java
@@ -646,6 +646,12 @@ public void addBond(int atom1, int atom2, IBond.Order order,
*/
public boolean isEmpty();
+
+ /**
+ * @inheritDoc
+ */
+ @Override
+ public IAtomContainer clone() throws CloneNotSupportedException;
}
View
7 src/main/org/openscience/cdk/interfaces/IBioPolymer.java
@@ -136,5 +136,10 @@
* @return hashtable containing the strands in the Polymer
*/
public Map<String,IStrand> getStrands();
-
+
+ /**
+ * @inheritDoc
+ */
+ @Override
+ public IBioPolymer clone() throws CloneNotSupportedException;
}
View
7 src/main/org/openscience/cdk/interfaces/ICrystal.java
@@ -139,4 +139,11 @@
* @see #getZ
*/
public void setZ(Integer value);
+
+
+ /**
+ * @inheritDoc
+ */
+ @Override
+ public ICrystal clone() throws CloneNotSupportedException;
}
View
5 src/main/org/openscience/cdk/interfaces/IMolecule.java
@@ -33,5 +33,10 @@
*/
public interface IMolecule extends IAtomContainer {
+ /**
+ * @inheritDoc
+ */
+ @Override
+ public IMolecule clone() throws CloneNotSupportedException;
}
View
6 src/main/org/openscience/cdk/interfaces/IMonomer.java
@@ -72,4 +72,10 @@
* @see #getMonomerType
*/
public void setMonomerType(String cMonomerType);
+
+ /**
+ * @inheritDoc
+ */
+ @Override
+ public IMonomer clone() throws CloneNotSupportedException;
}
View
5 src/main/org/openscience/cdk/interfaces/IPDBMonomer.java
@@ -75,6 +75,11 @@
*/
public void setResSeq(String newResSeq);
+ /**
+ * @inheritDoc
+ */
+ @Override
+ public IPDBMonomer clone() throws CloneNotSupportedException;
}
View
7 src/main/org/openscience/cdk/interfaces/IPDBPolymer.java
@@ -75,5 +75,10 @@
* @return Collection containing the PDBStructure in the PDBPolymer
*/
public Collection<IPDBStructure> getStructures();
-
+
+ /**
+ * @inheritDoc
+ */
+ @Override
+ public IPDBPolymer clone() throws CloneNotSupportedException;
}
View
5 src/main/org/openscience/cdk/interfaces/IPolymer.java
@@ -89,4 +89,9 @@
*/
public void removeMonomer(String name);
+ /**
+ * @inheritDoc
+ */
+ @Override
+ public IPolymer clone() throws CloneNotSupportedException;
}
View
7 src/main/org/openscience/cdk/interfaces/IRing.java
@@ -61,5 +61,10 @@
* @return the sum of all bond orders in the ring
*/
public int getBondOrderSum();
-
+
+ /**
+ * @inheritDoc
+ */
+ @Override
+ public IRing clone() throws CloneNotSupportedException;
}
View
6 src/main/org/openscience/cdk/interfaces/IStrand.java
@@ -125,4 +125,10 @@
* @return Map containing the monomers in the strand.
*/
public Map<String,IMonomer> getMonomers();
+
+ /**
+ * @inheritDoc
+ */
+ @Override
+ public IStrand clone() throws CloneNotSupportedException;
}
View
8 src/main/org/openscience/cdk/protein/data/PDBMonomer.java
@@ -100,6 +100,14 @@ public String getResSeq() {
return resSeq;
}
+ /**
+ * @inheritDoc
+ */
+ @Override
+ public IPDBMonomer clone() throws CloneNotSupportedException {
+ return (IPDBMonomer) super.clone();
+ }
+
public void setResSeq(String resSeq) {
this.resSeq = resSeq;
}
View
12 src/main/org/openscience/cdk/protein/data/PDBPolymer.java
@@ -117,8 +117,16 @@ public void addAtom(IPDBAtom oAtom, IMonomer oMonomer, IStrand oStrand) {
// don't return the original
return new ArrayList<String>(sequentialListOfMonomers);
}
-
- public String toString() {
+
+ /**
+ * @inheritDoc
+ */
+ @Override
+ public IPDBPolymer clone() throws CloneNotSupportedException {
+ return (IPDBPolymer) super.clone();
+ }
+
+ public String toString() {
StringBuffer stringContent = new StringBuffer();
stringContent.append("PDBPolymer(");
stringContent.append(this.hashCode()).append(", ");
View
2 src/main/org/openscience/cdk/silent/AminoAcid.java
@@ -137,7 +137,7 @@ private void setCTerminus(IAtom atom) {
*
* @return The cloned object
*/
- public Object clone() throws CloneNotSupportedException {
+ public IAminoAcid clone() throws CloneNotSupportedException {
AminoAcid clone = (AminoAcid) super.clone();
// copying the new N-terminus and C-terminus pointers
if (getNTerminus() != null)
View
2 src/main/org/openscience/cdk/silent/AtomContainer.java
@@ -1521,7 +1521,7 @@ public String toString()
* @return The cloned object
* @see #shallowCopy
*/
- public Object clone() throws CloneNotSupportedException {
+ public IAtomContainer clone() throws CloneNotSupportedException {
// this is pretty wasteful as we need to delete most the data
View
2 src/main/org/openscience/cdk/silent/BioPolymer.java
@@ -265,7 +265,7 @@ public String toString() {
return stringContent.toString();
}
- public Object clone() throws CloneNotSupportedException {
+ public IBioPolymer clone() throws CloneNotSupportedException {
BioPolymer clone = (BioPolymer)super.clone();
clone.strands.clear();
for (Iterator<String> strands = clone.getStrandNames().iterator(); strands.hasNext();) {
View
2 src/main/org/openscience/cdk/silent/Crystal.java
@@ -203,7 +203,7 @@ public void setZ(Integer value) {
*
* @return The cloned crystal.
*/
- public Object clone() throws CloneNotSupportedException {
+ public ICrystal clone() throws CloneNotSupportedException {
Crystal clone = (Crystal)super.clone();
// clone the axes
clone.setA(new Vector3d(this.aAxis));
View
4 src/main/org/openscience/cdk/silent/Molecule.java
@@ -99,8 +99,8 @@ public String toString() {
return description.toString();
}
- public Object clone() throws CloneNotSupportedException {
- return super.clone();
+ public IMolecule clone() throws CloneNotSupportedException {
+ return (IMolecule) super.clone();
}
}
View
8 src/main/org/openscience/cdk/silent/Monomer.java
@@ -114,6 +114,14 @@ public void setMonomerType(String cMonomerType) {
monomerType = cMonomerType;
}
+ /**
+ * @inheritDoc
+ */
+ @Override
+ public IMonomer clone() throws CloneNotSupportedException {
+ return (IMonomer) super.clone();
+ }
+
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append("Monomer{").append(this.hashCode());
View
8 src/main/org/openscience/cdk/silent/PDBMonomer.java
@@ -97,6 +97,14 @@ public String getResSeq() {
return resSeq;
}
+ /**
+ * @inheritDoc
+ */
+ @Override
+ public IPDBMonomer clone() throws CloneNotSupportedException {
+ return (IPDBMonomer) super.clone();
+ }
+
public void setResSeq(String resSeq) {
this.resSeq = resSeq;
}
View
10 src/main/org/openscience/cdk/silent/PDBPolymer.java
@@ -114,7 +114,15 @@ public void addAtom(IPDBAtom oAtom, IMonomer oMonomer, IStrand oStrand) {
// don't return the original
return new ArrayList<String>(sequentialListOfMonomers);
}
-
+
+ /**
+ * @inheritDoc
+ */
+ @Override
+ public IPDBPolymer clone() throws CloneNotSupportedException {
+ return (IPDBPolymer) super.clone();
+ }
+
public String toString() {
StringBuffer stringContent = new StringBuffer();
stringContent.append("PDBPolymer(");
View
2 src/main/org/openscience/cdk/silent/Polymer.java
@@ -144,7 +144,7 @@ public String toString() {
TODO it's not clear why we need to remove all elements after the clone
Looks like we should only clone the monomer related stuff
*/
- public Object clone() throws CloneNotSupportedException {
+ public IPolymer clone() throws CloneNotSupportedException {
Polymer clone = (Polymer)super.clone();
clone.removeAllElements();
clone.monomers = new Hashtable<String, IMonomer>();
View
13 src/main/org/openscience/cdk/silent/Ring.java
@@ -146,8 +146,17 @@ public int getBondOrderSum()
}
return orderSum;
}
-
- public String toString() {
+
+ /**
+ * @inheritDoc
+ */
+ @Override
+ public IRing clone() throws CloneNotSupportedException {
+ return (IRing) super.clone();
+ }
+
+
+ public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append("Ring(");
buffer.append(super.toString());
View
2 src/main/org/openscience/cdk/silent/Strand.java
@@ -238,7 +238,7 @@ public String toString() {
return stringContent.toString();
}
- public Object clone() throws CloneNotSupportedException {
+ public IStrand clone() throws CloneNotSupportedException {
Strand clone = (Strand)super.clone();
clone.monomers.clear();
for (Iterator<String> iter = clone.getMonomerNames().iterator(); iter.hasNext();) {

0 comments on commit fed46c8

Please sign in to comment.