Update of /cvsroot/cdk/cdk/src/org/openscience/cdk/isomorphism/matchers In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10109/src/org/openscience/cdk/isomorphism/matchers Modified Files: OrderQueryBond.java QueryAtom.java QueryAtomContainer.java QueryBond.java SymbolQueryAtom.java Added Files: QueryAtomContainerCreator.java Log Message: More tweaks to the architecture. Result: The old UniversalIsomorphismTester is maintained, but *does* allow querying with QueryAtomContainer (see new test). However, the latter is not used yet, that will come in a moment. --- NEW FILE: QueryAtomContainerCreator.java --- /* $RCSfile: QueryAtomContainerCreator.java,v $ * $Author: egonw $ * $Date: 2004/03/03 13:09:28 $ * $Revision: 1.1 $ * * Copyright (C) 2004 The Chemistry Development Kit (CDK) project * * Contact: cdk...@li... * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; either version 2.1 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package org.openscience.cdk.isomorphism.matchers; import org.openscience.cdk.Atom; import org.openscience.cdk.AtomContainer; import org.openscience.cdk.Bond; /** * @cdk.module extra */ public class QueryAtomContainerCreator { /** * Creates a QueryAtomContainerCreator with SymbolQueryAtom's and * OrderQueryBond's. */ public static QueryAtomContainer createBasicQueryContainer(AtomContainer container) { QueryAtomContainer queryContainer = new QueryAtomContainer(); Atom[] atoms = container.getAtoms(); for (int i=0; i<atoms.length; i++) { queryContainer.addAtom(new SymbolQueryAtom(atoms[i])); } Bond[] bonds = container.getBonds(); for (int i=0; i<bonds.length; i++) { int index1 = container.getAtomNumber(bonds[i].getAtomAt(0)); int index2 = container.getAtomNumber(bonds[i].getAtomAt(1)); queryContainer.addBond(new OrderQueryBond((QueryAtom)queryContainer.getAtomAt(index1), (QueryAtom)queryContainer.getAtomAt(index1), bonds[i].getOrder())); } return queryContainer; } } Index: OrderQueryBond.java =================================================================== RCS file: /cvsroot/cdk/cdk/src/org/openscience/cdk/isomorphism/matchers/OrderQueryBond.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- OrderQueryBond.java 3 Mar 2004 10:36:47 -0000 1.1 +++ OrderQueryBond.java 3 Mar 2004 13:09:28 -0000 1.2 @@ -23,19 +23,39 @@ */ package org.openscience.cdk.isomorphism.matchers; +import org.openscience.cdk.Atom; import org.openscience.cdk.Bond; /** * @cdk.module extra */ -public class OrderQueryBond extends Bond { +public class OrderQueryBond extends Bond implements QueryBond { + + public OrderQueryBond() { + } public OrderQueryBond(QueryAtom atom1, QueryAtom atom2, double order) { - super(atom1, atom2, order); + super((Atom)atom1, (Atom)atom2, order); } public boolean matches(Bond bond) { throw new AbstractMethodError("The QueryBond class did not implement this method"); }; + + public void setAtoms(Atom[] atoms) { + if (atoms.length > 0 && atoms[0] instanceof QueryAtom) { + super.setAtoms(atoms); + } else { + throw new IllegalArgumentException("Array is not of type QueryAtom[]"); + } + } + + public void setAtomAt(Atom atom, int position) { + if (atom instanceof QueryAtom) { + super.setAtomAt(atom, position); + } else { + throw new IllegalArgumentException("Atom is not of type QueryAtom"); + } + } } Index: QueryAtom.java =================================================================== RCS file: /cvsroot/cdk/cdk/src/org/openscience/cdk/isomorphism/matchers/QueryAtom.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- QueryAtom.java 3 Mar 2004 10:36:48 -0000 1.3 +++ QueryAtom.java 3 Mar 2004 13:09:28 -0000 1.4 @@ -28,14 +28,9 @@ /** * @cdk.module extra */ -public abstract class QueryAtom extends Atom { +public interface QueryAtom { - public QueryAtom() { - throw new InstantiationError("An abstract QueryAtom should not be used directly"); - }; + public boolean matches(Atom atom); - public boolean matches(Atom atom) { - throw new AbstractMethodError("The QueryBond class did not implement this method"); - }; } Index: QueryAtomContainer.java =================================================================== RCS file: /cvsroot/cdk/cdk/src/org/openscience/cdk/isomorphism/matchers/QueryAtomContainer.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- QueryAtomContainer.java 3 Mar 2004 10:36:48 -0000 1.1 +++ QueryAtomContainer.java 3 Mar 2004 13:09:28 -0000 1.2 @@ -30,16 +30,11 @@ /** * @cdk.module extra */ -public abstract class QueryAtomContainer extends AtomContainer { +public class QueryAtomContainer extends AtomContainer { public QueryAtomContainer() { - throw new InstantiationError("An abstract QueryAtomContainer should not be used directly"); }; - public boolean matches(AtomContainer container) { - throw new AbstractMethodError("The QueryBond class did not implement this method"); - }; - public void add(AtomContainer container) { if (container instanceof QueryAtomContainer) { super.add(container); Index: QueryBond.java =================================================================== RCS file: /cvsroot/cdk/cdk/src/org/openscience/cdk/isomorphism/matchers/QueryBond.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- QueryBond.java 3 Mar 2004 10:36:48 -0000 1.1 +++ QueryBond.java 3 Mar 2004 13:09:28 -0000 1.2 @@ -29,30 +29,9 @@ /** * @cdk.module extra */ -public abstract class QueryBond extends Bond { +public interface QueryBond { - public QueryBond() { - throw new InstantiationError("An abstract QueryBond should not be used directly"); - }; + public boolean matches(Bond bond); - public boolean matches(Bond bond) { - throw new AbstractMethodError("The QueryBond class did not implement this method"); - }; - - public void setAtoms(Atom[] atoms) { - if (atoms.length > 0 && atoms[0] instanceof QueryAtom) { - super.setAtoms(atoms); - } else { - throw new IllegalArgumentException("Array is not of type QueryAtom[]"); - } - } - - public void setAtomAt(Atom atom, int position) { - if (atom instanceof QueryAtom) { - super.setAtomAt(atom, position); - } else { - throw new IllegalArgumentException("Atom is not of type QueryAtom"); - } - } } Index: SymbolQueryAtom.java =================================================================== RCS file: /cvsroot/cdk/cdk/src/org/openscience/cdk/isomorphism/matchers/SymbolQueryAtom.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- SymbolQueryAtom.java 3 Mar 2004 10:36:48 -0000 1.1 +++ SymbolQueryAtom.java 3 Mar 2004 13:09:28 -0000 1.2 @@ -28,10 +28,12 @@ /** * @cdk.module extra */ -public class SymbolQueryAtom extends Atom { +public class SymbolQueryAtom extends Atom implements QueryAtom { - public SymbolQueryAtom(String elementSymbol) { - super(elementSymbol); + public SymbolQueryAtom() {} + + public SymbolQueryAtom(Atom atom) { + super(atom.getSymbol()); } public boolean matches(Atom atom) { |