class BondDiff {

    public static IDifference difference(IChemObject first, IChemObject second) {
        if (!(first instanceof IBond && second instanceof IBond)) {
            return null;
        }
        IBond firstB = (IBond) first;
        IBond secondB = (IBond) second;
        IDifferenceList totalDiff = new ChemObjectDifference("BondDiff");
        totalDiff.addChild(BondOrderDifference.construct("order", firstB.getOrder(), secondB.getOrder()));
        totalDiff.addChild(IntegerDifference.construct("atomCount", firstB.getAtomCount(), secondB.getAtomCount()));
        if (firstB.getAtomCount() == secondB.getAtomCount()) {
            totalDiff.addChild(AtomDiff.difference(firstB.getBegin(), secondB.getBegin()));
            totalDiff.addChild(AtomDiff.difference(firstB.getEnd(), secondB.getEnd()));
            for (int i = 2; i < firstB.getAtomCount(); i++) {
                totalDiff.addChild(AtomDiff.difference(firstB.getAtom(i), secondB.getAtom(i)));
            }
        }
        totalDiff.addChild(ElectronContainerDiff.difference(first, second));
        if (totalDiff.childCount() > 0) {
            return totalDiff;
        } else {
            return null;
        }
    }

    private  BondDiff();

}