remove toList

This commit is contained in:
TopchetoEU 2023-08-26 11:53:09 +03:00
parent 480293734b
commit 51789efd90
No known key found for this signature in database
GPG Key ID: 24E57B2E9C61AD19
4 changed files with 14 additions and 10 deletions

View File

@ -3,6 +3,7 @@ package me.topchetoeu.jscript.filesystem;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.stream.Collectors;
public class PhysicalFilesystem implements Filesystem { public class PhysicalFilesystem implements Filesystem {
public final Path root; public final Path root;
@ -34,7 +35,7 @@ public class PhysicalFilesystem implements Filesystem {
path = joinPaths(root, path); path = joinPaths(root, path);
if (path.toFile().isDirectory()) { 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()) { else if (path.toFile().isFile()) {
return new PhysicalFile(path, perms); return new PhysicalFile(path, perms);

View File

@ -1,6 +1,7 @@
package me.topchetoeu.jscript.json; package me.topchetoeu.jscript.json;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import me.topchetoeu.jscript.exceptions.SyntaxException; import me.topchetoeu.jscript.exceptions.SyntaxException;
import me.topchetoeu.jscript.parsing.Operator; import me.topchetoeu.jscript.parsing.Operator;
@ -131,7 +132,7 @@ public class JSON {
} }
if (el.isMap()) { if (el.isMap()) {
var res = new StringBuilder().append("{"); 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++) { for (int i = 0; i < entries.size(); i++) {
if (i != 0) res.append(","); if (i != 0) res.append(",");

View File

@ -1,6 +1,7 @@
package me.topchetoeu.jscript.polyfills; package me.topchetoeu.jscript.polyfills;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.stream.Collectors;
import me.topchetoeu.jscript.engine.CallContext; import me.topchetoeu.jscript.engine.CallContext;
import me.topchetoeu.jscript.engine.values.ArrayValue; import me.topchetoeu.jscript.engine.values.ArrayValue;
@ -42,7 +43,7 @@ public class Map {
@Native @Native
public void forEach(CallContext ctx, FunctionValue func, Object thisArg) throws InterruptedException { 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); func.call(ctx, thisArg, el.getValue(), el.getKey(), this);
} }
} }
@ -53,16 +54,16 @@ public class Map {
.entrySet() .entrySet()
.stream() .stream()
.map(v -> new ArrayValue(v.getKey(), v.getValue())) .map(v -> new ArrayValue(v.getKey(), v.getValue()))
.toList() .collect(Collectors.toList())
); );
} }
@Native @Native
public Object keys(CallContext ctx) throws InterruptedException { 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 @Native
public Object values(CallContext ctx) throws InterruptedException { 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") @NativeGetter("size")

View File

@ -1,6 +1,7 @@
package me.topchetoeu.jscript.polyfills; package me.topchetoeu.jscript.polyfills;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.stream.Collectors;
import me.topchetoeu.jscript.engine.CallContext; import me.topchetoeu.jscript.engine.CallContext;
import me.topchetoeu.jscript.engine.values.ArrayValue; 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 { public void forEach(CallContext ctx, Object func, Object thisArg) throws InterruptedException {
if (!(func instanceof FunctionValue)) throw EngineException.ofType("func must be a function."); 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); ((FunctionValue)func).call(ctx, thisArg, el, el, this);
} }
} }
@Native @Native
public ObjectValue entries() { 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) -> { var next = new NativeFunction("next", (ctx, thisArg, args) -> {
if (it.hasNext()) { if (it.hasNext()) {
@ -61,7 +62,7 @@ public class Set {
} }
@Native @Native
public ObjectValue keys() { 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) -> { var next = new NativeFunction("next", (ctx, thisArg, args) -> {
if (it.hasNext()) { if (it.hasNext()) {
@ -78,7 +79,7 @@ public class Set {
} }
@Native @Native
public ObjectValue values() { 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) -> { var next = new NativeFunction("next", (ctx, thisArg, args) -> {
if (it.hasNext()) { if (it.hasNext()) {