diff --git a/projects/common/src/client/java/dan200/computercraft/client/gui/AbstractComputerScreen.java b/projects/common/src/client/java/dan200/computercraft/client/gui/AbstractComputerScreen.java index b81be66760..8faf9e3654 100644 --- a/projects/common/src/client/java/dan200/computercraft/client/gui/AbstractComputerScreen.java +++ b/projects/common/src/client/java/dan200/computercraft/client/gui/AbstractComputerScreen.java @@ -33,7 +33,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.concurrent.TimeUnit; @@ -219,7 +218,7 @@ public void uploadResult(UploadResult result, @Nullable Component message) { private void alert(Component title, Component message) { OptionScreen.show(minecraft, title, message, - Collections.singletonList(OptionScreen.newButton(OK, b -> minecraft.setScreen(this))), + List.of(OptionScreen.newButton(OK, b -> minecraft.setScreen(this))), () -> minecraft.setScreen(this) ); } diff --git a/projects/common/src/main/java/dan200/computercraft/impl/UpgradeManager.java b/projects/common/src/main/java/dan200/computercraft/impl/UpgradeManager.java index d9b0fe3670..dd7dd6a649 100644 --- a/projects/common/src/main/java/dan200/computercraft/impl/UpgradeManager.java +++ b/projects/common/src/main/java/dan200/computercraft/impl/UpgradeManager.java @@ -48,8 +48,8 @@ public record UpgradeWrapper, T extends private final String kind; private final ResourceKey> registry; - private Map> current = Collections.emptyMap(); - private Map> currentWrappers = Collections.emptyMap(); + private Map> current = Map.of(); + private Map> currentWrappers = Map.of(); public UpgradeManager(String kind, String path, ResourceKey> registry) { super(GSON, path); diff --git a/projects/common/src/main/java/dan200/computercraft/impl/network/wired/WiredNetworkChangeImpl.java b/projects/common/src/main/java/dan200/computercraft/impl/network/wired/WiredNetworkChangeImpl.java index f4ee29920e..007b660c13 100644 --- a/projects/common/src/main/java/dan200/computercraft/impl/network/wired/WiredNetworkChangeImpl.java +++ b/projects/common/src/main/java/dan200/computercraft/impl/network/wired/WiredNetworkChangeImpl.java @@ -12,7 +12,7 @@ import java.util.Map; final class WiredNetworkChangeImpl implements WiredNetworkChange { - private static final WiredNetworkChangeImpl EMPTY = new WiredNetworkChangeImpl(Collections.emptyMap(), Collections.emptyMap()); + private static final WiredNetworkChangeImpl EMPTY = new WiredNetworkChangeImpl(Map.of(), Map.of()); private final Map removed; private final Map added; @@ -27,11 +27,11 @@ static WiredNetworkChangeImpl changed(Map removed, Map added) { - return added.isEmpty() ? EMPTY : new WiredNetworkChangeImpl(Collections.emptyMap(), Collections.unmodifiableMap(added)); + return added.isEmpty() ? EMPTY : new WiredNetworkChangeImpl(Map.of(), Collections.unmodifiableMap(added)); } static WiredNetworkChangeImpl removed(Map removed) { - return removed.isEmpty() ? EMPTY : new WiredNetworkChangeImpl(Collections.unmodifiableMap(removed), Collections.emptyMap()); + return removed.isEmpty() ? EMPTY : new WiredNetworkChangeImpl(Collections.unmodifiableMap(removed), Map.of()); } static WiredNetworkChangeImpl changeOf(Map oldPeripherals, Map newPeripherals) { @@ -39,9 +39,9 @@ static WiredNetworkChangeImpl changeOf(Map oldPeripherals, if (oldPeripherals.isEmpty() && newPeripherals.isEmpty()) { return EMPTY; } else if (oldPeripherals.isEmpty()) { - return new WiredNetworkChangeImpl(Collections.emptyMap(), newPeripherals); + return new WiredNetworkChangeImpl(Map.of(), newPeripherals); } else if (newPeripherals.isEmpty()) { - return new WiredNetworkChangeImpl(oldPeripherals, Collections.emptyMap()); + return new WiredNetworkChangeImpl(oldPeripherals, Map.of()); } Map added = new HashMap<>(newPeripherals); diff --git a/projects/common/src/main/java/dan200/computercraft/impl/network/wired/WiredNetworkImpl.java b/projects/common/src/main/java/dan200/computercraft/impl/network/wired/WiredNetworkImpl.java index 7e9df786fa..ef85273042 100644 --- a/projects/common/src/main/java/dan200/computercraft/impl/network/wired/WiredNetworkImpl.java +++ b/projects/common/src/main/java/dan200/computercraft/impl/network/wired/WiredNetworkImpl.java @@ -56,10 +56,10 @@ public boolean connect(WiredNode nodeU, WiredNode nodeV) { // Move all nodes across into this network, destroying the original nodes. nodes.addAll(otherNodes); for (var node : otherNodes) node.network = this; - other.nodes = Collections.emptySet(); + other.nodes = Set.of(); // Move all peripherals across, - other.peripherals = Collections.emptyMap(); + other.peripherals = Map.of(); peripherals.putAll(otherPeripherals); if (!thisPeripherals.isEmpty()) { @@ -216,7 +216,7 @@ public boolean remove(WiredNode node) { try { // We special case the original node: detaching all peripherals when needed. wired.network = wiredNetwork; - wired.peripherals = Collections.emptyMap(); + wired.peripherals = Map.of(); // Ensure every network is finalised for (var network : maximals) { @@ -332,7 +332,7 @@ private void removeSingleNode(WiredNodeImpl wired, WiredNetworkImpl wiredNetwork // Detach the old peripherals then remove them from the old network wired.network = wiredNetwork; wired.neighbours.clear(); - wired.peripherals = Collections.emptyMap(); + wired.peripherals = Map.of(); // Broadcast the change if (!peripherals.isEmpty()) WiredNetworkChangeImpl.removed(peripherals).broadcast(wired); diff --git a/projects/common/src/main/java/dan200/computercraft/shared/command/CommandComputerCraft.java b/projects/common/src/main/java/dan200/computercraft/shared/command/CommandComputerCraft.java index fd9e83454a..834ce21915 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/command/CommandComputerCraft.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/command/CommandComputerCraft.java @@ -89,7 +89,7 @@ public static void register(CommandDispatcher dispatcher) { RequiredArgumentBuilder.argument("computer", manyComputers()) .suggests((context, builder) -> Suggestions.empty()) ) - .argManyValue("args", StringArgumentType.string(), Collections.emptyList()) + .argManyValue("args", StringArgumentType.string(), List.of()) .executes((c, a) -> queue(getComputersArgument(c, "computer"), a))) .then(command("view") @@ -300,7 +300,7 @@ private static int trackStop(CommandSourceStack source) throws CommandSyntaxExce return 1; } - private static final List DEFAULT_FIELDS = Arrays.asList( + private static final List DEFAULT_FIELDS = List.of( new AggregatedMetric(Metrics.COMPUTER_TASKS, Aggregate.COUNT), new AggregatedMetric(Metrics.COMPUTER_TASKS, Aggregate.NONE), new AggregatedMetric(Metrics.COMPUTER_TASKS, Aggregate.AVG) diff --git a/projects/common/src/main/java/dan200/computercraft/shared/command/arguments/ComputersArgumentType.java b/projects/common/src/main/java/dan200/computercraft/shared/command/arguments/ComputersArgumentType.java index d263cb5cae..7cbee3b390 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/command/arguments/ComputersArgumentType.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/command/arguments/ComputersArgumentType.java @@ -32,7 +32,7 @@ public final class ComputersArgumentType implements ArgumentType EXAMPLES = Arrays.asList( + private static final List EXAMPLES = List.of( "0", "#0", "@Label", "~Advanced" ); @@ -75,7 +75,7 @@ public ComputersSupplier parse(StringReader reader) throws CommandSyntaxExceptio var instance = reader.readInt(); computers = s -> { var computer = ServerContext.get(s.getServer()).registry().get(instance); - return computer == null ? Collections.emptyList() : Collections.singletonList(computer); + return computer == null ? List.of() : List.of(computer); }; } diff --git a/projects/common/src/main/java/dan200/computercraft/shared/command/builder/CommandBuilder.java b/projects/common/src/main/java/dan200/computercraft/shared/command/builder/CommandBuilder.java index a150b8c88d..02401973e4 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/command/builder/CommandBuilder.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/command/builder/CommandBuilder.java @@ -15,7 +15,6 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.function.Predicate; import java.util.function.Supplier; @@ -63,7 +62,7 @@ public CommandNodeBuilder>> argManyValue(String nam } public CommandNodeBuilder>> argManyValue(String name, ArgumentType type, T defaultValue) { - return argManyValue(name, type, Collections.singletonList(defaultValue)); + return argManyValue(name, type, List.of(defaultValue)); } public CommandNodeBuilder>> argMany(String name, ArgumentType type, Supplier> empty) { diff --git a/projects/common/src/main/java/dan200/computercraft/shared/computer/apis/CommandAPI.java b/projects/common/src/main/java/dan200/computercraft/shared/computer/apis/CommandAPI.java index 3715570d7a..3fcb162c24 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/computer/apis/CommandAPI.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/computer/apis/CommandAPI.java @@ -134,12 +134,12 @@ public final long execAsync(ILuaContext context, String command) throws LuaExcep public final List list(IArguments args) throws LuaException { var server = computer.getLevel().getServer(); - if (server == null) return Collections.emptyList(); + if (server == null) return List.of(); CommandNode node = server.getCommands().getDispatcher().getRoot(); for (var j = 0; j < args.count(); j++) { var name = args.getString(j); node = node.getChild(name); - if (!(node instanceof LiteralCommandNode)) return Collections.emptyList(); + if (!(node instanceof LiteralCommandNode)) return List.of(); } List result = new ArrayList<>(); diff --git a/projects/common/src/main/java/dan200/computercraft/shared/data/BlockNamedEntityLootCondition.java b/projects/common/src/main/java/dan200/computercraft/shared/data/BlockNamedEntityLootCondition.java index 81f2957724..bec825a0ec 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/data/BlockNamedEntityLootCondition.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/data/BlockNamedEntityLootCondition.java @@ -12,7 +12,6 @@ import net.minecraft.world.level.storage.loot.predicates.LootItemCondition; import net.minecraft.world.level.storage.loot.predicates.LootItemConditionType; -import java.util.Collections; import java.util.Set; /** @@ -33,7 +32,7 @@ public boolean test(LootContext lootContext) { @Override public Set> getReferencedContextParams() { - return Collections.singleton(LootContextParams.BLOCK_ENTITY); + return Set.of(LootContextParams.BLOCK_ENTITY); } @Override diff --git a/projects/common/src/main/java/dan200/computercraft/shared/data/HasComputerIdLootCondition.java b/projects/common/src/main/java/dan200/computercraft/shared/data/HasComputerIdLootCondition.java index da73a0b4c5..d89f9783de 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/data/HasComputerIdLootCondition.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/data/HasComputerIdLootCondition.java @@ -12,7 +12,6 @@ import net.minecraft.world.level.storage.loot.predicates.LootItemCondition; import net.minecraft.world.level.storage.loot.predicates.LootItemConditionType; -import java.util.Collections; import java.util.Set; /** @@ -33,7 +32,7 @@ public boolean test(LootContext lootContext) { @Override public Set> getReferencedContextParams() { - return Collections.singleton(LootContextParams.BLOCK_ENTITY); + return Set.of(LootContextParams.BLOCK_ENTITY); } @Override diff --git a/projects/common/src/main/java/dan200/computercraft/shared/data/PlayerCreativeLootCondition.java b/projects/common/src/main/java/dan200/computercraft/shared/data/PlayerCreativeLootCondition.java index 36e248f64d..0601b84854 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/data/PlayerCreativeLootCondition.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/data/PlayerCreativeLootCondition.java @@ -12,7 +12,6 @@ import net.minecraft.world.level.storage.loot.predicates.LootItemCondition; import net.minecraft.world.level.storage.loot.predicates.LootItemConditionType; -import java.util.Collections; import java.util.Set; /** @@ -33,7 +32,7 @@ public boolean test(LootContext lootContext) { @Override public Set> getReferencedContextParams() { - return Collections.singleton(LootContextParams.THIS_ENTITY); + return Set.of(LootContextParams.THIS_ENTITY); } @Override diff --git a/projects/common/src/main/java/dan200/computercraft/shared/integration/RecipeModHelpers.java b/projects/common/src/main/java/dan200/computercraft/shared/integration/RecipeModHelpers.java index e848accef2..44b0c7c3d8 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/integration/RecipeModHelpers.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/integration/RecipeModHelpers.java @@ -9,14 +9,12 @@ import dan200.computercraft.impl.PocketUpgrades; import dan200.computercraft.impl.TurtleUpgrades; import dan200.computercraft.shared.ModRegistry; -import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.pocket.items.PocketComputerItem; import dan200.computercraft.shared.turtle.items.TurtleItem; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.function.Supplier; @@ -24,7 +22,6 @@ * Utilities for recipe mod plugins (such as JEI). */ public final class RecipeModHelpers { - static final List MAIN_FAMILIES = Arrays.asList(ComputerFamily.NORMAL, ComputerFamily.ADVANCED); static final List> TURTLES = List.of(ModRegistry.Items.TURTLE_NORMAL, ModRegistry.Items.TURTLE_ADVANCED); static final List> POCKET_COMPUTERS = List.of(ModRegistry.Items.POCKET_COMPUTER_NORMAL, ModRegistry.Items.POCKET_COMPUTER_ADVANCED); diff --git a/projects/common/src/main/java/dan200/computercraft/shared/integration/UpgradeRecipeGenerator.java b/projects/common/src/main/java/dan200/computercraft/shared/integration/UpgradeRecipeGenerator.java index 253f76a280..95a7700d94 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/integration/UpgradeRecipeGenerator.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/integration/UpgradeRecipeGenerator.java @@ -114,7 +114,7 @@ public List findRecipesWithInput(ItemStack stack) { // Suggest possible upgrades which can be applied to this turtle var left = item.getUpgradeWithData(stack, TurtleSide.LEFT); var right = item.getUpgradeWithData(stack, TurtleSide.RIGHT); - if (left != null && right != null) return Collections.emptyList(); + if (left != null && right != null) return List.of(); List recipes = new ArrayList<>(); var ingredient = Ingredient.of(stack); @@ -135,7 +135,7 @@ public List findRecipesWithInput(ItemStack stack) { } else if (stack.getItem() instanceof PocketComputerItem) { // Suggest possible upgrades which can be applied to this turtle var back = PocketComputerItem.getUpgrade(stack); - if (back != null) return Collections.emptyList(); + if (back != null) return List.of(); List recipes = new ArrayList<>(); var ingredient = Ingredient.of(stack); @@ -148,7 +148,7 @@ public List findRecipesWithInput(ItemStack stack) { } else { // If this item is usable as an upgrade, find all possible recipes. var upgrades = upgradeItemLookup.get(stack.getItem()); - if (upgrades == null) return Collections.emptyList(); + if (upgrades == null) return List.of(); List recipes = null; var multiple = false; @@ -169,7 +169,7 @@ public List findRecipesWithInput(ItemStack stack) { } } - return recipes == null ? Collections.emptyList() : Collections.unmodifiableList(recipes); + return recipes == null ? List.of() : Collections.unmodifiableList(recipes); } } @@ -215,7 +215,7 @@ public List findRecipesWithOutput(ItemStack stack) { return Collections.unmodifiableList(recipes); } else { - return Collections.emptyList(); + return List.of(); } } diff --git a/projects/common/src/main/java/dan200/computercraft/shared/integration/jei/JEIComputerCraft.java b/projects/common/src/main/java/dan200/computercraft/shared/integration/jei/JEIComputerCraft.java index b6b0146970..6893b7d1a2 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/integration/jei/JEIComputerCraft.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/integration/jei/JEIComputerCraft.java @@ -22,7 +22,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; -import java.util.Collections; +import java.util.List; @JeiPlugin public class JEIComputerCraft implements IModPlugin { @@ -61,7 +61,7 @@ public void onRuntimeAvailable(IJeiRuntime runtime) { var category = registry.createRecipeLookup(RecipeTypes.CRAFTING); category.get().forEach(wrapper -> { if (RecipeModHelpers.shouldRemoveRecipe(wrapper.getId())) { - registry.hideRecipes(RecipeTypes.CRAFTING, Collections.singleton(wrapper)); + registry.hideRecipes(RecipeTypes.CRAFTING, List.of(wrapper)); } }); } diff --git a/projects/common/src/main/java/dan200/computercraft/shared/integration/jei/RecipeResolver.java b/projects/common/src/main/java/dan200/computercraft/shared/integration/jei/RecipeResolver.java index 29030d6f21..afccd5a5e7 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/integration/jei/RecipeResolver.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/integration/jei/RecipeResolver.java @@ -15,7 +15,6 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.CraftingRecipe; -import java.util.Collections; import java.util.List; class RecipeResolver implements IRecipeManagerPlugin { @@ -24,36 +23,36 @@ class RecipeResolver implements IRecipeManagerPlugin { @Override public List> getRecipeTypes(IFocus focus) { var value = focus.getTypedValue().getIngredient(); - if (!(value instanceof ItemStack stack)) return Collections.emptyList(); + if (!(value instanceof ItemStack stack)) return List.of(); return switch (focus.getRole()) { case INPUT -> stack.getItem() instanceof TurtleItem || stack.getItem() instanceof PocketComputerItem || resolver.isUpgrade(stack) - ? Collections.singletonList(RecipeTypes.CRAFTING) - : Collections.emptyList(); + ? List.of(RecipeTypes.CRAFTING) + : List.of(); case OUTPUT -> stack.getItem() instanceof TurtleItem || stack.getItem() instanceof PocketComputerItem - ? Collections.singletonList(RecipeTypes.CRAFTING) - : Collections.emptyList(); - default -> Collections.emptyList(); + ? List.of(RecipeTypes.CRAFTING) + : List.of(); + default -> List.of(); }; } @Override public List getRecipes(IRecipeCategory recipeCategory, IFocus focus) { if (!(focus.getTypedValue().getIngredient() instanceof ItemStack stack) || recipeCategory.getRecipeType() != RecipeTypes.CRAFTING) { - return Collections.emptyList(); + return List.of(); } return switch (focus.getRole()) { case INPUT -> cast(resolver.findRecipesWithInput(stack)); case OUTPUT -> cast(resolver.findRecipesWithOutput(stack)); - default -> Collections.emptyList(); + default -> List.of(); }; } @Override public List getRecipes(IRecipeCategory recipeCategory) { - return Collections.emptyList(); + return List.of(); } @SuppressWarnings({ "unchecked", "rawtypes" }) diff --git a/projects/common/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/CableBlockEntity.java b/projects/common/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/CableBlockEntity.java index 4584e76df7..d0d162c6f6 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/CableBlockEntity.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/CableBlockEntity.java @@ -30,7 +30,7 @@ import net.minecraft.world.phys.Vec3; import javax.annotation.Nullable; -import java.util.Collections; +import java.util.Map; import java.util.Objects; public class CableBlockEntity extends BlockEntity { @@ -274,7 +274,7 @@ void modemChanged() { if (!canAttachPeripheral() && peripheralAccessAllowed) { peripheralAccessAllowed = false; peripheral.detach(); - node.updatePeripherals(Collections.emptyMap()); + node.updatePeripherals(Map.of()); setChanged(); updateBlockState(); } @@ -291,7 +291,7 @@ private void togglePeripheralAccess() { peripheral.detach(); peripheralAccessAllowed = false; - node.updatePeripherals(Collections.emptyMap()); + node.updatePeripherals(Map.of()); } updateBlockState(); diff --git a/projects/common/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/WiredModemFullBlockEntity.java b/projects/common/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/WiredModemFullBlockEntity.java index dca62cd74f..fa2c07abd2 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/WiredModemFullBlockEntity.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/WiredModemFullBlockEntity.java @@ -240,14 +240,14 @@ private void togglePeripheralAccess() { peripheralAccessAllowed = false; for (var peripheral : peripherals) peripheral.detach(); - node.updatePeripherals(Collections.emptyMap()); + node.updatePeripherals(Map.of()); } updateBlockState(); } private Set getConnectedPeripheralNames() { - if (!peripheralAccessAllowed) return Collections.emptySet(); + if (!peripheralAccessAllowed) return Set.of(); Set peripherals = new HashSet<>(6); for (var peripheral : this.peripherals) { @@ -258,7 +258,7 @@ private Set getConnectedPeripheralNames() { } private Map getConnectedPeripherals() { - if (!peripheralAccessAllowed) return Collections.emptyMap(); + if (!peripheralAccessAllowed) return Map.of(); Map peripherals = new HashMap<>(6); for (var peripheral : this.peripherals) peripheral.extendMap(peripherals); diff --git a/projects/common/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/WiredModemLocalPeripheral.java b/projects/common/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/WiredModemLocalPeripheral.java index 4a806cac2f..22bd70fac0 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/WiredModemLocalPeripheral.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/WiredModemLocalPeripheral.java @@ -103,7 +103,7 @@ public void extendMap(Map peripherals) { public Map toMap() { return peripheral == null - ? Collections.emptyMap() + ? Map.of() : Collections.singletonMap(type + "_" + id, peripheral); } diff --git a/projects/common/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/WiredModemPeripheral.java b/projects/common/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/WiredModemPeripheral.java index ee8719f915..96e2ef1edd 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/WiredModemPeripheral.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/WiredModemPeripheral.java @@ -68,7 +68,7 @@ public Level getLevel() { @Override public Set getAdditionalTypes() { - return Collections.singleton("peripheral_hub"); + return Set.of("peripheral_hub"); } //region Peripheral methods @@ -88,7 +88,7 @@ public Set getAdditionalTypes() { @LuaFunction public final Collection getNamesRemote(IComputerAccess computer) { var wrappers = getWrappers(computer); - return wrappers == null ? Collections.emptySet() : wrappers.keySet(); + return wrappers == null ? Set.of() : wrappers.keySet(); } /** diff --git a/projects/common/src/main/java/dan200/computercraft/shared/pocket/core/PocketServerComputer.java b/projects/common/src/main/java/dan200/computercraft/shared/pocket/core/PocketServerComputer.java index a6662c93d1..35db4abddc 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/pocket/core/PocketServerComputer.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/pocket/core/PocketServerComputer.java @@ -107,7 +107,7 @@ public void invalidatePeripheral() { @Override @Deprecated(forRemoval = true) public Map getUpgrades() { - return upgrade == null ? Collections.emptyMap() : Collections.singletonMap(upgrade.getUpgradeID(), getPeripheral(ComputerSide.BACK)); + return upgrade == null ? Map.of() : Collections.singletonMap(upgrade.getUpgradeID(), getPeripheral(ComputerSide.BACK)); } public @Nullable UpgradeData getUpgrade() { diff --git a/projects/common/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleInventoryCrafting.java b/projects/common/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleInventoryCrafting.java index 0829806838..e428d36fdc 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleInventoryCrafting.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleInventoryCrafting.java @@ -70,7 +70,7 @@ public List doCrafting(Level world, int maxCount) { if (recipe == null) return null; // Special case: craft(0) just returns an empty list if crafting was possible - if (maxCount == 0) return Collections.emptyList(); + if (maxCount == 0) return List.of(); var player = TurtlePlayer.get(turtle).player(); diff --git a/projects/common/src/main/java/dan200/computercraft/shared/util/NBTUtil.java b/projects/common/src/main/java/dan200/computercraft/shared/util/NBTUtil.java index 5fa6f70617..bad2223cb3 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/util/NBTUtil.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/util/NBTUtil.java @@ -20,7 +20,6 @@ import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Arrays; -import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -38,7 +37,7 @@ public final class NBTUtil { try { var ctor = CompoundTag.class.getDeclaredConstructor(Map.class); ctor.setAccessible(true); - EMPTY_TAG = ctor.newInstance(Collections.emptyMap()); + EMPTY_TAG = ctor.newInstance(Map.of()); } catch (ReflectiveOperationException e) { throw new RuntimeException(e); } diff --git a/projects/common/src/test/java/dan200/computercraft/shared/network/server/UploadFileMessageTest.java b/projects/common/src/test/java/dan200/computercraft/shared/network/server/UploadFileMessageTest.java index 1add6e2d91..0322f34be3 100644 --- a/projects/common/src/test/java/dan200/computercraft/shared/network/server/UploadFileMessageTest.java +++ b/projects/common/src/test/java/dan200/computercraft/shared/network/server/UploadFileMessageTest.java @@ -16,7 +16,6 @@ import java.nio.ByteBuffer; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; @@ -110,7 +109,7 @@ private static List receive(List packets) { @Provide Arbitrary fileUpload() { return Combinators.combine( - Arbitraries.oneOf(Arrays.asList( + Arbitraries.oneOf(List.of( // 1.16 doesn't correctly handle unicode file names. We'll be generous in our tests here. Arbitraries.strings().ofMinLength(1).ascii().ofMaxLength(MAX_FILE_NAME), Arbitraries.strings().ofMinLength(1).ofMaxLength(MAX_FILE_NAME / 4) diff --git a/projects/common/src/testMod/java/dan200/computercraft/export/JsonDump.java b/projects/common/src/testMod/java/dan200/computercraft/export/JsonDump.java index 43d642cd78..474c879bf1 100644 --- a/projects/common/src/testMod/java/dan200/computercraft/export/JsonDump.java +++ b/projects/common/src/testMod/java/dan200/computercraft/export/JsonDump.java @@ -52,8 +52,8 @@ public void setInput(int pos, Ingredient ingredient, Set trackedItems) { inputs[pos] = itemIds; } - private static final Set canonicalItem = new HashSet<>(Arrays.asList( + private static final Set canonicalItem = Set.of( Items.GLASS_PANE, Items.STONE, Items.CHEST - )); + ); } } diff --git a/projects/common/src/testMod/kotlin/dan200/computercraft/gametest/Monitor_Test.kt b/projects/common/src/testMod/kotlin/dan200/computercraft/gametest/Monitor_Test.kt index 2433a58938..ebc158c67c 100644 --- a/projects/common/src/testMod/kotlin/dan200/computercraft/gametest/Monitor_Test.kt +++ b/projects/common/src/testMod/kotlin/dan200/computercraft/gametest/Monitor_Test.kt @@ -35,7 +35,7 @@ class Monitor_Test { val toSet = BlockInput( ModRegistry.Blocks.MONITOR_ADVANCED.get().defaultBlockState(), - Collections.emptySet(), + emptySet(), tag, ) diff --git a/projects/core-api/src/main/java/dan200/computercraft/api/peripheral/IPeripheral.java b/projects/core-api/src/main/java/dan200/computercraft/api/peripheral/IPeripheral.java index 501894dddf..1a857d8d04 100644 --- a/projects/core-api/src/main/java/dan200/computercraft/api/peripheral/IPeripheral.java +++ b/projects/core-api/src/main/java/dan200/computercraft/api/peripheral/IPeripheral.java @@ -7,7 +7,6 @@ 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 getAdditionalTypes() { - return Collections.emptySet(); + return Set.of(); } /** diff --git a/projects/core-api/src/main/java/dan200/computercraft/api/peripheral/PeripheralType.java b/projects/core-api/src/main/java/dan200/computercraft/api/peripheral/PeripheralType.java index 1b5edf6f1e..08cc97448d 100644 --- a/projects/core-api/src/main/java/dan200/computercraft/api/peripheral/PeripheralType.java +++ b/projects/core-api/src/main/java/dan200/computercraft/api/peripheral/PeripheralType.java @@ -6,7 +6,6 @@ import javax.annotation.Nullable; import java.util.Collection; -import java.util.Collections; import java.util.Set; /** @@ -16,7 +15,7 @@ * 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 additionalTypes; @@ -46,7 +45,7 @@ public static PeripheralType untyped() { */ 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 @@ private static void checkTypeName(@Nullable String type) { } private static Set getTypes(Collection 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); } } diff --git a/projects/core/src/main/java/dan200/computercraft/core/apis/HTTPAPI.java b/projects/core/src/main/java/dan200/computercraft/core/apis/HTTPAPI.java index a97c03a065..65ef1f966c 100644 --- a/projects/core/src/main/java/dan200/computercraft/core/apis/HTTPAPI.java +++ b/projects/core/src/main/java/dan200/computercraft/core/apis/HTTPAPI.java @@ -18,7 +18,6 @@ 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 final Object[] request(IArguments args) throws LuaException { 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 final Object[] request(IArguments args) throws LuaException { // 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 final Object[] websocket(IArguments args) throws LuaException { 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(); } diff --git a/projects/core/src/main/java/dan200/computercraft/core/apis/http/request/HttpResponseHandle.java b/projects/core/src/main/java/dan200/computercraft/core/apis/http/request/HttpResponseHandle.java index e82e5c3ad0..126ddc1336 100644 --- a/projects/core/src/main/java/dan200/computercraft/core/apis/http/request/HttpResponseHandle.java +++ b/projects/core/src/main/java/dan200/computercraft/core/apis/http/request/HttpResponseHandle.java @@ -12,7 +12,7 @@ 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 final Map getResponseHeaders() { @Override public Iterable getExtra() { - return Collections.singletonList(reader); + return List.of(reader); } } diff --git a/projects/core/src/main/java/dan200/computercraft/core/apis/transfer/TransferredFile.java b/projects/core/src/main/java/dan200/computercraft/core/apis/transfer/TransferredFile.java index 1893d9290b..177dc66663 100644 --- a/projects/core/src/main/java/dan200/computercraft/core/apis/transfer/TransferredFile.java +++ b/projects/core/src/main/java/dan200/computercraft/core/apis/transfer/TransferredFile.java @@ -9,7 +9,7 @@ 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 final String getName() { @Override public Iterable getExtra() { - return Collections.singleton(handle); + return List.of(handle); } } diff --git a/projects/core/src/main/java/dan200/computercraft/core/computer/ComputerSystem.java b/projects/core/src/main/java/dan200/computercraft/core/computer/ComputerSystem.java index 9e776d1838..12bb8cc8c0 100644 --- a/projects/core/src/main/java/dan200/computercraft/core/computer/ComputerSystem.java +++ b/projects/core/src/main/java/dan200/computercraft/core/computer/ComputerSystem.java @@ -12,7 +12,6 @@ import dan200.computercraft.core.apis.IAPIEnvironment; import javax.annotation.Nullable; -import java.util.Collections; import java.util.Map; /** @@ -43,7 +42,7 @@ public String getLabel() { @Override public Map getAvailablePeripherals() { // TODO: Should this return peripherals on the current computer? - return Collections.emptyMap(); + return Map.of(); } @Nullable diff --git a/projects/core/src/main/java/dan200/computercraft/core/filesystem/FileMount.java b/projects/core/src/main/java/dan200/computercraft/core/filesystem/FileMount.java index b9a27687bb..087464cd77 100644 --- a/projects/core/src/main/java/dan200/computercraft/core/filesystem/FileMount.java +++ b/projects/core/src/main/java/dan200/computercraft/core/filesystem/FileMount.java @@ -14,7 +14,6 @@ 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 @@ * A {@link Mount} implementation which provides read-only access to a directory. */ public class FileMount implements Mount { - private static final Set READ_OPTIONS = Collections.singleton(StandardOpenOption.READ); + private static final Set READ_OPTIONS = Set.of(StandardOpenOption.READ); protected final Path root; diff --git a/projects/core/src/test/java/dan200/computercraft/core/ComputerTestDelegate.java b/projects/core/src/test/java/dan200/computercraft/core/ComputerTestDelegate.java index c411959ae9..da6ecab5e9 100644 --- a/projects/core/src/test/java/dan200/computercraft/core/ComputerTestDelegate.java +++ b/projects/core/src/test/java/dan200/computercraft/core/ComputerTestDelegate.java @@ -195,7 +195,7 @@ private static class DynamicNodeBuilder { 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 boolean equals(@Nullable IPeripheral other) { @LuaFunction public final Collection getNamesRemote() { - return Collections.singleton("remote_1"); + return List.of("remote_1"); } @LuaFunction @@ -315,7 +315,7 @@ public final Object[] hasTypeRemote(String name, String type) { @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; } } diff --git a/projects/core/src/test/java/dan200/computercraft/core/apis/http/options/AddressRuleTest.java b/projects/core/src/test/java/dan200/computercraft/core/apis/http/options/AddressRuleTest.java index 1e403f6822..ddf009c821 100644 --- a/projects/core/src/test/java/dan200/computercraft/core/apis/http/options/AddressRuleTest.java +++ b/projects/core/src/test/java/dan200/computercraft/core/apis/http/options/AddressRuleTest.java @@ -10,7 +10,7 @@ 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 @@ public class AddressRuleTest { @Test public void matchesPort() { - Iterable rules = Collections.singletonList(AddressRule.parse( + Iterable rules = List.of(AddressRule.parse( "127.0.0.1", OptionalInt.of(8080), Action.ALLOW.toPartial() )); diff --git a/projects/core/src/test/java/dan200/computercraft/core/asm/MethodTest.java b/projects/core/src/test/java/dan200/computercraft/core/asm/MethodTest.java index c405250076..2bfa495e89 100644 --- a/projects/core/src/test/java/dan200/computercraft/core/asm/MethodTest.java +++ b/projects/core/src/test/java/dan200/computercraft/core/asm/MethodTest.java @@ -14,7 +14,7 @@ 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 final int go2() { @Override public Iterable getExtra() { - return Collections.singletonList(new GeneratorTest.Basic()); + return List.of(new GeneratorTest.Basic()); } } diff --git a/projects/core/src/testFixtures/java/dan200/computercraft/test/core/ArbitraryByteBuffer.java b/projects/core/src/testFixtures/java/dan200/computercraft/test/core/ArbitraryByteBuffer.java index f117e543de..2866e4206b 100644 --- a/projects/core/src/testFixtures/java/dan200/computercraft/test/core/ArbitraryByteBuffer.java +++ b/projects/core/src/testFixtures/java/dan200/computercraft/test/core/ArbitraryByteBuffer.java @@ -10,7 +10,7 @@ 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 RandomGenerator generator(int genSize) { @Override public EdgeCases 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) )); diff --git a/projects/web/src/main/java/dan200/computercraft/core/asm/MethodReflection.java b/projects/web/src/main/java/dan200/computercraft/core/asm/MethodReflection.java index 11203e3d8b..96c3ed8896 100644 --- a/projects/web/src/main/java/dan200/computercraft/core/asm/MethodReflection.java +++ b/projects/web/src/main/java/dan200/computercraft/core/asm/MethodReflection.java @@ -74,7 +74,7 @@ private static final class Internal { .build(CacheLoader.from(Internal::getMethodsImpl)); private static final StaticGenerator GENERATOR = new StaticGenerator<>( - LuaMethod.class, Collections.singletonList(ILuaContext.class), Internal::createClass + LuaMethod.class, List.of(ILuaContext.class), Internal::createClass ); static List>> getMethods(Class klass) {