/** * Clones this <code>ReactionSet</code> and the contained <code>Reaction</code>s * too. * * @return The cloned ReactionSet */ @Override public Object clone() throws CloneNotSupportedException { ReactionSet clone = (ReactionSet) super.clone(); // clone the reactions clone.reactionCount = this.reactionCount; clone.reactions = new IReaction[clone.reactionCount]; for (int f = 0; f < clone.reactionCount; f++) { clone.reactions[f] = (IReaction) ((IReaction) reactions[f]).clone(); } return clone; }
/** * Clones this <code>ReactionSet</code> and the contained <code>Reaction</code>s * too. * * @return The cloned ReactionSet */ @Override public Object clone() throws CloneNotSupportedException { ReactionSet clone = (ReactionSet) super.clone(); // clone the reactions clone.reactionCount = this.reactionCount; clone.reactions = new IReaction[clone.reactionCount]; for (int f = 0; f < clone.reactionCount; f++) { clone.reactions[f] = (IReaction) ((IReaction) reactions[f]).clone(); } return clone; }
clone.addReaction((IReaction) reaction.clone());
clone.addReaction((IReaction) reaction.clone());
clone.addReaction((IReaction) reaction.clone());
clone.addReaction((IReaction) reaction.clone());
@Test @Override public void testClone() throws Exception { IReaction reaction = (IReaction) newChemObject(); Object clone = reaction.clone(); Assert.assertNotNull(clone); Assert.assertTrue(clone instanceof IReaction); }
@Test public void testClone_Mapping() throws Exception { IReaction reaction = (IReaction) newChemObject(); IMapping mapping = reaction.getBuilder().newInstance(IMapping.class, reaction.getBuilder().newInstance(IAtom.class, "C"), reaction.getBuilder().newInstance(IAtom.class, "C")); reaction.addMapping(mapping); IReaction clonedReaction = (IReaction) reaction.clone(); Iterator<IMapping> mappings = reaction.mappings().iterator(); Iterator<IMapping> clonedMappings = clonedReaction.mappings().iterator(); Assert.assertNotNull(mappings); Assert.assertTrue(mappings.hasNext()); Assert.assertNotNull(clonedMappings); Assert.assertTrue(clonedMappings.hasNext()); }
@Test public void testShiftReactionVertical_IAtomContainer_Rectangle2D_Rectangle2D_double() throws Exception { IAtom atom1 = new Atom("C"); atom1.setPoint2d(new Point2d(0, 1)); IAtom atom2 = new Atom("C"); atom2.setPoint2d(new Point2d(1, 0)); IAtomContainer react1 = new AtomContainer(); IReaction reaction = new Reaction(); reaction.addReactant(react1); react1.addAtom(atom1); react1.addAtom(atom2); react1.addBond(0, 1, IBond.Order.SINGLE); IReaction reaction2 = (IReaction) reaction.clone(); IAtomContainer react2 = reaction2.getReactants().getAtomContainer(0); // shift the second reaction up GeometryUtil.shiftReactionVertical(reaction2, GeometryUtil.getMinMax(react2), GeometryUtil.getMinMax(react1), 1.0); // assert all coordinates of the second reaction moved up AtomContainerDiff.diff(react1, react2); for (int i = 0; i < 2; i++) { atom1 = react1.getAtom(0); atom2 = react2.getAtom(0); // so, x coordinates should be the same Assert.assertEquals(atom1.getPoint2d().x, atom2.getPoint2d().x, 0.0); // but, y coordinates should not Assert.assertTrue(atom1.getPoint2d().y < atom2.getPoint2d().y); } }
react1.addAtom(atom2); react1.addBond(0, 1, IBond.Order.SINGLE); IReaction reaction2 = (IReaction) reaction.clone(); IAtomContainer react2 = reaction2.getReactants().getAtomContainer(0);