OxygenAtomCountDescriptor implements ISubstanceDescriptor { @Override public DescriptorValue calculate(ISubstance substance) { int count = 0; if (substance != null) { for (IAtomContainer container : substance.atomContainers()) { for (IAtom atom : container.atoms()) { if ("O".equals(atom.getSymbol()) || 8 == atom.getAtomicNumber()) count++; } } } return new DescriptorValue( getSpecification(), getParameterNames(), getParameters(), new IntegerResult(count), getDescriptorNames() ); }  @Override String[] getDescriptorNames(); @Override String[] getParameterNames(); @Override Object getParameterType(String substance); @Override Object[] getParameters(); @Override DescriptorSpecification getSpecification(); @Override void setParameters(Object[] parameters); @Override DescriptorValue calculate(ISubstance substance); @Override IDescriptorResult getDescriptorResultType(); @Override void initialise(IChemObjectBuilder builder);  }
@Test public void testCalculate_ZnO() throws Exception { ISubstance material = new Substance(); material.addAtomContainer( MolecularFormulaManipulator.getAtomContainer( "ZnO", DefaultChemObjectBuilder.getInstance() ) ); DescriptorValue value = descriptor.calculate(material); Assert.assertNotNull(value); IDescriptorResult result = value.getValue(); Assert.assertNotNull(result); Assert.assertEquals(1, ((IntegerResult)result).intValue()); }
@Test public void testCalculate_IronOxide() throws Exception { ISubstance material = new Substance(); material.addAtomContainer( MolecularFormulaManipulator.getAtomContainer( "Fe3O4", DefaultChemObjectBuilder.getInstance() ) ); DescriptorValue value = descriptor.calculate(material); Assert.assertNotNull(value); IDescriptorResult result = value.getValue(); Assert.assertNotNull(result); Assert.assertEquals(4, ((IntegerResult)result).intValue()); }