MassToFormulaTool { public void setRestrictions(List<IRule> rulesNew) throws CDKException { Iterator<IRule> itRules = rulesNew.iterator(); while (itRules.hasNext()) { IRule rule = itRules.next(); if (rule instanceof ElementRule) { mfRange = (MolecularFormulaRange) ((Object[]) rule.getParameters())[0]; Iterator<IRule> oldRuleIt = rules.iterator(); while (oldRuleIt.hasNext()) { IRule oldRule = oldRuleIt.next(); if (oldRule instanceof ElementRule) { rules.remove(oldRule); rules.add(rule); break; } } this.matrix_Base = getMatrix(mfRange.getIsotopeCount()); } else if (rule instanceof ChargeRule) { this.charge = (Double) ((Object[]) rule.getParameters())[0]; Iterator<IRule> oldRuleIt = rules.iterator(); while (oldRuleIt.hasNext()) { IRule oldRule = oldRuleIt.next(); if (oldRule instanceof ChargeRule) { rules.remove(oldRule); rules.add(rule); break; } } } else if (rule instanceof ToleranceRangeRule) { this.tolerance = (Double) ((Object[]) rule.getParameters())[1]; Iterator<IRule> oldRuleIt = rules.iterator(); while (oldRuleIt.hasNext()) { IRule oldRule = oldRuleIt.next(); if (oldRule instanceof ToleranceRangeRule) { rules.remove(oldRule); rules.add(rule); break; } } } else { rules.add(rule); } } } MassToFormulaTool(IChemObjectBuilder builder); void setRestrictions(List<IRule> rulesNew); List<IRule> getRestrictions(); void setDefaultRestrictions(); IMolecularFormulaSet generate(double mass);  }
@Test public void testHighMass() throws Exception { MassToFormulaTool mfTool = new MassToFormulaTool(builder); List<IRule> myRules = new ArrayList<IRule>(); IRule rule1 = new ElementRule(); Object[] params = new Object[1]; MolecularFormulaRange mfRange = new MolecularFormulaRange(); mfRange.addIsotope(ifac.getMajorIsotope("C"), 0, 200); mfRange.addIsotope(ifac.getMajorIsotope("H"), 0, 200); mfRange.addIsotope(ifac.getMajorIsotope("O"), 0, 200); mfRange.addIsotope(ifac.getMajorIsotope("N"), 0, 50); mfRange.addIsotope(ifac.getMajorIsotope("S"), 0, 50); params[0] = mfRange; rule1.setParameters(params); myRules.add(rule1); mfTool.setRestrictions(myRules); }