Use JVM signatures instead of FQ-names for additional built-ins

This commit is contained in:
Denis Zharkov
2016-04-20 19:31:24 +03:00
parent 8cf29ea4f3
commit 1efed64014
6 changed files with 261 additions and 64 deletions
@@ -16,6 +16,7 @@
package org.jetbrains.kotlin.utils;
import kotlin.jvm.functions.Function1;
import org.jetbrains.annotations.NotNull;
import java.util.*;
@@ -36,6 +37,30 @@ public class DFS {
return dfs(nodes, neighbors, new VisitedWithSet<N>(), handler);
}
public static <N> Boolean ifAny(
@NotNull Collection<N> nodes,
@NotNull Neighbors<N> neighbors,
@NotNull final Function1<N, Boolean> predicate
) {
final boolean[] result = new boolean[1];
return dfs(nodes, neighbors, new AbstractNodeHandler<N, Boolean>() {
@Override
public boolean beforeChildren(N current) {
if (predicate.invoke(current)) {
result[0] = true;
}
return !result[0];
}
@Override
public Boolean result() {
return result[0];
}
});
}
public static <N, R> R dfsFromNode(@NotNull N node, @NotNull Neighbors<N> neighbors, @NotNull Visited<N> visited, @NotNull NodeHandler<N, R> handler) {
doDfs(node, neighbors, visited, handler);
return handler.result();