public Set<String> filterHostsInMaintenanceState(Set<String> candidateHosts,
      HostPredicate condition) throws AmbariException {
    // Filter hosts that are in MS
    Set<String> removedHosts = new HashSet<>();
    for (String hostname : candidateHosts) {
      if (condition.shouldHostBeRemoved(hostname)) {
        removedHosts.add(hostname);
      }
    }
    candidateHosts.removeAll(removedHosts);
    return removedHosts;
  }
Removes from a set all hosts that match a given condition.

@param candidateHosts
         source set that should to be modified
@param condition
         condition
@return all hosts that have been removed from a candidateHosts
ambari-server/src/main/java/org/apache/ambari/server/controller/MaintenanceStateHelper.java