code: private static void distributeShareSorted(
        double total, final Collection<? extends Schedulable> schedulables,
        ScheduleComparator comparator) {
      List<Schedulable> sches = new ArrayList<Schedulable>(schedulables);
      Collections.sort(sches, comparator);
      for (Schedulable schedulable : sches) {
        int max = Math.min(schedulable.getRequested(), schedulable.getMaximum());
        if (total > max) {
          schedulable.share = max;
          total -= max;
        } else {
          schedulable.share = total;
          return;
        }
      }
    }
docs: Distribute the share among Schedulables in a greedy manner when
  they are sorted based on some comparator and the first Schedulable
  has to be fully satisfied before the next one can get any resources
  
  @param total the total amount of share to be distributed
  @param schedulables a collection of schedulables to get the share
  @param comparator a comparator to use when sorting schedulables