mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-10-22 09:27:39 +00:00
Replace Collections methods with {List,Map,Set}.of
The two implementations aren't entirely compatible - the implementation returned by .of will throw an NPE on .contains(null), whereas the Collections implementations just return false. However, we try to avoid passing null to collections methods, so this should be safe. There's no strong reason to do this, but it helps make the code a little more consistent
This commit is contained in:
@@ -18,7 +18,6 @@ import io.netty.handler.codec.http.HttpHeaderNames;
|
||||
import io.netty.handler.codec.http.HttpHeaders;
|
||||
import io.netty.handler.codec.http.HttpMethod;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
@@ -83,7 +82,7 @@ public class HTTPAPI implements ILuaAPI {
|
||||
var options = args.getTable(0);
|
||||
address = getStringField(options, "url");
|
||||
postString = optStringField(options, "body", null);
|
||||
headerTable = optTableField(options, "headers", Collections.emptyMap());
|
||||
headerTable = optTableField(options, "headers", Map.of());
|
||||
binary = optBooleanField(options, "binary", false);
|
||||
requestMethod = optStringField(options, "method", null);
|
||||
redirect = optBooleanField(options, "redirect", true);
|
||||
@@ -92,7 +91,7 @@ public class HTTPAPI implements ILuaAPI {
|
||||
// Get URL and post information
|
||||
address = args.getString(0);
|
||||
postString = args.optString(1, null);
|
||||
headerTable = args.optTable(2, Collections.emptyMap());
|
||||
headerTable = args.optTable(2, Map.of());
|
||||
binary = args.optBoolean(3, false);
|
||||
requestMethod = null;
|
||||
redirect = true;
|
||||
@@ -154,11 +153,11 @@ public class HTTPAPI implements ILuaAPI {
|
||||
if (args.get(0) instanceof Map) {
|
||||
var options = args.getTable(0);
|
||||
address = getStringField(options, "url");
|
||||
headerTable = optTableField(options, "headers", Collections.emptyMap());
|
||||
headerTable = optTableField(options, "headers", Map.of());
|
||||
timeoutArg = optRealField(options, "timeout");
|
||||
} else {
|
||||
address = args.getString(0);
|
||||
headerTable = args.optTable(1, Collections.emptyMap());
|
||||
headerTable = args.optTable(1, Map.of());
|
||||
timeoutArg = Optional.empty();
|
||||
}
|
||||
|
||||
|
@@ -12,7 +12,7 @@ import dan200.computercraft.core.apis.handles.EncodedReadableHandle;
|
||||
import dan200.computercraft.core.apis.handles.HandleGeneric;
|
||||
import dan200.computercraft.core.methods.ObjectSource;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -74,6 +74,6 @@ public class HttpResponseHandle implements ObjectSource {
|
||||
|
||||
@Override
|
||||
public Iterable<Object> getExtra() {
|
||||
return Collections.singletonList(reader);
|
||||
return List.of(reader);
|
||||
}
|
||||
}
|
||||
|
@@ -9,7 +9,7 @@ import dan200.computercraft.core.apis.handles.BinaryReadableHandle;
|
||||
import dan200.computercraft.core.methods.ObjectSource;
|
||||
|
||||
import java.nio.channels.SeekableByteChannel;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
@@ -42,6 +42,6 @@ public class TransferredFile implements ObjectSource {
|
||||
|
||||
@Override
|
||||
public Iterable<Object> getExtra() {
|
||||
return Collections.singleton(handle);
|
||||
return List.of(handle);
|
||||
}
|
||||
}
|
||||
|
@@ -12,7 +12,6 @@ import dan200.computercraft.core.apis.ComputerAccess;
|
||||
import dan200.computercraft.core.apis.IAPIEnvironment;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -43,7 +42,7 @@ public class ComputerSystem extends ComputerAccess implements IComputerSystem {
|
||||
@Override
|
||||
public Map<String, IPeripheral> getAvailablePeripherals() {
|
||||
// TODO: Should this return peripherals on the current computer?
|
||||
return Collections.emptyMap();
|
||||
return Map.of();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@@ -14,7 +14,6 @@ import java.nio.channels.SeekableByteChannel;
|
||||
import java.nio.file.FileSystemException;
|
||||
import java.nio.file.*;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -22,7 +21,7 @@ import java.util.Set;
|
||||
* A {@link Mount} implementation which provides read-only access to a directory.
|
||||
*/
|
||||
public class FileMount implements Mount {
|
||||
private static final Set<OpenOption> READ_OPTIONS = Collections.singleton(StandardOpenOption.READ);
|
||||
private static final Set<OpenOption> READ_OPTIONS = Set.of(StandardOpenOption.READ);
|
||||
|
||||
protected final Path root;
|
||||
|
||||
|
@@ -195,7 +195,7 @@ public class ComputerTestDelegate {
|
||||
DynamicNodeBuilder(String name, String path, Executable executor) {
|
||||
this.name = name;
|
||||
this.uri = getUri(path);
|
||||
this.children = Collections.emptyMap();
|
||||
this.children = Map.of();
|
||||
this.executor = executor;
|
||||
}
|
||||
|
||||
@@ -295,7 +295,7 @@ public class ComputerTestDelegate {
|
||||
|
||||
@LuaFunction
|
||||
public final Collection<String> getNamesRemote() {
|
||||
return Collections.singleton("remote_1");
|
||||
return List.of("remote_1");
|
||||
}
|
||||
|
||||
@LuaFunction
|
||||
@@ -315,7 +315,7 @@ public class ComputerTestDelegate {
|
||||
|
||||
@LuaFunction
|
||||
public final Object[] getMethodsRemote(String name) {
|
||||
return name.equals("remote_1") ? new Object[]{ Collections.singletonList("func") } : null;
|
||||
return name.equals("remote_1") ? new Object[]{ List.of("func") } : null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -10,7 +10,7 @@ import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
@@ -18,7 +18,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
public class AddressRuleTest {
|
||||
@Test
|
||||
public void matchesPort() {
|
||||
Iterable<AddressRule> rules = Collections.singletonList(AddressRule.parse(
|
||||
Iterable<AddressRule> rules = List.of(AddressRule.parse(
|
||||
"127.0.0.1", OptionalInt.of(8080),
|
||||
Action.ALLOW.toPartial()
|
||||
));
|
||||
|
@@ -14,7 +14,7 @@ import dan200.computercraft.core.methods.ObjectSource;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
@@ -169,7 +169,7 @@ public class MethodTest {
|
||||
|
||||
@Override
|
||||
public Iterable<Object> getExtra() {
|
||||
return Collections.singletonList(new GeneratorTest.Basic());
|
||||
return List.of(new GeneratorTest.Basic());
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -10,7 +10,7 @@ import net.jqwik.api.arbitraries.SizableArbitrary;
|
||||
import javax.annotation.Nullable;
|
||||
import java.math.BigInteger;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.Spliterators;
|
||||
import java.util.function.Consumer;
|
||||
@@ -74,7 +74,7 @@ public final class ArbitraryByteBuffer implements SizableArbitrary<ByteBuffer> {
|
||||
|
||||
@Override
|
||||
public EdgeCases<ByteBuffer> edgeCases(int maxEdgeCases) {
|
||||
return EdgeCases.fromSuppliers(Arrays.asList(
|
||||
return EdgeCases.fromSuppliers(List.of(
|
||||
() -> new ShrinkableBuffer(allocateRandom(minSize, new Random()), minSize),
|
||||
() -> new ShrinkableBuffer(allocateRandom(getMaxSize(), new Random()), minSize)
|
||||
));
|
||||
|
Reference in New Issue
Block a user