class AromaticityCalculator {

    public static boolean isAromatic(IRing ring, IAtomContainer atomContainer) {

        java.util.Iterator<IAtom> ringAtoms = ring.atoms().iterator();
        int eCount = 0;
        java.util.List<IBond> conectedBonds;
        int numDoubleBond = 0;
        boolean allConnectedBondsSingle;

        while (ringAtoms.hasNext()) {
            IAtom atom = ringAtoms.next();
            numDoubleBond = 0;
            allConnectedBondsSingle = true;
            conectedBonds = atomContainer.getConnectedBondsList(atom);
            for (IBond conectedBond : conectedBonds) {
                if (conectedBond.getOrder() == IBond.Order.DOUBLE && ring.contains(conectedBond)) {
                    numDoubleBond++;
                }

                // Count the Electron if bond order = 1.5
                else if (conectedBond.getFlag(CDKConstants.ISAROMATIC) && ring.contains(conectedBond)) {
                    numDoubleBond = 1;
                }

                if (conectedBond.getOrder() != IBond.Order.SINGLE) {
                    allConnectedBondsSingle = false;
                }
            }
            if (numDoubleBond == 1) {
                //C or heteroatoms both contibute 1 electron in sp2 hybridized form
                eCount++;
            } else if (!atom.getSymbol().equals("C")) {
                //Heteroatom probably in sp3 hybrid therefore 2 electrons contributed.
                eCount = eCount + 2;
            } else if (atom.getFlag(CDKConstants.ISAROMATIC)) {
                eCount++;
            } else if (allConnectedBondsSingle && atom.getSymbol().equals("C") && atom.getFormalCharge() == 1.0) {
                // This is for tropylium and kinds.
                // Dependence on hybridisation would be better:
                // empty p-orbital is needed
                continue;
            } else {
                return false;
            }
        }
        return eCount - 2 != 0 && (eCount - 2) % 4 == 0;
    }

}