1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-10-28 12: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:
Jonathan Coates
2023-10-21 10:37:43 +01:00
parent 8eabd4f303
commit cab66a2d6e
37 changed files with 79 additions and 95 deletions

View File

@@ -7,7 +7,6 @@ package dan200.computercraft.api.peripheral;
import dan200.computercraft.api.lua.LuaFunction;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.Set;
/**
@@ -35,7 +34,7 @@ public interface IPeripheral {
* @see PeripheralType#getAdditionalTypes()
*/
default Set<String> getAdditionalTypes() {
return Collections.emptySet();
return Set.of();
}
/**

View File

@@ -6,7 +6,6 @@ package dan200.computercraft.api.peripheral;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
/**
@@ -16,7 +15,7 @@ import java.util.Set;
* lexicographically smallest non-empty name being chosen.
*/
public final class PeripheralType {
private static final PeripheralType UNTYPED = new PeripheralType(null, Collections.emptySet());
private static final PeripheralType UNTYPED = new PeripheralType(null, Set.of());
private final @Nullable String type;
private final Set<String> additionalTypes;
@@ -46,7 +45,7 @@ public final class PeripheralType {
*/
public static PeripheralType ofType(String type) {
checkTypeName("type cannot be null or empty");
return new PeripheralType(type, Collections.emptySet());
return new PeripheralType(type, Set.of());
}
/**
@@ -118,8 +117,8 @@ public final class PeripheralType {
}
private static Set<String> getTypes(Collection<String> types) {
if (types.isEmpty()) return Collections.emptySet();
if (types.size() == 1) return Collections.singleton(types.iterator().next());
if (types.isEmpty()) return Set.of();
if (types.size() == 1) return Set.of(types.iterator().next());
return Set.copyOf(types);
}
}