Permalink
Browse files

Use interfaces instead of implementations

Change-Id: I90a468ef590a246cac670d8d2d3c337a39301de0

Signed-off-by: Rajarshi Guha <rajarshi.guha@gmail.com>
  • Loading branch information...
1 parent b2838d5 commit 829da6c767e011e40fec11d59c866c816f189e80 @egonw egonw committed with rajarshi Apr 18, 2012
Showing with 23 additions and 25 deletions.
  1. +23 −25 src/main/org/openscience/cdk/ringsearch/FiguerasSSSRFinder.java
@@ -27,13 +27,12 @@
import java.util.List;
import java.util.Vector;
-import org.openscience.cdk.Atom;
-import org.openscience.cdk.Ring;
-import org.openscience.cdk.RingSet;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IBond;
import org.openscience.cdk.interfaces.IChemObjectBuilder;
+import org.openscience.cdk.interfaces.IRing;
+import org.openscience.cdk.interfaces.IRingSet;
import org.openscience.cdk.tools.ILoggingTool;
import org.openscience.cdk.tools.LoggingToolFactory;
import org.openscience.cdk.tools.manipulator.RingSetManipulator;
@@ -68,17 +67,16 @@
* @param mol the molecule to be searched for rings
* @return a RingSet containing the rings in molecule
*/
- public RingSet findSSSR(IAtomContainer mol)
- {
+ public IRingSet findSSSR(IAtomContainer mol) {
IBond brokenBond = null;
IChemObjectBuilder builder = mol.getBuilder();
- RingSet sssr = builder.newInstance(RingSet.class);
+ IRingSet sssr = builder.newInstance(IRingSet.class);
IAtomContainer molecule = builder.newInstance(IAtomContainer.class);
molecule.add(mol);
IAtom smallest;
int smallestDegree, nodesToBreakCounter, degree;
- Atom[] rememberNodes;
- Ring ring;
+ IAtom[] rememberNodes;
+ IRing ring;
//Two Vectors - as defined in the article. One to hold the
//full set of atoms in the structure and on to store the numbers
@@ -141,26 +139,26 @@ public RingSet findSSSR(IAtomContainer mol)
// they are part of.
else if (smallestDegree == 2)
{
- rememberNodes = new Atom[nodesN2.size()];
+ rememberNodes = new IAtom[nodesN2.size()];
nodesToBreakCounter = 0;
for (int f = 0; f < nodesN2.size(); f++)
{
- ring = getRing((Atom)nodesN2.get(f), molecule);
+ ring = getRing((IAtom)nodesN2.get(f), molecule);
if (ring != null)
{
// check, if this ring already is in SSSR
if (!RingSetManipulator.ringAlreadyInSet(ring, sssr))
{
sssr.addAtomContainer(ring);
- rememberNodes[nodesToBreakCounter] = (Atom)nodesN2.get(f);
+ rememberNodes[nodesToBreakCounter] = (IAtom)nodesN2.get(f);
nodesToBreakCounter++;
}
}
}
if (nodesToBreakCounter == 0)
{
nodesToBreakCounter = 1;
- rememberNodes[0] = (Atom)nodesN2.get(0);
+ rememberNodes[0] = (IAtom)nodesN2.get(0);
}
for (int f = 0; f < nodesToBreakCounter; f++){
breakBond(rememberNodes[f], molecule);
@@ -206,7 +204,7 @@ else if (smallestDegree == 3)
* @param molecule The molecule that contains the rootNode
* @return The smallest Ring rootnode is part of
*/
- private Ring getRing(IAtom rootNode, IAtomContainer molecule)
+ private IRing getRing(IAtom rootNode, IAtomContainer molecule)
{
IAtom node, neighbor, mAtom;
List neighbors, mAtoms;
@@ -238,7 +236,7 @@ private Ring getRing(IAtom rootNode, IAtomContainer molecule)
((List)neighbor.getProperty(PATH)).add(neighbor);
}
while (queue.size() > 0){
- node = (Atom)queue.pop();
+ node = (IAtom)queue.pop();
mAtoms = molecule.getConnectedAtomsList(node);
for (int f = 0; f < mAtoms.size(); f++){
mAtom = (IAtom)mAtoms.get(f);
@@ -285,12 +283,12 @@ private Ring getRing(IAtom rootNode, IAtomContainer molecule)
* @param mol The molecule this ring is a substructure of
* @return The ring formed by the given atoms
*/
- private Ring prepareRing(List vec, IAtomContainer mol)
+ private IRing prepareRing(List vec, IAtomContainer mol)
{
// add the atoms in vec to the new ring
int atomCount = vec.size();
- Ring ring = new Ring(atomCount);
- Atom[] atoms = new Atom[atomCount];
+ IRing ring = mol.getBuilder().newInstance(IRing.class, atomCount);
+ IAtom[] atoms = new IAtom[atomCount];
vec.toArray(atoms);
ring.setAtoms(atoms);
// add the bonds in mol to the new ring
@@ -357,7 +355,7 @@ private void initPath(IAtomContainer molecule)
private List getIntersection(List vec1, List vec2) {
List is = new Vector();
for (int f = 0; f < vec1.size(); f++){
- if (vec2.contains((Atom)vec1.get(f))) is.add((Atom)vec1.get(f));
+ if (vec2.contains((IAtom)vec1.get(f))) is.add((IAtom)vec1.get(f));
}
return is;
}
@@ -373,7 +371,7 @@ private Vector getUnion(Vector vec1, Vector vec2){
// FIXME: the JavaDoc does not describe what happens: that vec1 gets to be the union!
Vector is = (Vector)vec1.clone();
for (int f = vec2.size()- 1; f > -1; f--){
- if (!vec1.contains((Atom)vec2.elementAt(f))) is.addElement((Atom)vec2.elementAt(f));
+ if (!vec1.contains((IAtom)vec2.elementAt(f))) is.addElement((IAtom)vec2.elementAt(f));
}
return is;
}
@@ -384,7 +382,7 @@ private Vector getUnion(Vector vec1, Vector vec2){
* @param atom The atom one bond is eliminated of
* @param molecule The molecule that contains the atom
*/
- private void breakBond(Atom atom, IAtomContainer molecule) {
+ private void breakBond(IAtom atom, IAtomContainer molecule) {
Iterator<IBond> bonds = molecule.bonds().iterator();
while (bonds.hasNext()) {
IBond bond = (IBond) bonds.next();
@@ -405,10 +403,10 @@ private void breakBond(Atom atom, IAtomContainer molecule) {
* @param ring
* @param molecule
*/
- private IBond checkEdges(Ring ring, IAtomContainer molecule)
+ private IBond checkEdges(IRing ring, IAtomContainer molecule)
{
- Ring r1, r2;
- RingSet ringSet = new RingSet();
+ IRing r1, r2;
+ IRingSet ringSet = ring.getBuilder().newInstance(IRingSet.class);
IBond bond;
int minMaxSize = Integer.MAX_VALUE;
int minMax = 0;
@@ -433,9 +431,9 @@ private IBond checkEdges(Ring ring, IAtomContainer molecule)
}
for (int i = 0; i < ringSet.getAtomContainerCount(); i++)
{
- if (((Ring)ringSet.getAtomContainer(i)).getBondCount() < minMaxSize)
+ if (((IRing)ringSet.getAtomContainer(i)).getBondCount() < minMaxSize)
{
- minMaxSize = ((Ring)ringSet.getAtomContainer(i)).getBondCount();
+ minMaxSize = ((IRing)ringSet.getAtomContainer(i)).getBondCount();
minMax = i;
}
}

0 comments on commit 829da6c

Please sign in to comment.