/** * Get the isotope instance given an IIsotope. The instance is those * that has the isotope with the same symbol, natural abundance and * exact mass. * * @param isotope The IIsotope for looking for * @return The IIsotope instance * @see #isotopes */ private IIsotope getIsotope(IIsotope isotope) { for (IIsotope thisIsotope : isotopes()) { if (isTheSame(isotope, thisIsotope)) return thisIsotope; } return null; }
/** * Get the isotope instance given an IIsotope. The instance is those * that has the isotope with the same symbol, natural abundance and * exact mass. * * @param isotope The IIsotope for looking for * @return The IIsotope instance * @see #isotopes */ private IIsotope getIsotope(IIsotope isotope) { for (IIsotope thisIsotope : isotopes()) { if (isTheSame(isotope, thisIsotope)) return thisIsotope; } return null; }
/** * True, if the MolecularFormula contains the given IIsotope object and not * the instance. The method looks for other isotopes which has the same * symbol, natural abundance and exact mass. * * @param isotope The IIsotope this MolecularFormula is searched for * @return True, if the MolecularFormula contains the given isotope object */ @Override public boolean contains(IIsotope isotope) { for (IIsotope thisIsotope : isotopes()) { if (isTheSame(thisIsotope, isotope)) { return true; } } return false; }
/** * True, if the MolecularFormula contains the given IIsotope object and not * the instance. The method looks for other isotopes which has the same * symbol, natural abundance and exact mass. * * @param isotope The IIsotope this MolecularFormula is searched for * @return True, if the MolecularFormula contains the given isotope object */ @Override public boolean contains(IIsotope isotope) { for (IIsotope thisIsotope : isotopes()) { if (isTheSame(thisIsotope, isotope)) { return true; } } return false; }
/** * Adds an Isotope to this MolecularFormula in a number of occurrences. * * @param isotope The isotope to be added to this MolecularFormula * @param count The number of occurrences to add * @see #addIsotope(IIsotope) */ @Override public IMolecularFormula addIsotope(IIsotope isotope, int count) { boolean flag = false; for (IIsotope thisIsotope : isotopes()) { if (isTheSame(thisIsotope, isotope)) { isotopes.put(thisIsotope, isotopes.get(thisIsotope) + count); flag = true; break; } } if (!flag) { isotopes.put(isotope, count); } return this; }
/** * Adds an Isotope to this MolecularFormula in a number of occurrences. * * @param isotope The isotope to be added to this MolecularFormula * @param count The number of occurrences to add * @see #addIsotope(IIsotope) */ @Override public IMolecularFormula addIsotope(IIsotope isotope, int count) { boolean flag = false; for (IIsotope thisIsotope : isotopes()) { if (isTheSame(thisIsotope, isotope)) { isotopes.put(thisIsotope, isotopes.get(thisIsotope) + count); flag = true; break; } } if (!flag) { isotopes.put(isotope, count); } return this; }
@Test public void testIsTheSame_IIsotope_IIsotope() throws IOException { MolecularFormula mf = new MolecularFormula(); IIsotope carb = getBuilder().newInstance(IIsotope.class, "C"); IIsotope anotherCarb = getBuilder().newInstance(IIsotope.class, "C"); IIsotope h = getBuilder().newInstance(IIsotope.class, "H"); carb.setExactMass(12.0); anotherCarb.setExactMass(12.0); h.setExactMass(1.0); carb.setNaturalAbundance(34.0); anotherCarb.setNaturalAbundance(34.0); h.setNaturalAbundance(99.0); Assert.assertTrue(mf.isTheSame(carb, carb)); Assert.assertTrue(mf.isTheSame(carb, anotherCarb)); Assert.assertFalse(mf.isTheSame(carb, h)); } }