Skip to content

Commit

Permalink
Illegal stream usage fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
cstancu committed Feb 10, 2017
1 parent 5b8cebe commit 0a5fd96
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import java.util.Collections;
import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import org.graalvm.compiler.debug.CSVUtil;
import org.graalvm.compiler.debug.GraalError;
Expand All @@ -44,6 +43,7 @@
import org.graalvm.compiler.debug.internal.method.MethodMetricsImpl;
import org.graalvm.compiler.debug.internal.method.MethodMetricsPrinter;
import org.graalvm.compiler.options.OptionValues;
import org.graalvm.util.CollectionsUtil;

/**
* Facility for printing the {@linkplain KeyRegistry#getDebugValues() values} collected across all
Expand Down Expand Up @@ -77,7 +77,7 @@ public void printDebugValues(OptionValues options) throws GraalError {
summary = "Complete";
}
if (DebugValueThreadFilter.getValue(options) != null && topLevelMaps.size() != 0) {
topLevelMaps = topLevelMaps.stream().filter(map -> Pattern.compile(DebugValueThreadFilter.getValue(options)).matcher(map.getName()).find()).collect(Collectors.toList());
topLevelMaps = CollectionsUtil.filterToList(topLevelMaps, map -> Pattern.compile(DebugValueThreadFilter.getValue(options)).matcher(map.getName()).find());
if (topLevelMaps.size() == 0) {
TTY.println("Warning: DebugValueThreadFilter=%s eliminated all maps so nothing will be printed", DebugValueThreadFilter.getValue(options));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ public static Collection<DebugMethodMetrics> collectedMetrics() {
Set<ResolvedJavaMethod> methods = new HashSet<>();

// gather all methods we found
threadMaps.stream().forEach(x -> {
threadMaps.forEach(x -> {
// snapshot the current compilations to only capture all methods compiled until now
HashMap<ResolvedJavaMethod, CompilationData> snapShot = new HashMap<>(x);
snapShot.keySet().forEach(y -> methods.add(y));
Expand Down
15 changes: 15 additions & 0 deletions graal/org.graalvm.util/src/org/graalvm/util/CollectionsUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.function.Function;
import java.util.function.IntFunction;
import java.util.function.Predicate;
import java.util.function.Supplier;

/**
* This class contains utility methods for commonly used functional patterns for collections.
Expand Down Expand Up @@ -61,6 +62,20 @@ public static <T> boolean anyMatch(Iterable<T> inputs, Predicate<T> predicate) {
return false;
}

public static <T> List<T> filterToList(List<T> inputs, Predicate<? super T> predicate) {
return filterToList(inputs, predicate, ArrayList::new);
}

public static <T> List<T> filterToList(List<T> inputs, Predicate<? super T> predicate, Supplier<List<T>> listGenerator) {
List<T> resultList = listGenerator.get();
for (T t : inputs) {
if (predicate.test(t)) {
resultList.add(t);
}
}
return resultList;
}

/**
* Filters the inputs, maps them given the mapping function and adds them in the array provided
* by the generator.
Expand Down

0 comments on commit 0a5fd96

Please sign in to comment.