public static IAtom[] findTerminalAtoms(IAtomContainer container, IAtom focus) {
        List<IBond> focusBonds = container.getConnectedBondsList(focus);
        if (focusBonds.size() != 2)
            throw new IllegalArgumentException("focus must have exactly 2 neighbors");
        IAtom leftPrev  = focus;
        IAtom rightPrev = focus;
        IAtom left      = focusBonds.get(0).getOther(focus);
        IAtom right     = focusBonds.get(1).getOther(focus);
        IAtom tmp;
        while (left != null && right != null) {
            tmp = getOtherNbr(container, left, leftPrev);
            leftPrev = left;
            left     = tmp;
            tmp = getOtherNbr(container, right, rightPrev);
            rightPrev = right;
            right     = tmp;
        }
        return new IAtom[]{leftPrev, rightPrev};
    }
public static IAtom [ ] findTerminalAtoms ( IAtomContainer container , IAtom focus ) { List < IBond > focusBonds = container . getConnectedBondsList ( focus ) ; if ( focusBonds . size ( ) != 2 ) throw new IllegalArgumentException ( "focus must have exactly 2 neighbors" ) ; IAtom leftPrev = focus ; IAtom rightPrev = focus ; IAtom left = focusBonds . get ( 0 ) . getOther ( focus ) ; IAtom right = focusBonds . get ( 1 ) . getOther ( focus ) ; IAtom tmp ; while ( left != null && right != null ) { tmp = getOtherNbr ( container , left , leftPrev ) ; leftPrev = left ; left = tmp ; tmp = getOtherNbr ( container , right , rightPrev ) ; rightPrev = right ; right = tmp ; } return new IAtom [ ] { leftPrev , rightPrev } ; }
Helper method to locate two terminal atoms in a container for a given
focus.

@param container structure representation
@param focus cumulated atom
@return the terminal atoms (unordered)