Skip to content
Permalink
Browse files

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

Change-Id: Idaf10f55a17ba56bbf7052b4932c0f9b335db1c3
Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information
johnmay authored and egonw committed Nov 1, 2012
1 parent a46545d commit c3d4af007388962db2f01ddd0034ee08602e2d7c
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
@@ -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)
@@ -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)
@@ -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();) {
@@ -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));
@@ -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();
}
}

@@ -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) {
@@ -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>();
@@ -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());
@@ -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();) {
@@ -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) {
@@ -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) {
@@ -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) {
@@ -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) {
@@ -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) {
@@ -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);
@@ -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) {
@@ -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) {
@@ -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) {
@@ -73,4 +73,10 @@
*/
public void addCTerminus(IAtom atom);


/**
* @inheritDoc
*/
@Override
public IAminoAcid clone() throws CloneNotSupportedException;
}
@@ -646,6 +646,12 @@ public void addBond(int atom1, int atom2, IBond.Order order,
*/
public boolean isEmpty();


/**
* @inheritDoc
*/
@Override
public IAtomContainer clone() throws CloneNotSupportedException;
}


@@ -136,5 +136,10 @@
* @return hashtable containing the strands in the Polymer
*/
public Map<String,IStrand> getStrands();


/**
* @inheritDoc
*/
@Override
public IBioPolymer clone() throws CloneNotSupportedException;
}
@@ -139,4 +139,11 @@
* @see #getZ
*/
public void setZ(Integer value);


/**
* @inheritDoc
*/
@Override
public ICrystal clone() throws CloneNotSupportedException;
}
@@ -33,5 +33,10 @@
*/
public interface IMolecule extends IAtomContainer {

/**
* @inheritDoc
*/
@Override
public IMolecule clone() throws CloneNotSupportedException;
}

@@ -72,4 +72,10 @@
* @see #getMonomerType
*/
public void setMonomerType(String cMonomerType);

/**
* @inheritDoc
*/
@Override
public IMonomer clone() throws CloneNotSupportedException;
}
@@ -75,6 +75,11 @@
*/
public void setResSeq(String newResSeq);

/**
* @inheritDoc
*/
@Override
public IPDBMonomer clone() throws CloneNotSupportedException;
}


@@ -75,5 +75,10 @@
* @return Collection containing the PDBStructure in the PDBPolymer
*/
public Collection<IPDBStructure> getStructures();


/**
* @inheritDoc
*/
@Override
public IPDBPolymer clone() throws CloneNotSupportedException;
}
@@ -89,4 +89,9 @@
*/
public void removeMonomer(String name);

/**
* @inheritDoc
*/
@Override
public IPolymer clone() throws CloneNotSupportedException;
}
@@ -61,5 +61,10 @@
* @return the sum of all bond orders in the ring
*/
public int getBondOrderSum();


/**
* @inheritDoc
*/
@Override
public IRing clone() throws CloneNotSupportedException;
}
@@ -125,4 +125,10 @@
* @return Map containing the monomers in the strand.
*/
public Map<String,IMonomer> getMonomers();

/**
* @inheritDoc
*/
@Override
public IStrand clone() throws CloneNotSupportedException;
}
@@ -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;
}
@@ -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(", ");
@@ -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)
@@ -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
@@ -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();) {
@@ -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));

0 comments on commit c3d4af0

Please sign in to comment.
You can’t perform that action at this time.