/** * Adds this Bond to its atoms bond lists. If this method is not called, * then the list returned from calling {@link Atom#getBonds()} will not * include this bond. * <p> * If you created your Bond with the constructor * {@link #Bond(Atom, Atom, int)}, this method has already been called for * you and should not be called again. */ // TODO first check if those bonds haven't been made already private void addSelfToAtoms() { List<Bond> bonds = atomA.getBonds(); if (bonds==null) { bonds = new ArrayList<Bond>(AtomImpl.BONDS_INITIAL_CAPACITY); atomA.setBonds(bonds); } boolean exists = false; for (Bond bond : bonds) { // TODO is it equals() what we want here, or is it == ? - JD 2016-03-02 if (bond.getOther(atomA).equals(atomB)) { exists = true; break; } } if (!exists) { atomA.addBond(this); atomB.addBond(this); } }
protected void cloneAtomsAndBonds(Group newGroup) { // copy the atoms for (Atom atom1 : atoms) { Atom atom = (Atom) atom1.clone(); newGroup.addAtom(atom); atom.setGroup(newGroup); } // copy the bonds for (int i=0;i<atoms.size();i++) { Atom atom1 = atoms.get(i); List<Bond> bonds1 = atom1.getBonds(); if (bonds1 != null) { for (Bond b : bonds1) { int atomAIndex = atoms.indexOf(b.getAtomA()); int atomBIndex = atoms.indexOf(b.getAtomB()); // The order of the atoms are the same on the original and the cloned object, which we use here. Bond newBond = new BondImpl(newGroup.getAtom(atomAIndex), newGroup.getAtom(atomBIndex), b.getBondOrder(), false); newGroup.getAtom(i).addBond(newBond); } } } }