/** * Clones this <code>Reaction</code> and its content. * * @return The cloned object */ @Override public Object clone() throws CloneNotSupportedException { Reaction clone = (Reaction) super.clone(); // clone the reactants, products and agents clone.reactants = (IAtomContainerSet) reactants.clone(); clone.agents = (IAtomContainerSet) agents.clone(); clone.products = (IAtomContainerSet) products.clone(); // create a Map of corresponding atoms for molecules (key: original Atom, // value: clone Atom) Map<IAtom, IAtom> atomatom = new Hashtable<IAtom, IAtom>(); for (int i = 0; i < reactants.getAtomContainerCount(); ++i) { IAtomContainer mol = reactants.getAtomContainer(i); IAtomContainer mol2 = clone.reactants.getAtomContainer(i); for (int j = 0; j < mol.getAtomCount(); ++j) atomatom.put(mol.getAtom(j), mol2.getAtom(j)); } // clone the maps clone.map = new Mapping[map.length]; for (int f = 0; f < mappingCount; f++) { clone.map[f] = new Mapping(atomatom.get(map[f].getChemObject(0)), atomatom.get(map[f].getChemObject(1))); } return clone; }
/** * Clones this <code>Reaction</code> and its content. * * @return The cloned object */ @Override public Object clone() throws CloneNotSupportedException { Reaction clone = (Reaction) super.clone(); // clone the reactants, products and agents clone.reactants = (IAtomContainerSet) reactants.clone(); clone.agents = (IAtomContainerSet) agents.clone(); clone.products = (IAtomContainerSet) products.clone(); // create a Map of corresponding atoms for molecules (key: original Atom, // value: clone Atom) Map<IAtom, IAtom> atomatom = new Hashtable<IAtom, IAtom>(); for (int i = 0; i < reactants.getAtomContainerCount(); ++i) { IAtomContainer mol = reactants.getAtomContainer(i); IAtomContainer mol2 = clone.reactants.getAtomContainer(i); for (int j = 0; j < mol.getAtomCount(); ++j) atomatom.put(mol.getAtom(j), mol2.getAtom(j)); } // clone the maps clone.map = new Mapping[map.length]; for (int f = 0; f < mappingCount; f++) { clone.map[f] = new Mapping(atomatom.get(map[f].getChemObject(0)), atomatom.get(map[f].getChemObject(1))); } return clone; }
/** * Clones this <code>Reaction</code> and its content. * * @return The cloned object */ @Override public Object clone() throws CloneNotSupportedException { Reaction clone = (Reaction) super.clone(); // clone the reactants, products and agents clone.reactants = (IAtomContainerSet) reactants.clone(); clone.agents = (IAtomContainerSet) agents.clone(); clone.products = (IAtomContainerSet) products.clone(); // create a Map of corresponding atoms for molecules (key: original Atom, // value: clone Atom) Map<IAtom, IAtom> atomatom = new Hashtable<IAtom, IAtom>(); for (int i = 0; i < reactants.getAtomContainerCount(); ++i) { IAtomContainer mol = reactants.getAtomContainer(i); IAtomContainer mol2 = clone.reactants.getAtomContainer(i); for (int j = 0; j < mol.getAtomCount(); ++j) atomatom.put(mol.getAtom(j), mol2.getAtom(j)); } // clone the maps clone.map = new Mapping[map.length]; for (int f = 0; f < mappingCount; f++) { clone.map[f] = new Mapping(atomatom.get(map[f].getChemObject(0)), atomatom.get(map[f].getChemObject(1))); } return clone; }
/** * Clones this <code>Reaction</code> and its content. * * @return The cloned object */ @Override public Object clone() throws CloneNotSupportedException { Reaction clone = (Reaction) super.clone(); // clone the reactants, products and agents clone.reactants = (IAtomContainerSet) reactants.clone(); clone.agents = (IAtomContainerSet) agents.clone(); clone.products = (IAtomContainerSet) products.clone(); // create a Map of corresponding atoms for molecules (key: original Atom, // value: clone Atom) Map<IAtom, IAtom> atomatom = new Hashtable<IAtom, IAtom>(); for (int i = 0; i < reactants.getAtomContainerCount(); ++i) { IAtomContainer mol = reactants.getAtomContainer(i); IAtomContainer mol2 = clone.reactants.getAtomContainer(i); for (int j = 0; j < mol.getAtomCount(); ++j) atomatom.put(mol.getAtom(j), mol2.getAtom(j)); } // clone the maps clone.map = new Mapping[map.length]; for (int f = 0; f < mappingCount; f++) { clone.map[f] = new Mapping(atomatom.get(map[f].getChemObject(0)), atomatom.get(map[f].getChemObject(1))); } return clone; }
clone.setOfMolecules = (IAtomContainerSet) setOfMolecules.clone(); } else { clone.setOfMolecules = null;
clone.setOfMolecules = (IAtomContainerSet) setOfMolecules.clone(); } else { clone.setOfMolecules = null;
clone.setOfMolecules = (AtomContainerSet) setOfMolecules.clone(); } else { clone.setOfMolecules = null;
clone.setOfMolecules = (AtomContainerSet) setOfMolecules.clone(); } else { clone.setOfMolecules = null;
@Override @Test public void testClone() throws Exception { IAtomContainerSet containerSet = (IAtomContainerSet) newChemObject(); Object clone = containerSet.clone(); Assert.assertTrue(clone instanceof IAtomContainerSet); Assert.assertNotSame(containerSet, clone); }
@Test public void testCloneMultiplier() throws Exception { IAtomContainerSet containerSet = (IAtomContainerSet) newChemObject(); containerSet.addAtomContainer(containerSet.getBuilder().newInstance(IAtomContainer.class), 2); Object clone = containerSet.clone(); Assert.assertTrue(clone instanceof IAtomContainerSet); IAtomContainerSet clonedSet = (IAtomContainerSet) clone; Assert.assertNotSame(containerSet, clonedSet); Assert.assertEquals(2, containerSet.getMultiplier(0).intValue()); Assert.assertEquals(2, clonedSet.getMultiplier(0).intValue()); }
@Test public void testCloneDuplication() throws Exception { IAtomContainerSet containerSet = (IAtomContainerSet) newChemObject(); containerSet.addAtomContainer(containerSet.getBuilder().newInstance(IAtomContainer.class)); Object clone = containerSet.clone(); Assert.assertTrue(clone instanceof IAtomContainerSet); IAtomContainerSet clonedSet = (IAtomContainerSet) clone; Assert.assertNotSame(containerSet, clonedSet); Assert.assertEquals(containerSet.getAtomContainerCount(), clonedSet.getAtomContainerCount()); }