Skip to content

Commit

Permalink
spotless + null collector fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nbauernfeind committed Feb 9, 2024
1 parent 7f03162 commit 5f5c70d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
Expand Down Expand Up @@ -303,10 +304,14 @@ protected synchronized Object setVariable(String name, @Nullable Object newValue

@Override
protected Map<String, Object> getAllValues(Predicate<Map.Entry<String, Object>> predicate) {
return PyLib
.ensureGil(() -> scope.getEntries()
.filter(predicate)
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
final HashMap<String, Object> result = new HashMap<>();
// note: we can't use collect(Collectors.toMap()) because we allow null values
return PyLib.ensureGil(() -> {
scope.getEntries()
.filter(predicate)
.forEach(entry -> result.put(entry.getKey(), entry.getValue()));
return result;
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -772,9 +772,12 @@ protected Object setVariable(String name, @Nullable Object newValue) {
@Override
protected Map<String, Object> getAllValues(@NotNull final Predicate<Map.Entry<String, Object>> predicate) {
synchronized (bindingBackingMap) {
return bindingBackingMap.entrySet().stream()
final HashMap<String, Object> result = new HashMap<>();
// note: we can't use collect(Collectors.toMap()) because we allow null values
bindingBackingMap.entrySet().stream()
.filter(predicate)
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
.forEach(e -> result.put(e.getKey(), e.getValue()));
return result;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,14 @@ protected Object setVariable(String name, @Nullable Object newValue) {

@Override
protected Map<String, Object> getAllValues(Predicate<Map.Entry<String, Object>> predicate) {
// note: we can't use collect(Collectors.toMap()) because we allow null values
final HashMap<String, Object> result = new HashMap<>();
synchronized (variables) {
return variables.entrySet().stream()
variables.entrySet().stream()
.filter(predicate)
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
.forEach(entry -> result.put(entry.getKey(), entry.getValue()));
}
return result;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
public class PythonScopeJpyImpl implements PythonScope<PyObject> {
private static volatile boolean cacheEnabled =
Configuration.getInstance().getBooleanForClassWithDefault(PythonScopeJpyImpl.class, "cacheEnabled", false);

public static void setCacheEnabled(boolean enabled) {
cacheEnabled = enabled;
}
Expand Down

0 comments on commit 5f5c70d

Please sign in to comment.