public void undo() { if(chemModel.getMoleculeSet()==null) chemModel.setMoleculeSet(chemModel.getBuilder().newInstance(IAtomContainerSet.class)); chemModel.getMoleculeSet().addAtomContainer(oldContainer); chemModel.getReactionSet().removeReaction(ReactionSetManipulator.getReactionByAtomContainerID(chemModel.getReactionSet(), movedContainer.getID())); }
public void undo() { if(chemModel.getMoleculeSet()==null) chemModel.setMoleculeSet(chemModel.getBuilder().newInstance(IAtomContainerSet.class)); chemModel.getMoleculeSet().addAtomContainer(oldContainer); IAtomContainerSet reactantsorproducts; if(reactantOrProduct) reactantsorproducts = ReactionSetManipulator.getReactionByReactionID(chemModel.getReactionSet(), reactionID).getReactants(); else reactantsorproducts = ReactionSetManipulator.getReactionByReactionID(chemModel.getReactionSet(), reactionID).getProducts(); IReaction reaction = ReactionSetManipulator.getReactionByReactionID(chemModel.getReactionSet(), reactionID); int count=0; for(IAtomContainer mol : reactantsorproducts.atomContainers()){ if(mol.getID().equals(movedContainer.getID())){ reactantsorproducts.removeAtomContainer(count); break; } count++; } if(reaction.getReactantCount()==0 && reaction.getProductCount()==0) chemModel.getReactionSet().removeReaction(reaction); if(chemModel.getReactionSet().getReactionCount()==0) chemModel.setReactionSet(null); }
@Test public void testRemoveReaction_IReaction() { IReactionSet reactionSet = (IReactionSet) newChemObject(); IReaction reaction = reactionSet.getBuilder().newInstance(IReaction.class); reaction.setID("1"); reactionSet.addReaction(reaction); IReaction relevantReaction = reactionSet.getBuilder().newInstance(IReaction.class); relevantReaction.setID("2"); reactionSet.addReaction(relevantReaction); Assert.assertEquals(2, reactionSet.getReactionCount()); reactionSet.removeReaction(relevantReaction); Assert.assertEquals(1, reactionSet.getReactionCount()); Assert.assertEquals("1", reactionSet.getReaction(0).getID()); reactionSet.addReaction(relevantReaction); reactionSet.addReaction(relevantReaction); Assert.assertEquals(3, reactionSet.getReactionCount()); reactionSet.removeReaction(relevantReaction); Assert.assertEquals(1, reactionSet.getReactionCount()); Assert.assertEquals("1", reactionSet.getReaction(0).getID()); }
@Test public void testRemoveReaction_int() { IReactionSet reactionSet = (IReactionSet) newChemObject(); reactionSet.addReaction(reactionSet.getBuilder().newInstance(IReaction.class)); // 1 reactionSet.addReaction(reactionSet.getBuilder().newInstance(IReaction.class)); // 2 reactionSet.addReaction(reactionSet.getBuilder().newInstance(IReaction.class)); // 3 Assert.assertEquals(3, reactionSet.getReactionCount()); reactionSet.removeReaction(1); Assert.assertEquals(2, reactionSet.getReactionCount()); Assert.assertNotNull(reactionSet.getReaction(0)); Assert.assertNotNull(reactionSet.getReaction(1)); }