/** * Utility method to dereference an bond pointer. If the bond is not * an {@link BondRef} it simply returns the input. * * @param bond the bond * @return non-pointer bond */ public static IBond deref(IBond bond) { while (bond instanceof BondRef) bond = ((BondRef) bond).deref(); return bond; }
private void delFromEndpoints(BondRef bondref) { for (int i = 0; i < bondref.getAtomCount(); i++) { BaseAtomRef aref = getAtomRefUnsafe(bondref.getAtom(i)); // atom may have already been deleted, naughty! if (aref != null) aref.bonds.remove(bondref); } }
/** * {@inheritDoc} */ @Override public int indexOf(IBond bond) { final BondRef bref = getBondRefUnsafe(bond); return bref == null ? -1 : bref.getIndex(); }
@Override public IAtom getAtom(int idx) { switch (idx) { case 0: return getBegin(); case 1: return getEnd(); default: return mol.getAtomRef(super.getAtom(idx)); } }
@Override public void setAtom(IAtom atom, int idx) { super.setAtom(atom, idx); if (idx == 0) { if (beg != null) beg.bonds.remove(this); beg = mol.getAtomRef(atom); beg.bonds.add(this); } else if (idx == 1) { if (end != null) end.bonds.remove(this); end = mol.getAtomRef(atom); end.bonds.add(this); } }
@Override public void setAtoms(IAtom[] atoms) { assert atoms.length == 2; super.setAtoms(atoms); // check for swap: intended ref check if (atoms[0] == end && atoms[1] == beg) { BaseAtomRef tmp = beg; beg = end; end = tmp; return; } if (beg != null) beg.bonds.remove(this); if (end != null) end.bonds.remove(this); beg = mol.getAtomRef(atoms[0]); end = mol.getAtomRef(atoms[1]); beg.bonds.add(this); end.bonds.add(this); }
@Override public IAtom getAtom(int idx) { switch (idx) { case 0: return getBegin(); case 1: return getEnd(); default: return mol.getAtomRef(super.getAtom(idx)); } }
@Override public void setAtom(IAtom atom, int idx) { super.setAtom(atom, idx); if (idx == 0) { if (beg != null) beg.bonds.remove(this); beg = mol.getAtomRef(atom); beg.bonds.add(this); } else if (idx == 1) { if (end != null) end.bonds.remove(this); end = mol.getAtomRef(atom); end.bonds.add(this); } }
@Override public void setAtoms(IAtom[] atoms) { assert atoms.length == 2; super.setAtoms(atoms); // check for swap: intended ref check if (atoms[0] == end && atoms[1] == beg) { BaseAtomRef tmp = beg; beg = end; end = tmp; return; } if (beg != null) beg.bonds.remove(this); if (end != null) end.bonds.remove(this); beg = mol.getAtomRef(atoms[0]); end = mol.getAtomRef(atoms[1]); beg.bonds.add(this); end.bonds.add(this); }
private static IBond unbox(IBond bond) { while (bond instanceof BondRef) bond = ((BondRef) bond).deref(); return bond; }
private void delFromEndpoints(BondRef bondref) { for (int i = 0; i < bondref.getAtomCount(); i++) { BaseAtomRef aref = getAtomRefUnsafe(bondref.getAtom(i)); // atom may have already been deleted, naughty! if (aref != null) aref.bonds.remove(bondref); } }
@Override public IAtom getAtom(int idx) { switch (idx) { case 0: return getBegin(); case 1: return getEnd(); default: return mol.getAtomRef(super.getAtom(idx)); } }
/** * {@inheritDoc} */ @Override public int indexOf(IBond bond) { final BondRef bref = getBondRefUnsafe(bond); return bref == null ? -1 : bref.getIndex(); }
@Override public void setAtom(IAtom atom, int idx) { super.setAtom(atom, idx); if (idx == 0) { if (beg != null) beg.bonds.remove(this); beg = mol.getAtomRef(atom); beg.bonds.add(this); } else if (idx == 1) { if (end != null) end.bonds.remove(this); end = mol.getAtomRef(atom); end.bonds.add(this); } }
@Override public void setAtoms(IAtom[] atoms) { assert atoms.length == 2; super.setAtoms(atoms); // check for swap: intended ref check if (Objects.equals(atoms[0], end) && Objects.equals(atoms[1], beg)) { BaseAtomRef tmp = beg; beg = end; end = tmp; return; } if (beg != null) beg.bonds.remove(this); if (end != null) end.bonds.remove(this); beg = mol.getAtomRef(atoms[0]); end = mol.getAtomRef(atoms[1]); beg.bonds.add(this); end.bonds.add(this); }