MolecularFormulaSetManipulator { public static IMolecularFormulaSet remove(IMolecularFormulaSet formulaSet, IMolecularFormula formulaMin, IMolecularFormula formulaMax) { if (!validCorrelation(formulaMin, formulaMax)) return null; IMolecularFormulaSet newFormulaSet = formulaSet.getBuilder().newInstance(IMolecularFormulaSet.class); for (IMolecularFormula formula : formulaSet.molecularFormulas()) { boolean flagPass = true; if (!validCorrelation(formula, formulaMin)) continue; for (IElement element : MolecularFormulaManipulator.elements(formulaMin)) { int occur = MolecularFormulaManipulator.getElementCount(formula, element); int occurMax = MolecularFormulaManipulator.getElementCount(formulaMax, element); int occurMin = MolecularFormulaManipulator.getElementCount(formulaMin, element); if (!(occurMin <= occur) || !(occur <= occurMax)) { flagPass = false; break; } } if (flagPass) newFormulaSet.addMolecularFormula(formula); } return newFormulaSet; }  static IMolecularFormula getMaxOccurrenceElements(IMolecularFormulaSet mfSet); static IMolecularFormula getMinOccurrenceElements(IMolecularFormulaSet mfSet); static IMolecularFormulaSet remove(IMolecularFormulaSet formulaSet, IMolecularFormula formulaMin,
            IMolecularFormula formulaMax); static boolean contains(IMolecularFormulaSet formulaSet, IMolecularFormula formula); static IMolecularFormulaSet remove(IMolecularFormulaSet formulaSet, MolecularFormulaRange formulaRange);  }
@Test public void testRemove_IMolecularFormulaSet_IMolecularFormula_IMolecularFormula() { IMolecularFormula formulaMin = new MolecularFormula(); formulaMin.addIsotope(builder.newInstance(IIsotope.class, "C"), 1); formulaMin.addIsotope(builder.newInstance(IIsotope.class, "H"), 1); formulaMin.addIsotope(builder.newInstance(IIsotope.class, "O"), 1); IMolecularFormula formulaMax = new MolecularFormula(); formulaMax.addIsotope(builder.newInstance(IIsotope.class, "C"), 4); formulaMax.addIsotope(builder.newInstance(IIsotope.class, "H"), 12); formulaMax.addIsotope(builder.newInstance(IIsotope.class, "N"), 2); IMolecularFormula mf1 = new MolecularFormula(); mf1.addIsotope(builder.newInstance(IIsotope.class, "C"), 3); mf1.addIsotope(builder.newInstance(IIsotope.class, "H"), 10); mf1.addIsotope(builder.newInstance(IIsotope.class, "N"), 1); IMolecularFormulaSet formulaSet = new MolecularFormulaSet(); formulaSet.addMolecularFormula(mf1); IMolecularFormulaSet newMFSet = MolecularFormulaSetManipulator.remove(formulaSet, formulaMin, formulaMax); Assert.assertNull(newMFSet); }
@Test public void testRemove_1() { IMolecularFormula formulaMin = new MolecularFormula(); formulaMin.addIsotope(builder.newInstance(IIsotope.class, "C"), 1); formulaMin.addIsotope(builder.newInstance(IIsotope.class, "H"), 1); formulaMin.addIsotope(builder.newInstance(IIsotope.class, "N"), 1); IMolecularFormula formulaMax = new MolecularFormula(); formulaMax.addIsotope(builder.newInstance(IIsotope.class, "C"), 4); formulaMax.addIsotope(builder.newInstance(IIsotope.class, "H"), 12); formulaMax.addIsotope(builder.newInstance(IIsotope.class, "N"), 2); IMolecularFormula mf1 = new MolecularFormula(); mf1.addIsotope(builder.newInstance(IIsotope.class, "C"), 3); mf1.addIsotope(builder.newInstance(IIsotope.class, "H"), 10); mf1.addIsotope(builder.newInstance(IIsotope.class, "N"), 1); IMolecularFormula mf2 = new MolecularFormula(); mf2.addIsotope(builder.newInstance(IIsotope.class, "C"), 1); mf2.addIsotope(builder.newInstance(IIsotope.class, "H"), 1); mf2.addIsotope(builder.newInstance(IIsotope.class, "N"), 1); IMolecularFormula mf3 = new MolecularFormula(); mf3.addIsotope(builder.newInstance(IIsotope.class, "C"), 4); mf3.addIsotope(builder.newInstance(IIsotope.class, "H"), 12); mf3.addIsotope(builder.newInstance(IIsotope.class, "N"), 2); IMolecularFormula mf4 = new MolecularFormula(); mf4.addIsotope(builder.newInstance(IIsotope.class, "C"), 7); mf4.addIsotope(builder.newInstance(IIsotope.class, "H"), 10); mf4.addIsotope(builder.newInstance(IIsotope.class, "N"), 1); IMolecularFormulaSet formulaSet = new MolecularFormulaSet(); formulaSet.addMolecularFormula(mf1); formulaSet.addMolecularFormula(mf2); formulaSet.addMolecularFormula(mf3); formulaSet.addMolecularFormula(mf4); IMolecularFormulaSet newMFSet = MolecularFormulaSetManipulator.remove(formulaSet, formulaMin, formulaMax); Assert.assertEquals(3, newMFSet.size()); Assert.assertEquals(MolecularFormulaManipulator.getString(mf1), MolecularFormulaManipulator.getString(newMFSet.getMolecularFormula(0))); Assert.assertEquals(MolecularFormulaManipulator.getString(mf2), MolecularFormulaManipulator.getString(newMFSet.getMolecularFormula(1))); Assert.assertEquals(MolecularFormulaManipulator.getString(mf3), MolecularFormulaManipulator.getString(newMFSet.getMolecularFormula(2))); }
@Test public void testRemove_2() { IMolecularFormula formulaMin = new MolecularFormula(); formulaMin.addIsotope(builder.newInstance(IIsotope.class, "C"), 1); formulaMin.addIsotope(builder.newInstance(IIsotope.class, "H"), 1); formulaMin.addIsotope(builder.newInstance(IIsotope.class, "N"), 1); IMolecularFormula formulaMax = new MolecularFormula(); formulaMax.addIsotope(builder.newInstance(IIsotope.class, "C"), 4); formulaMax.addIsotope(builder.newInstance(IIsotope.class, "H"), 12); formulaMax.addIsotope(builder.newInstance(IIsotope.class, "N"), 2); IMolecularFormula mf1 = new MolecularFormula(); mf1.addIsotope(builder.newInstance(IIsotope.class, "C"), 3); mf1.addIsotope(builder.newInstance(IIsotope.class, "H"), 10); mf1.addIsotope(builder.newInstance(IIsotope.class, "N"), 1); IMolecularFormula mf2 = new MolecularFormula(); mf2.addIsotope(builder.newInstance(IIsotope.class, "C"), 1); mf2.addIsotope(builder.newInstance(IIsotope.class, "H"), 1); IMolecularFormulaSet formulaSet = new MolecularFormulaSet(); formulaSet.addMolecularFormula(mf1); formulaSet.addMolecularFormula(mf2); IMolecularFormulaSet newMFSet = MolecularFormulaSetManipulator.remove(formulaSet, formulaMin, formulaMax); Assert.assertEquals(1, newMFSet.size()); Assert.assertEquals(MolecularFormulaManipulator.getString(mf1), MolecularFormulaManipulator.getString(newMFSet.getMolecularFormula(0))); }
@Test public void testRemove_3() { IMolecularFormula formulaMin = new MolecularFormula(); formulaMin.addIsotope(builder.newInstance(IIsotope.class, "C"), 1); formulaMin.addIsotope(builder.newInstance(IIsotope.class, "H"), 1); formulaMin.addIsotope(builder.newInstance(IIsotope.class, "N"), 1); IMolecularFormula formulaMax = new MolecularFormula(); formulaMax.addIsotope(builder.newInstance(IIsotope.class, "C"), 4); formulaMax.addIsotope(builder.newInstance(IIsotope.class, "H"), 12); formulaMax.addIsotope(builder.newInstance(IIsotope.class, "N"), 2); IMolecularFormula mf1 = new MolecularFormula(); mf1.addIsotope(builder.newInstance(IIsotope.class, "C"), 3); mf1.addIsotope(builder.newInstance(IIsotope.class, "H"), 10); mf1.addIsotope(builder.newInstance(IIsotope.class, "N"), 1); IMolecularFormula mf2 = new MolecularFormula(); mf2.addIsotope(builder.newInstance(IIsotope.class, "C"), 1); mf2.addIsotope(builder.newInstance(IIsotope.class, "H"), 1); mf2.addIsotope(builder.newInstance(IIsotope.class, "O"), 1); IMolecularFormulaSet formulaSet = new MolecularFormulaSet(); formulaSet.addMolecularFormula(mf1); formulaSet.addMolecularFormula(mf2); IMolecularFormulaSet newMFSet = MolecularFormulaSetManipulator.remove(formulaSet, formulaMin, formulaMax); Assert.assertEquals(1, newMFSet.size()); Assert.assertEquals(MolecularFormulaManipulator.getString(mf1), MolecularFormulaManipulator.getString(newMFSet.getMolecularFormula(0))); }
@Test public void testRemove_IMolecularFormulaSet_MolecularFormulaRange() { MolecularFormulaRange formulaRange = new MolecularFormulaRange(); formulaRange.addIsotope(builder.newInstance(IIsotope.class, "C"), 0, 4); formulaRange.addIsotope(builder.newInstance(IIsotope.class, "H"), 0, 12); formulaRange.addIsotope(builder.newInstance(IIsotope.class, "N"), 0, 2); IMolecularFormula mf2 = new MolecularFormula(); mf2.addIsotope(builder.newInstance(IIsotope.class, "C"), 1); mf2.addIsotope(builder.newInstance(IIsotope.class, "H"), 11); mf2.addIsotope(builder.newInstance(IIsotope.class, "N"), 1); IMolecularFormula mf1 = new MolecularFormula(); mf1.addIsotope(builder.newInstance(IIsotope.class, "C"), 3); mf1.addIsotope(builder.newInstance(IIsotope.class, "H"), 10); IMolecularFormulaSet formulaSet = new MolecularFormulaSet(); formulaSet.addMolecularFormula(mf1); formulaSet.addMolecularFormula(mf2); IMolecularFormulaSet newMFSet = MolecularFormulaSetManipulator.remove(formulaSet, formulaRange); Assert.assertEquals(2, newMFSet.size()); }