From 51789efd9009ba22bba47cdc39ec9675431e7225 Mon Sep 17 00:00:00 2001 From: TopchetoEU <36534413+TopchetoEU@users.noreply.github.com> Date: Sat, 26 Aug 2023 11:53:09 +0300 Subject: [PATCH] remove toList --- .../jscript/filesystem/PhysicalFilesystem.java | 3 ++- src/me/topchetoeu/jscript/json/JSON.java | 3 ++- src/me/topchetoeu/jscript/polyfills/Map.java | 9 +++++---- src/me/topchetoeu/jscript/polyfills/Set.java | 9 +++++---- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/me/topchetoeu/jscript/filesystem/PhysicalFilesystem.java b/src/me/topchetoeu/jscript/filesystem/PhysicalFilesystem.java index b985938..043b7b7 100644 --- a/src/me/topchetoeu/jscript/filesystem/PhysicalFilesystem.java +++ b/src/me/topchetoeu/jscript/filesystem/PhysicalFilesystem.java @@ -3,6 +3,7 @@ package me.topchetoeu.jscript.filesystem; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.util.stream.Collectors; public class PhysicalFilesystem implements Filesystem { public final Path root; @@ -34,7 +35,7 @@ public class PhysicalFilesystem implements Filesystem { path = joinPaths(root, path); if (path.toFile().isDirectory()) { - return new MemoryFile(String.join("\n", Files.list(path).map(Path::toString).toList()).getBytes()); + return new MemoryFile(String.join("\n", Files.list(path).map(Path::toString).collect(Collectors.toList())).getBytes()); } else if (path.toFile().isFile()) { return new PhysicalFile(path, perms); diff --git a/src/me/topchetoeu/jscript/json/JSON.java b/src/me/topchetoeu/jscript/json/JSON.java index 0df53d5..0869990 100644 --- a/src/me/topchetoeu/jscript/json/JSON.java +++ b/src/me/topchetoeu/jscript/json/JSON.java @@ -1,6 +1,7 @@ package me.topchetoeu.jscript.json; import java.util.List; +import java.util.stream.Collectors; import me.topchetoeu.jscript.exceptions.SyntaxException; import me.topchetoeu.jscript.parsing.Operator; @@ -131,7 +132,7 @@ public class JSON { } if (el.isMap()) { var res = new StringBuilder().append("{"); - var entries = el.map().entrySet().stream().toList(); + var entries = el.map().entrySet().stream().collect(Collectors.toList()); for (int i = 0; i < entries.size(); i++) { if (i != 0) res.append(","); diff --git a/src/me/topchetoeu/jscript/polyfills/Map.java b/src/me/topchetoeu/jscript/polyfills/Map.java index 9d92e1d..e7b22d5 100644 --- a/src/me/topchetoeu/jscript/polyfills/Map.java +++ b/src/me/topchetoeu/jscript/polyfills/Map.java @@ -1,6 +1,7 @@ package me.topchetoeu.jscript.polyfills; import java.util.LinkedHashMap; +import java.util.stream.Collectors; import me.topchetoeu.jscript.engine.CallContext; import me.topchetoeu.jscript.engine.values.ArrayValue; @@ -42,7 +43,7 @@ public class Map { @Native public void forEach(CallContext ctx, FunctionValue func, Object thisArg) throws InterruptedException { - for (var el : objs.entrySet().stream().toList()) { + for (var el : objs.entrySet().stream().collect(Collectors.toList())) { func.call(ctx, thisArg, el.getValue(), el.getKey(), this); } } @@ -53,16 +54,16 @@ public class Map { .entrySet() .stream() .map(v -> new ArrayValue(v.getKey(), v.getValue())) - .toList() + .collect(Collectors.toList()) ); } @Native public Object keys(CallContext ctx) throws InterruptedException { - return Values.fromJavaIterable(ctx, objs.keySet().stream().toList()); + return Values.fromJavaIterable(ctx, objs.keySet().stream().collect(Collectors.toList())); } @Native public Object values(CallContext ctx) throws InterruptedException { - return Values.fromJavaIterable(ctx, objs.values().stream().toList()); + return Values.fromJavaIterable(ctx, objs.values().stream().collect(Collectors.toList())); } @NativeGetter("size") diff --git a/src/me/topchetoeu/jscript/polyfills/Set.java b/src/me/topchetoeu/jscript/polyfills/Set.java index 51a4265..f432e5e 100644 --- a/src/me/topchetoeu/jscript/polyfills/Set.java +++ b/src/me/topchetoeu/jscript/polyfills/Set.java @@ -1,6 +1,7 @@ package me.topchetoeu.jscript.polyfills; import java.util.LinkedHashSet; +import java.util.stream.Collectors; import me.topchetoeu.jscript.engine.CallContext; import me.topchetoeu.jscript.engine.values.ArrayValue; @@ -37,14 +38,14 @@ public class Set { public void forEach(CallContext ctx, Object func, Object thisArg) throws InterruptedException { if (!(func instanceof FunctionValue)) throw EngineException.ofType("func must be a function."); - for (var el : objs.stream().toList()) { + for (var el : objs.stream().collect(Collectors.toList())) { ((FunctionValue)func).call(ctx, thisArg, el, el, this); } } @Native public ObjectValue entries() { - var it = objs.stream().toList().iterator(); + var it = objs.stream().collect(Collectors.toList()).iterator(); var next = new NativeFunction("next", (ctx, thisArg, args) -> { if (it.hasNext()) { @@ -61,7 +62,7 @@ public class Set { } @Native public ObjectValue keys() { - var it = objs.stream().toList().iterator(); + var it = objs.stream().collect(Collectors.toList()).iterator(); var next = new NativeFunction("next", (ctx, thisArg, args) -> { if (it.hasNext()) { @@ -78,7 +79,7 @@ public class Set { } @Native public ObjectValue values() { - var it = objs.stream().toList().iterator(); + var it = objs.stream().collect(Collectors.toList()).iterator(); var next = new NativeFunction("next", (ctx, thisArg, args) -> { if (it.hasNext()) {