Skip to content

Commit 434c9b1

Browse files
egonwrajarshi
authored andcommitted
Use interfaces instead of implementations
Signed-off-by: Rajarshi Guha <rajarshi.guha@gmail.com>
1 parent 76dcdf7 commit 434c9b1

11 files changed

+62
-82
lines changed

src/main/org/openscience/cdk/reaction/type/HeterolyticCleavagePBReaction.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import java.util.Iterator;
3030

3131
import org.openscience.cdk.CDKConstants;
32-
import org.openscience.cdk.DefaultChemObjectBuilder;
3332
import org.openscience.cdk.annotations.TestClass;
3433
import org.openscience.cdk.annotations.TestMethod;
3534
import org.openscience.cdk.exception.CDKException;
@@ -134,7 +133,7 @@ public IReactionSet initiate(IMoleculeSet reactants, IMoleculeSet agents) throws
134133
throw new CDKException("HeterolyticCleavagePBReaction don't expects agents");
135134
}
136135

137-
IReactionSet setOfReactions = DefaultChemObjectBuilder.getInstance().newInstance(IReactionSet.class);
136+
IReactionSet setOfReactions = reactants.getBuilder().newInstance(IReactionSet.class);
138137
IMolecule reactant = reactants.getMolecule(0);
139138

140139
/* if the parameter hasActiveCenter is not fixed yet, set the active centers*/

src/main/org/openscience/cdk/reaction/type/PiBondingMovementReaction.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
import java.util.Iterator;
2929

3030
import org.openscience.cdk.CDKConstants;
31-
import org.openscience.cdk.Molecule;
32-
import org.openscience.cdk.DefaultChemObjectBuilder;
3331
import org.openscience.cdk.annotations.TestClass;
3432
import org.openscience.cdk.annotations.TestMethod;
3533
import org.openscience.cdk.exception.CDKException;
@@ -131,7 +129,7 @@ public IReactionSet initiate(IMoleculeSet reactants, IMoleculeSet agents) throws
131129
throw new CDKException("PiBondingMovementReaction don't expects agents");
132130
}
133131

134-
IReactionSet setOfReactions = DefaultChemObjectBuilder.getInstance().newInstance(IReactionSet.class);
132+
IReactionSet setOfReactions = reactants.getBuilder().newInstance(IReactionSet.class);
135133
IMolecule reactant = reactants.getMolecule(0);
136134

137135
AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(reactant);
@@ -145,7 +143,7 @@ public IReactionSet initiate(IMoleculeSet reactants, IMoleculeSet agents) throws
145143
// }
146144

147145
AllRingsFinder arf = new AllRingsFinder();
148-
IRingSet ringSet = arf.findAllRings((Molecule) reactant);
146+
IRingSet ringSet = arf.findAllRings((IMolecule) reactant);
149147
for (int ir = 0; ir < ringSet.getAtomContainerCount(); ir++) {
150148
IRing ring = (IRing) ringSet.getAtomContainer(ir);
151149

@@ -174,7 +172,7 @@ public IReactionSet initiate(IMoleculeSet reactants, IMoleculeSet agents) throws
174172
continue;
175173

176174

177-
IReaction reaction = DefaultChemObjectBuilder.getInstance().newInstance(IReaction.class);
175+
IReaction reaction = reactants.getBuilder().newInstance(IReaction.class);
178176
reaction.addReactant(reactant);
179177

180178
IMolecule reactantCloned;
@@ -216,7 +214,7 @@ public IReactionSet initiate(IMoleculeSet reactants, IMoleculeSet agents) throws
216214
*/
217215
private void setActiveCenters(IMolecule reactant) throws CDKException {
218216
AllRingsFinder arf = new AllRingsFinder();
219-
IRingSet ringSet = arf.findAllRings((Molecule) reactant);
217+
IRingSet ringSet = arf.findAllRings((IMolecule) reactant);
220218
for (int ir = 0; ir < ringSet.getAtomContainerCount(); ir++) {
221219
IRing ring = (IRing) ringSet.getAtomContainer(ir);
222220
//only rings with even number of atoms

src/main/org/openscience/cdk/reaction/type/RadicalChargeSiteInitiationReaction.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.util.Iterator;
2929

3030
import org.openscience.cdk.CDKConstants;
31-
import org.openscience.cdk.DefaultChemObjectBuilder;
3231
import org.openscience.cdk.annotations.TestClass;
3332
import org.openscience.cdk.annotations.TestMethod;
3433
import org.openscience.cdk.exception.CDKException;
@@ -124,7 +123,7 @@ public IReactionSet initiate(IMoleculeSet reactants, IMoleculeSet agents) throws
124123
throw new CDKException("RadicalChargeSiteInitiationReaction don't expects agents");
125124
}
126125

127-
IReactionSet setOfReactions = DefaultChemObjectBuilder.getInstance().newInstance(IReactionSet.class);
126+
IReactionSet setOfReactions = reactants.getBuilder().newInstance(IReactionSet.class);
128127
IMolecule reactant = reactants.getMolecule(0);
129128

130129
/* if the parameter hasActiveCenter is not fixed yet, set the active centers*/

src/main/org/openscience/cdk/reaction/type/RadicalSiteHrAlphaReaction.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@
2929
import java.util.Iterator;
3030

3131
import org.openscience.cdk.CDKConstants;
32-
import org.openscience.cdk.Molecule;
33-
import org.openscience.cdk.DefaultChemObjectBuilder;
34-
import org.openscience.cdk.Ring;
3532
import org.openscience.cdk.annotations.TestClass;
3633
import org.openscience.cdk.annotations.TestMethod;
3734
import org.openscience.cdk.aromaticity.CDKHueckelAromaticityDetector;
@@ -42,6 +39,7 @@
4239
import org.openscience.cdk.interfaces.IMoleculeSet;
4340
import org.openscience.cdk.interfaces.IReaction;
4441
import org.openscience.cdk.interfaces.IReactionSet;
42+
import org.openscience.cdk.interfaces.IRing;
4543
import org.openscience.cdk.interfaces.IRingSet;
4644
import org.openscience.cdk.reaction.IReactionProcess;
4745
import org.openscience.cdk.reaction.ReactionEngine;
@@ -133,15 +131,15 @@ public IReactionSet initiate(IMoleculeSet reactants, IMoleculeSet agents) throws
133131
throw new CDKException("RadicalSiteHrAlphaReaction don't expects agents");
134132
}
135133

136-
IReactionSet setOfReactions = DefaultChemObjectBuilder.getInstance().newInstance(IReactionSet.class);
134+
IReactionSet setOfReactions = reactants.getBuilder().newInstance(IReactionSet.class);
137135
IMolecule reactant = reactants.getMolecule(0);
138136

139137
AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(reactant);
140138
CDKHueckelAromaticityDetector.detectAromaticity(reactant);
141139
AllRingsFinder arf = new AllRingsFinder();
142-
IRingSet ringSet = arf.findAllRings((Molecule) reactant);
140+
IRingSet ringSet = arf.findAllRings((IMolecule) reactant);
143141
for (int ir = 0; ir < ringSet.getAtomContainerCount(); ir++) {
144-
Ring ring = (Ring)ringSet.getAtomContainer(ir);
142+
IRing ring = (IRing)ringSet.getAtomContainer(ir);
145143
for (int jr = 0; jr < ring.getAtomCount(); jr++) {
146144
IAtom aring = ring.getAtom(jr);
147145
aring.setFlag(CDKConstants.ISINRING, true);
@@ -159,7 +157,7 @@ public IReactionSet initiate(IMoleculeSet reactants, IMoleculeSet agents) throws
159157
if(atomi.getFlag(CDKConstants.REACTIVE_CENTER)
160158
&& reactant.getConnectedSingleElectronsCount(atomi) == 1) {
161159

162-
hcg.getSpheres((Molecule) reactant, atomi, 2, true);
160+
hcg.getSpheres((IMolecule) reactant, atomi, 2, true);
163161
Iterator<IAtom> atomls = hcg.getNodesInSphere(2).iterator();
164162
while(atomls.hasNext()){
165163
IAtom atoml = atomls.next();
@@ -216,7 +214,7 @@ private void setActiveCenters(IMolecule reactant) throws CDKException {
216214
IAtom atomi = atomis.next();
217215
if(reactant.getConnectedSingleElectronsCount(atomi) == 1) {
218216

219-
hcg.getSpheres((Molecule) reactant, atomi, 2, true);
217+
hcg.getSpheres((IMolecule) reactant, atomi, 2, true);
220218
Iterator<IAtom> atomls = hcg.getNodesInSphere(2).iterator();
221219
while(atomls.hasNext()){
222220
IAtom atoml = atomls.next();

src/main/org/openscience/cdk/reaction/type/RadicalSiteHrBetaReaction.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@
2929
import java.util.Iterator;
3030

3131
import org.openscience.cdk.CDKConstants;
32-
import org.openscience.cdk.Molecule;
33-
import org.openscience.cdk.DefaultChemObjectBuilder;
34-
import org.openscience.cdk.Ring;
3532
import org.openscience.cdk.annotations.TestClass;
3633
import org.openscience.cdk.annotations.TestMethod;
3734
import org.openscience.cdk.aromaticity.CDKHueckelAromaticityDetector;
@@ -42,6 +39,7 @@
4239
import org.openscience.cdk.interfaces.IMoleculeSet;
4340
import org.openscience.cdk.interfaces.IReaction;
4441
import org.openscience.cdk.interfaces.IReactionSet;
42+
import org.openscience.cdk.interfaces.IRing;
4543
import org.openscience.cdk.interfaces.IRingSet;
4644
import org.openscience.cdk.reaction.IReactionProcess;
4745
import org.openscience.cdk.reaction.ReactionEngine;
@@ -134,15 +132,15 @@ public IReactionSet initiate(IMoleculeSet reactants, IMoleculeSet agents) throws
134132
throw new CDKException("RadicalSiteHrBetaReaction don't expects agents");
135133
}
136134

137-
IReactionSet setOfReactions = DefaultChemObjectBuilder.getInstance().newInstance(IReactionSet.class);
135+
IReactionSet setOfReactions = reactants.getBuilder().newInstance(IReactionSet.class);
138136
IMolecule reactant = reactants.getMolecule(0);
139137

140138
AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(reactant);
141139
CDKHueckelAromaticityDetector.detectAromaticity(reactant);
142140
AllRingsFinder arf = new AllRingsFinder();
143-
IRingSet ringSet = arf.findAllRings((Molecule) reactant);
141+
IRingSet ringSet = arf.findAllRings((IMolecule) reactant);
144142
for (int ir = 0; ir < ringSet.getAtomContainerCount(); ir++) {
145-
Ring ring = (Ring)ringSet.getAtomContainer(ir);
143+
IRing ring = (IRing)ringSet.getAtomContainer(ir);
146144
for (int jr = 0; jr < ring.getAtomCount(); jr++) {
147145
IAtom aring = ring.getAtom(jr);
148146
aring.setFlag(CDKConstants.ISINRING, true);
@@ -160,7 +158,7 @@ public IReactionSet initiate(IMoleculeSet reactants, IMoleculeSet agents) throws
160158
if(atomi.getFlag(CDKConstants.REACTIVE_CENTER)
161159
&& reactant.getConnectedSingleElectronsCount(atomi) == 1) {
162160

163-
hcg.getSpheres((Molecule) reactant, atomi, 3, true);
161+
hcg.getSpheres((IMolecule) reactant, atomi, 3, true);
164162
Iterator<IAtom> atomls = hcg.getNodesInSphere(3).iterator();
165163
while(atomls.hasNext()){
166164
IAtom atoml = atomls.next();
@@ -217,7 +215,7 @@ private void setActiveCenters(IMolecule reactant) throws CDKException {
217215
IAtom atomi = atomis.next();
218216
if(reactant.getConnectedSingleElectronsCount(atomi) == 1) {
219217

220-
hcg.getSpheres((Molecule) reactant, atomi, 3, true);
218+
hcg.getSpheres((IMolecule) reactant, atomi, 3, true);
221219
Iterator<IAtom> atomls = hcg.getNodesInSphere(3).iterator();
222220
while(atomls.hasNext()){
223221
IAtom atoml = atomls.next();

src/main/org/openscience/cdk/reaction/type/RadicalSiteHrDeltaReaction.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@
2929
import java.util.Iterator;
3030

3131
import org.openscience.cdk.CDKConstants;
32-
import org.openscience.cdk.Molecule;
33-
import org.openscience.cdk.DefaultChemObjectBuilder;
34-
import org.openscience.cdk.Ring;
3532
import org.openscience.cdk.annotations.TestClass;
3633
import org.openscience.cdk.annotations.TestMethod;
3734
import org.openscience.cdk.aromaticity.CDKHueckelAromaticityDetector;
@@ -42,6 +39,7 @@
4239
import org.openscience.cdk.interfaces.IMoleculeSet;
4340
import org.openscience.cdk.interfaces.IReaction;
4441
import org.openscience.cdk.interfaces.IReactionSet;
42+
import org.openscience.cdk.interfaces.IRing;
4543
import org.openscience.cdk.interfaces.IRingSet;
4644
import org.openscience.cdk.reaction.IReactionProcess;
4745
import org.openscience.cdk.reaction.ReactionEngine;
@@ -135,15 +133,15 @@ public IReactionSet initiate(IMoleculeSet reactants, IMoleculeSet agents) throws
135133
throw new CDKException("RadicalSiteHrDeltaReaction don't expects agents");
136134
}
137135

138-
IReactionSet setOfReactions = DefaultChemObjectBuilder.getInstance().newInstance(IReactionSet.class);
136+
IReactionSet setOfReactions = reactants.getBuilder().newInstance(IReactionSet.class);
139137
IMolecule reactant = reactants.getMolecule(0);
140138

141139
AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(reactant);
142140
CDKHueckelAromaticityDetector.detectAromaticity(reactant);
143141
AllRingsFinder arf = new AllRingsFinder();
144-
IRingSet ringSet = arf.findAllRings((Molecule) reactant);
142+
IRingSet ringSet = arf.findAllRings((IMolecule) reactant);
145143
for (int ir = 0; ir < ringSet.getAtomContainerCount(); ir++) {
146-
Ring ring = (Ring)ringSet.getAtomContainer(ir);
144+
IRing ring = (IRing)ringSet.getAtomContainer(ir);
147145
for (int jr = 0; jr < ring.getAtomCount(); jr++) {
148146
IAtom aring = ring.getAtom(jr);
149147
aring.setFlag(CDKConstants.ISINRING, true);
@@ -161,7 +159,7 @@ public IReactionSet initiate(IMoleculeSet reactants, IMoleculeSet agents) throws
161159
if(atomi.getFlag(CDKConstants.REACTIVE_CENTER)
162160
&& reactant.getConnectedSingleElectronsCount(atomi) == 1) {
163161

164-
hcg.getSpheres((Molecule) reactant, atomi, 5, true);
162+
hcg.getSpheres((IMolecule) reactant, atomi, 5, true);
165163
Iterator<IAtom> atomls = hcg.getNodesInSphere(5).iterator();
166164
while(atomls.hasNext()){
167165
IAtom atoml = atomls.next();
@@ -218,7 +216,7 @@ private void setActiveCenters(IMolecule reactant) throws CDKException {
218216
IAtom atomi = atomis.next();
219217
if(reactant.getConnectedSingleElectronsCount(atomi) == 1) {
220218

221-
hcg.getSpheres((Molecule) reactant, atomi, 5, true);
219+
hcg.getSpheres((IMolecule) reactant, atomi, 5, true);
222220
Iterator<IAtom> atomls = hcg.getNodesInSphere(5).iterator();
223221
while(atomls.hasNext()){
224222
IAtom atoml = atomls.next();

src/main/org/openscience/cdk/reaction/type/RadicalSiteHrGammaReaction.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@
2929
import java.util.Iterator;
3030

3131
import org.openscience.cdk.CDKConstants;
32-
import org.openscience.cdk.Molecule;
33-
import org.openscience.cdk.DefaultChemObjectBuilder;
34-
import org.openscience.cdk.Ring;
3532
import org.openscience.cdk.annotations.TestClass;
3633
import org.openscience.cdk.annotations.TestMethod;
3734
import org.openscience.cdk.aromaticity.CDKHueckelAromaticityDetector;
@@ -42,6 +39,7 @@
4239
import org.openscience.cdk.interfaces.IMoleculeSet;
4340
import org.openscience.cdk.interfaces.IReaction;
4441
import org.openscience.cdk.interfaces.IReactionSet;
42+
import org.openscience.cdk.interfaces.IRing;
4543
import org.openscience.cdk.interfaces.IRingSet;
4644
import org.openscience.cdk.reaction.IReactionProcess;
4745
import org.openscience.cdk.reaction.ReactionEngine;
@@ -134,15 +132,15 @@ public IReactionSet initiate(IMoleculeSet reactants, IMoleculeSet agents) throws
134132
throw new CDKException("RadicalSiteHrGammaReaction don't expects agents");
135133
}
136134

137-
IReactionSet setOfReactions = DefaultChemObjectBuilder.getInstance().newInstance(IReactionSet.class);
135+
IReactionSet setOfReactions = reactants.getBuilder().newInstance(IReactionSet.class);
138136
IMolecule reactant = reactants.getMolecule(0);
139137

140138
AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(reactant);
141139
CDKHueckelAromaticityDetector.detectAromaticity(reactant);
142140
AllRingsFinder arf = new AllRingsFinder();
143-
IRingSet ringSet = arf.findAllRings((Molecule) reactant);
141+
IRingSet ringSet = arf.findAllRings((IMolecule) reactant);
144142
for (int ir = 0; ir < ringSet.getAtomContainerCount(); ir++) {
145-
Ring ring = (Ring)ringSet.getAtomContainer(ir);
143+
IRing ring = (IRing)ringSet.getAtomContainer(ir);
146144
for (int jr = 0; jr < ring.getAtomCount(); jr++) {
147145
IAtom aring = ring.getAtom(jr);
148146
aring.setFlag(CDKConstants.ISINRING, true);
@@ -160,7 +158,7 @@ public IReactionSet initiate(IMoleculeSet reactants, IMoleculeSet agents) throws
160158
if(atomi.getFlag(CDKConstants.REACTIVE_CENTER) && atomi.getSymbol().equals("C")
161159
&& reactant.getConnectedSingleElectronsCount(atomi) == 1) {
162160

163-
hcg.getSpheres((Molecule) reactant, atomi, 4, true);
161+
hcg.getSpheres((IMolecule) reactant, atomi, 4, true);
164162
Iterator<IAtom> atomls = hcg.getNodesInSphere(4).iterator();
165163
while(atomls.hasNext()){
166164
IAtom atoml = atomls.next();
@@ -218,7 +216,7 @@ private void setActiveCenters(IMolecule reactant) throws CDKException {
218216
if(atomi.getSymbol().equals("C")
219217
&& reactant.getConnectedSingleElectronsCount(atomi) == 1) {
220218

221-
hcg.getSpheres((Molecule) reactant, atomi, 4, true);
219+
hcg.getSpheres((IMolecule) reactant, atomi, 4, true);
222220
Iterator<IAtom> atomls = hcg.getNodesInSphere(4).iterator();
223221
while(atomls.hasNext()){
224222
IAtom atoml = atomls.next();

src/main/org/openscience/cdk/reaction/type/RadicalSiteRrAlphaReaction.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@
3030
import java.util.List;
3131

3232
import org.openscience.cdk.CDKConstants;
33-
import org.openscience.cdk.Molecule;
34-
import org.openscience.cdk.DefaultChemObjectBuilder;
35-
import org.openscience.cdk.Ring;
3633
import org.openscience.cdk.annotations.TestClass;
3734
import org.openscience.cdk.annotations.TestMethod;
3835
import org.openscience.cdk.aromaticity.CDKHueckelAromaticityDetector;
@@ -43,6 +40,7 @@
4340
import org.openscience.cdk.interfaces.IMoleculeSet;
4441
import org.openscience.cdk.interfaces.IReaction;
4542
import org.openscience.cdk.interfaces.IReactionSet;
43+
import org.openscience.cdk.interfaces.IRing;
4644
import org.openscience.cdk.interfaces.IRingSet;
4745
import org.openscience.cdk.reaction.IReactionProcess;
4846
import org.openscience.cdk.reaction.ReactionEngine;
@@ -135,15 +133,15 @@ public IReactionSet initiate(IMoleculeSet reactants, IMoleculeSet agents) throws
135133
throw new CDKException("RadicalSiteRrAlphaReaction don't expects agents");
136134
}
137135

138-
IReactionSet setOfReactions = DefaultChemObjectBuilder.getInstance().newInstance(IReactionSet.class);
136+
IReactionSet setOfReactions = reactants.getBuilder().newInstance(IReactionSet.class);
139137
IMolecule reactant = reactants.getMolecule(0);
140138

141139
AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(reactant);
142140
CDKHueckelAromaticityDetector.detectAromaticity(reactant);
143141
AllRingsFinder arf = new AllRingsFinder();
144-
IRingSet ringSet = arf.findAllRings((Molecule) reactant);
142+
IRingSet ringSet = arf.findAllRings((IMolecule) reactant);
145143
for (int ir = 0; ir < ringSet.getAtomContainerCount(); ir++) {
146-
Ring ring = (Ring)ringSet.getAtomContainer(ir);
144+
IRing ring = (IRing)ringSet.getAtomContainer(ir);
147145
for (int jr = 0; jr < ring.getAtomCount(); jr++) {
148146
IAtom aring = ring.getAtom(jr);
149147
aring.setFlag(CDKConstants.ISINRING, true);
@@ -161,10 +159,10 @@ public IReactionSet initiate(IMoleculeSet reactants, IMoleculeSet agents) throws
161159
if(atomi.getFlag(CDKConstants.REACTIVE_CENTER)
162160
&& reactant.getConnectedSingleElectronsCount(atomi) == 1) {
163161

164-
hcg.getSpheres((Molecule) reactant, atomi, 1, true);
162+
hcg.getSpheres((IMolecule) reactant, atomi, 1, true);
165163
List<IAtom> atom1s = hcg.getNodesInSphere(1);
166164

167-
hcg.getSpheres((Molecule) reactant, atomi, 2, true);
165+
hcg.getSpheres((IMolecule) reactant, atomi, 2, true);
168166
Iterator<IAtom> atomls = hcg.getNodesInSphere(2).iterator();
169167
while(atomls.hasNext()){
170168
IAtom atoml = atomls.next();
@@ -224,10 +222,10 @@ private void setActiveCenters(IMolecule reactant) throws CDKException {
224222
IAtom atomi = atomis.next();
225223
if(reactant.getConnectedSingleElectronsCount(atomi) == 1) {
226224

227-
hcg.getSpheres((Molecule) reactant, atomi, 1, true);
225+
hcg.getSpheres((IMolecule) reactant, atomi, 1, true);
228226
List<IAtom> atom1s = hcg.getNodesInSphere(1);
229227

230-
hcg.getSpheres((Molecule) reactant, atomi, 2, true);
228+
hcg.getSpheres((IMolecule) reactant, atomi, 2, true);
231229
Iterator<IAtom> atomls = hcg.getNodesInSphere(2).iterator();
232230
while(atomls.hasNext()){
233231
IAtom atoml = atomls.next();

0 commit comments

Comments
 (0)