Component (Container aContainer, Component aComponent, Function<? super Pair<Container, Component>, ? extends Component> func) { Set<Component> loopGuard = new HashSet<>(); do { if (!loopGuard.add(aComponent)) return null; aComponent = func.fun(Pair.create(aContainer, aComponent)); } while (aComponent != null && myExcludes.contains(aComponent)); return aComponent; }