Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Replacing CDKException in MolecularFormulaGenerator constructor with
IllegalArgumentException.

Signed-off-by: John May <john@nextmovesoftware.com>
  • Loading branch information
tomas-pluskal authored and johnmay committed Jan 8, 2015
1 parent f05e04d commit fa05c86
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
Expand Up @@ -28,7 +28,6 @@

import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.interfaces.IChemObjectBuilder;
import org.openscience.cdk.interfaces.IIsotope;
import org.openscience.cdk.interfaces.IMolecularFormula;
Expand Down Expand Up @@ -80,6 +79,7 @@ public class MolecularFormulaGenerator {

private static final ILoggingTool logger = LoggingToolFactory
.createLoggingTool(MolecularFormulaGenerator.class);

private final IChemObjectBuilder builder;

/**
Expand Down Expand Up @@ -122,31 +122,32 @@ public class MolecularFormulaGenerator {
* Upper boundary of the target mass range
* @param mfRange
* A range of elemental compositions defining the search space
* @throws CDKException
* @throws IllegalArgumentException
* In case some of the isotopes in mfRange has undefined exact
* mass or in case illegal parameters are provided (e.g.,
* negative mass values or empty MolecularFormulaRange)
* @see MolecularFormulaRange
*/
public MolecularFormulaGenerator(final IChemObjectBuilder builder,
final double minMass, final double maxMass,
final MolecularFormulaRange mfRange) throws CDKException {
final MolecularFormulaRange mfRange) {

logger.info("Initiate MolecularFormulaGenerator, mass range ", minMass,
"-", maxMass);

// Check parameter values
if ((minMass < 0.0) || (maxMass < 0.0)) {
throw (new CDKException(
throw (new IllegalArgumentException(
"The minimum and maximum mass values must be >=0"));
}

if ((minMass > maxMass)) {
throw (new CDKException("Minimum mass must be <= maximum mass"));
throw (new IllegalArgumentException(
"Minimum mass must be <= maximum mass"));
}

if ((mfRange == null) || (mfRange.getIsotopeCount() == 0)) {
throw (new CDKException(
throw (new IllegalArgumentException(
"The MolecularFormulaRange parameter must be non-null and must contain at least one isotope"));
}

Expand All @@ -162,8 +163,9 @@ public MolecularFormulaGenerator(final IChemObjectBuilder builder,
for (IIsotope isotope : mfRange.isotopes()) {
// Check if exact mass of each isotope is set
if (isotope.getExactMass() == null)
throw new CDKException("The exact mass value of isotope "
+ isotope + " is not set");
throw new IllegalArgumentException(
"The exact mass value of isotope " + isotope
+ " is not set");
isotopesSet.add(isotope);
}
isotopes = isotopesSet.toArray(new IIsotope[isotopesSet.size()]);
Expand Down
Expand Up @@ -23,7 +23,6 @@
import org.openscience.cdk.CDKTestCase;
import org.openscience.cdk.config.IsotopeFactory;
import org.openscience.cdk.config.Isotopes;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.interfaces.IChemObjectBuilder;
import org.openscience.cdk.interfaces.IIsotope;
import org.openscience.cdk.interfaces.IMolecularFormula;
Expand Down Expand Up @@ -196,7 +195,7 @@ public void run() {
* Test empty molecular formula range
*
*/
@Test(expected = CDKException.class)
@Test(expected = IllegalArgumentException.class)
public void testEmptyMFRange() throws Exception {
new MolecularFormulaGenerator(builder, 0, 100,
new MolecularFormulaRange());
Expand All @@ -205,7 +204,7 @@ public void testEmptyMFRange() throws Exception {
/**
* Test negative mass
*/
@Test(expected = CDKException.class)
@Test(expected = IllegalArgumentException.class)
public void testNegativeMass() throws Exception {

IsotopeFactory ifac = Isotopes.getInstance();
Expand Down

0 comments on commit fa05c86

Please sign in to comment.