private Set<Key<?>> removeOptionalKeys(
      DependencyExplorerOutput output, Map<Key<?>, String> invalidKeys) {
    RequiredKeySet requiredKeys = new RequiredKeySet(output.getGraph());
    Set<Key<?>> optionalKeys = new LinkedHashSet<Key<?>>();
    // We need to use a for loop instead of a foreach loop because we remove
    // entries as we go (see the call to iterator.remove() below).
    for (Iterator<Map.Entry<Key<?>, String>> iterator = invalidKeys.entrySet().iterator();
        iterator.hasNext();) {
      Map.Entry<Key<?>, String> entry = iterator.next();
      Key<?> key = entry.getKey();
      if (!requiredKeys.isRequired(key)) {
        PrettyPrinter.log(logger, TreeLogger.DEBUG,
            "Removing the optional key %s because it had errors: %s", key, entry.getValue());
        optionalKeys.add(key);
        iterator.remove();
      }
    }
    return optionalKeys;
  }
private Set < Key < ? > > removeOptionalKeys ( DependencyExplorerOutput output , Map < Key < ? > , String > invalidKeys ) { RequiredKeySet requiredKeys = new RequiredKeySet ( output . getGraph ( ) ) ; Set < Key < ? > > optionalKeys = new LinkedHashSet < Key < ? > > ( ) ; for ( Iterator < Map . Entry < Key < ? > , String > > iterator = invalidKeys . entrySet ( ) . iterator ( ) ; iterator . hasNext ( ) ; ) { Map . Entry < Key < ? > , String > entry = iterator . next ( ) ; Key < ? > key = entry . getKey ( ) ; if ( ! requiredKeys . isRequired ( key ) ) { PrettyPrinter . log ( logger , TreeLogger . DEBUG , "Removing the optional key %s because it had errors: %s" , key , entry . getValue ( ) ) ; optionalKeys . add ( key ) ; iterator . remove ( ) ; } } return optionalKeys ; }
Remove optional keys from the {@code invalidKeys} map, and return the the set of optional keys
that had problems.