/** * gets atom by id. * * @param id * @return the atom or null */ public CMLAtom getAtomByIdXX(String id) { CMLAtom atom = null; if (getMoleculeCount() > 0) { getChildMoleculeAtomMap(); List<CMLAtom> atomList = childMoleculeAtomMap.get(id); if (atomList != null && atomList.size() == 1) { atom = atomList.get(0); } } else { CMLAtomArray atomArray = getAtomArray(); if (atomArray != null) { atom = atomArray.getAtomById(id); } } return atom; }
/** add atom. * * only if in same molecule. If already added returns with no-op * cannot add to child molecule. However if 'this' is a child of * a CMLMolecule throws Exception * @param atom * @throws RuntimeException * null, non-uniqueID, etc. */ public void addAtom(CMLAtom atom) throws RuntimeException { if (atom != null) { //ParentNode parent = this.getParent(); //if (parent instanceof CMLMolecule) { // throw new RuntimeException("Cannot add atom to child molecule"); //} CMLAtomArray atomArray = getOrCreateAtomArray(); // should it be atom array that tests this? String id = atom.getId(); if (id == null) { throw new RuntimeException("Null atom ID"); } CMLAtom oldAtom = atomArray.getAtomById(id); if (oldAtom == null) { atomArray.addAtom(atom); } } else { throw new RuntimeException("Cannot add null atom"); } }
/** * gets atom by id. * * @param id * @return the atom or null */ public CMLAtom getAtomById(String id) { CMLAtom atom = null; if (id != null) { CMLAtomArray atomArray = getAtomArray(); // use atomArray first in case there are child molecules if (atomArray != null) { // crude check for update index if (atomArray.atomMap.size() != atomArray.getAtomElements().size()) { atomArray.indexAtoms(); } atom = atomArray.getAtomById(id); } else if (getMoleculeCount() > 0) { getChildMoleculeAtomMap(); List<CMLAtom> atomList = childMoleculeAtomMap.get(id); if (atomList != null && atomList.size() == 1) { atom = atomList.get(0); } } } return atom; }