@Test public void testFindBond() { frag.addAtom(new Atom(1, ChemEl.C, frag)); frag.addAtom(new Atom(2, ChemEl.C, frag)); frag.addAtom(new Atom(3, ChemEl.N, frag)); frag.addAtom(new Atom(4, ChemEl.O, frag)); fm.createBond(frag.getAtomByID(2), frag.getAtomByID(4), 2); fm.createBond(frag.getAtomByID(1), frag.getAtomByID(2), 1); fm.createBond(frag.getAtomByID(1), frag.getAtomByID(3), 3); Bond b = frag.findBond(2, 4); assertNotNull("Found a bond", b); assertEquals("..a double bond", 2, b.getOrder()); b = frag.findBond(3, 1); assertNotNull("Found a different bond", b); assertEquals("..a triple bond", 3, b.getOrder()); b = frag.findBond(2, 3); assertNull("Don't find non-existent bonds", b); }
Bond findBond(int ID1, int ID2) { Atom a = atomMapFromId.get(ID1); if (a != null){ for (Bond b : a.getBonds()) { if((b.getFrom() == ID1 && b.getTo() == ID2) || (b.getTo() == ID1 && b.getFrom() == ID2)) { return b; } } } return null; }
Fragment implements Iterable<Atom> { Bond findBond(int ID1, int ID2) { Atom a = atomMapFromId.get(ID1); if (a != null){ for (Bond b : a.getBonds()) { if((b.getFrom() == ID1 && b.getTo() == ID2) || (b.getTo() == ID1 && b.getFrom() == ID2)) { return b; } } } return null; } }
Fragment implements Iterable<Atom> { Bond findBond(int ID1, int ID2) { Atom a = atomMapFromId.get(ID1); if (a != null){ for (Bond b : a.getBonds()) { if((b.getFrom() == ID1 && b.getTo() == ID2) || (b.getTo() == ID1 && b.getFrom() == ID2)) { return b; } } } return null; } Fragment(Element tokenEl);   Fragment(String type); }
Fragment implements Iterable<Atom> { Bond findBond(int ID1, int ID2) { Atom a = atomMapFromId.get(ID1); if (a != null){ for (Bond b : a.getBonds()) { if((b.getFrom() == ID1 && b.getTo() == ID2) || (b.getTo() == ID1 && b.getFrom() == ID2)) { return b; } } } return null; } Fragment(Element tokenEl);   Fragment(String type); @Override Iterator<Atom> iterator(); }
Fragment implements Iterable<Atom> { Bond findBond(int ID1, int ID2) { Atom a = atomMapFromId.get(ID1); if (a != null){ for (Bond b : a.getBonds()) { if((b.getFrom() == ID1 && b.getTo() == ID2) || (b.getTo() == ID1 && b.getFrom() == ID2)) { return b; } } } return null; } Fragment(Element tokenEl);   Fragment(String type); @Override Iterator<Atom> iterator();  }