MassNumberRule implements ISequenceSubRule<ILigand> { private Integer getMassNumber(ILigand ligand) { Integer massNumber = ligand.getLigandAtom().getMassNumber(); if (massNumber != null) return massNumber; if (factory == null) return 0; return factory.getMajorIsotope(ligand.getLigandAtom().getSymbol()).getMassNumber(); }  @Override int compare(ILigand ligand1, ILigand ligand2);  }
@Test public void testOrder() { VisitedAtoms visitedAtoms = new VisitedAtoms(); ILigand ligand1 = new Ligand(molecule, visitedAtoms, molecule.getAtom(1), molecule.getAtom(4)); ILigand ligand2 = new Ligand(molecule, visitedAtoms, molecule.getAtom(1), molecule.getAtom(3)); ILigand ligand3 = new Ligand(molecule, visitedAtoms, molecule.getAtom(1), molecule.getAtom(2)); ILigand ligand4 = new Ligand(molecule, visitedAtoms, molecule.getAtom(1), molecule.getAtom(0)); List<ILigand> ligands = new ArrayList<ILigand>(); ligands.add(ligand1); ligands.add(ligand2); ligands.add(ligand3); ligands.add(ligand4); Collections.sort(ligands, new MassNumberRule()); Assert.assertNotNull(ligands.get(0)); Assert.assertEquals("H", ligands.get(0).getLigandAtom().getSymbol()); Assert.assertEquals("H", ligands.get(1).getLigandAtom().getSymbol()); Assert.assertEquals(2, ligands.get(1).getLigandAtom().getMassNumber().intValue()); Assert.assertEquals("C", ligands.get(2).getLigandAtom().getSymbol()); Assert.assertEquals("C", ligands.get(3).getLigandAtom().getSymbol()); Assert.assertEquals(13, ligands.get(3).getLigandAtom().getMassNumber().intValue()); }