private boolean addPriorities(List<String> priorities, Set<String> childPriorities, String after) {
    if (after == null) {
      priorities.addAll(childPriorities);
      return true;
    }
    else {
      // Check the current priorities, if the "after" priority is there then add these
      for (int index = priorities.size() - 1; index >= 0; index--) {
        String priority = priorities.get(index);
        if (after.equals(priority)) {
          priorities.addAll(index + 1, childPriorities);
          return true;
        }
      }
    }
    return false;
  }
Add the given child priorities if the service they are supposed to come after have been added.
ambari-server/src/main/java/org/apache/ambari/server/stack/upgrade/ServiceCheckGrouping.java