code: public synchronized void sortResultsByFragments() {
  
          //        System.out.println("\nSort By Fragment");
          Map<Integer, Map<Integer, Integer>> allFragmentMCS = new TreeMap<Integer, Map<Integer, Integer>>();
          Map<Integer, Map<IAtom, IAtom>> allFragmentAtomMCS = new TreeMap<Integer, Map<IAtom, IAtom>>();
  
          Map<Integer, Double> stereoScoreMap = new TreeMap<Integer, Double>();
          Map<Integer, Double> energyScoreMap = new TreeMap<Integer, Double>();
          Map<Integer, Integer> fragmentScoreMap = new TreeMap<Integer, Integer>();
  
          initializeMaps(allFragmentMCS, allFragmentAtomMCS, stereoScoreMap, fragmentScoreMap, energyScoreMap);
  
          int minFragmentScore = 9999;
          for (Integer key : allFragmentAtomMCS.keySet()) {
              Map<IAtom, IAtom> mcsAtom = allFragmentAtomMCS.get(key);
              int fragmentCount = getMappedMoleculeFragmentSize(mcsAtom);
              fragmentScoreMap.put(key, fragmentCount);
              if (minFragmentScore > fragmentCount) {
                  minFragmentScore = fragmentCount;
              }
          }
          boolean flag = false;
          if (minFragmentScore < 9999) {
              flag = true;
              clear();
          }
          int counter = 0;
          for (Map.Entry<Integer, Integer> map : fragmentScoreMap.entrySet()) {
              if (minFragmentScore == map.getValue().intValue()) {
                  addSolution(counter, map.getKey(), allFragmentAtomMCS, allFragmentMCS, stereoScoreMap, energyScoreMap,
                          fragmentScoreMap);
                  counter++;
                  //                System.out.println("Fragment key " + map.getKey() + " Size: " + fragmentScoreMap.get(map.getKey()));
                  //                System.out.println("Fragment MCS " + allFragmentMCS.get(map.getKey()) + " Stereo Value: "
                  //                        + stereoScoreMap.get(map.getKey()));
              }
          }
  
          if (flag) {
              firstSolution.putAll(allMCS.get(0));
              firstAtomMCS.putAll(allAtomMCS.get(0));
              clear(allFragmentMCS, allFragmentAtomMCS, stereoScoreMap, fragmentScoreMap, energyScoreMap);
          }
  
      }
docs: Sort solution by ascending order of the fragment count.