code: private IMolecularFormulaSet returnOrdered(double mass, IMolecularFormulaSet formulaSet) {
          IMolecularFormulaSet solutions_new = null;
  
          if (formulaSet.size() != 0) {
  
              double valueMin = 100;
              int i_final = 0;
              solutions_new = formulaSet.getBuilder().newInstance(IMolecularFormulaSet.class);
              List<Integer> listI = new ArrayList<Integer>();
              for (int j = 0; j < formulaSet.size(); j++) {
                  for (int i = 0; i < formulaSet.size(); i++) {
                      if (listI.contains(i)) continue;
  
                      double value = MolecularFormulaManipulator.getTotalExactMass(formulaSet.getMolecularFormula(i));
                      double diff = Math.abs(mass - Math.abs(value));
                      if (valueMin > diff) {
                          valueMin = diff;
                          i_final = i;
                      }
  
                  }
                  valueMin = 100;
                  solutions_new.addMolecularFormula(formulaSet.getMolecularFormula(i_final));
                  listI.add(i_final);
              }
          }
  
          return solutions_new;
      }
docs: Return all molecular formulas but ordered according the tolerance difference between masses.
  
  @param  mass        The mass to analyze
  @param  formulaSet  The IMolecularFormulaSet to order
  @return             The IMolecularFormulaSet ordered