BooleanFunction<T> (final Set<JavaFileObject.Kind> kinds) { // optimization for a single-element collection final Iterator<JavaFileObject.Kind> it = kinds.iterator(); if (it.hasNext()) { final JavaFileObject.Kind kind = it.next(); if (!it.hasNext()) { return myFilterMap.get(kind); } } // OR-filter, quite rare case return new BooleanFunction<T>() { @Override public boolean fun(T data) { for (JavaFileObject.Kind kind : kinds) { if (myFilterMap.get(kind).fun(data)) { return true; } } return false; } }; }