Skip to content

Commit

Permalink
Fixes for the pseudo atom patch backporting: allow reading of IAtomCo…
Browse files Browse the repository at this point in the history
…ntainer where IMolecule was already supported, fixed imports. Also removes an redundant, incorrect accepts() method

Signed-off-by: Rajarshi  Guha <rajarshi.guha@gmail.com>
  • Loading branch information
egonw authored and rajarshi committed Jan 22, 2012
1 parent e59d204 commit 7dc949f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
4 changes: 4 additions & 0 deletions src/main/org/openscience/cdk/io/MDLV2000Reader.java
Expand Up @@ -29,6 +29,7 @@
import org.openscience.cdk.config.IsotopeFactory;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IBond;
import org.openscience.cdk.interfaces.IChemFile;
import org.openscience.cdk.interfaces.IChemModel;
Expand Down Expand Up @@ -164,6 +165,7 @@ public boolean accepts(Class<? extends IChemObject> classObject) {
if (IChemFile.class.equals(interfaces[i])) return true;
if (IChemModel.class.equals(interfaces[i])) return true;
if (IMolecule.class.equals(interfaces[i])) return true;
if (IAtomContainer.class.equals(interfaces[i])) return true;
}
Class superClass = classObject.getSuperclass();
if (superClass != null) return this.accepts(superClass);
Expand All @@ -187,6 +189,8 @@ public <T extends IChemObject> T read(T object) throws CDKException {
return (T)readChemModel((IChemModel)object);
} else if (object instanceof IMolecule) {
return (T)readMolecule((IMolecule)object);
} else if (object instanceof IAtomContainer) {
return (T)readMolecule(object.getBuilder().newInstance(IMolecule.class, object));
} else {
throw new CDKException("Only supported are ChemFile and Molecule.");
}
Expand Down
11 changes: 2 additions & 9 deletions src/main/org/openscience/cdk/io/MDLV3000Reader.java
Expand Up @@ -128,14 +128,15 @@ public boolean accepts(Class classObject) {
Class[] interfaces = classObject.getInterfaces();
for (int i=0; i<interfaces.length; i++) {
if (IMolecule.class.equals(interfaces[i])) return true;
if (IAtomContainer.class.equals(interfaces[i])) return true;
}
Class superClass = classObject.getSuperclass();
if (superClass != null) return this.accepts(superClass);
return false;
}

public <T extends IChemObject> T read(T object) throws CDKException {
if (object instanceof IMolecule) {
if (object instanceof IAtomContainer) {
return (T)readMolecule(object.getBuilder());
}
return null;
Expand Down Expand Up @@ -585,14 +586,6 @@ public boolean isReady() throws CDKException {
}
}

@TestMethod("testAccepts")
public boolean accepts(IChemObject object) {
if (object instanceof IMolecule) {
return true;
}
return false;
}

@TestMethod("testClose")
public void close() throws IOException {
input.close();
Expand Down
15 changes: 8 additions & 7 deletions src/test/org/openscience/cdk/io/MDLV2000WriterTest.java
Expand Up @@ -24,10 +24,16 @@
package org.openscience.cdk.io;


import java.io.InputStream;
import java.io.StringWriter;
import java.util.Properties;

import javax.vecmath.Point2d;
import javax.vecmath.Point3d;

import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

import org.openscience.cdk.Atom;
import org.openscience.cdk.AtomContainer;
import org.openscience.cdk.Bond;
Expand All @@ -39,6 +45,7 @@
import org.openscience.cdk.PseudoAtom;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IBond;
import org.openscience.cdk.interfaces.IBond.Order;
import org.openscience.cdk.interfaces.IChemModel;
Expand All @@ -51,12 +58,6 @@
import org.openscience.cdk.smiles.SmilesParser;
import org.openscience.cdk.templates.MoleculeFactory;

import javax.vecmath.Point2d;
import javax.vecmath.Point3d;
import java.io.StringWriter;
import java.io.InputStream;
import java.util.Properties;


/**
* TestCase for the writer MDL mol files using one test file.
Expand Down
5 changes: 3 additions & 2 deletions src/test/org/openscience/cdk/io/MDLV3000ReaderTest.java
Expand Up @@ -30,15 +30,16 @@
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openscience.cdk.DefaultChemObjectBuilder;
import org.openscience.cdk.Molecule;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IMolecule;
import org.openscience.cdk.nonotify.NNMolecule;
import org.openscience.cdk.interfaces.IPseudoAtom;
import org.openscience.cdk.nonotify.NNMolecule;
import org.openscience.cdk.tools.ILoggingTool;
import org.openscience.cdk.tools.LoggingToolFactory;
import org.openscience.cdk.DefaultChemObjectBuilder;

/**
* TestCase for the reading MDL V3000 mol files using one test file.
Expand Down

0 comments on commit 7dc949f

Please sign in to comment.