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:
parent
8eabd4f303
commit
cab66a2d6e
|
@ -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)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -48,8 +48,8 @@ public record UpgradeWrapper<R extends UpgradeSerialiser<? extends T>, T extends
|
|||
private final String kind;
|
||||
private final ResourceKey<Registry<R>> registry;
|
||||
|
||||
private Map<String, UpgradeWrapper<R, T>> current = Collections.emptyMap();
|
||||
private Map<T, UpgradeWrapper<R, T>> currentWrappers = Collections.emptyMap();
|
||||
private Map<String, UpgradeWrapper<R, T>> current = Map.of();
|
||||
private Map<T, UpgradeWrapper<R, T>> currentWrappers = Map.of();
|
||||
|
||||
public UpgradeManager(String kind, String path, ResourceKey<Registry<R>> registry) {
|
||||
super(GSON, path);
|
||||
|
|
|
@ -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<String, IPeripheral> removed;
|
||||
private final Map<String, IPeripheral> added;
|
||||
|
@ -27,11 +27,11 @@ static WiredNetworkChangeImpl changed(Map<String, IPeripheral> removed, Map<Stri
|
|||
}
|
||||
|
||||
static WiredNetworkChangeImpl added(Map<String, IPeripheral> 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<String, IPeripheral> 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<String, IPeripheral> oldPeripherals, Map<String, IPeripheral> newPeripherals) {
|
||||
|
@ -39,9 +39,9 @@ static WiredNetworkChangeImpl changeOf(Map<String, IPeripheral> 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<String, IPeripheral> added = new HashMap<>(newPeripherals);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -89,7 +89,7 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
|
|||
RequiredArgumentBuilder.<CommandSourceStack, ComputersArgumentType.ComputersSupplier>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<AggregatedMetric> DEFAULT_FIELDS = Arrays.asList(
|
||||
private static final List<AggregatedMetric> 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)
|
||||
|
|
|
@ -32,7 +32,7 @@ public final class ComputersArgumentType implements ArgumentType<ComputersArgume
|
|||
private static final ComputersArgumentType MANY = new ComputersArgumentType(false);
|
||||
private static final ComputersArgumentType SOME = new ComputersArgumentType(true);
|
||||
|
||||
private static final List<String> EXAMPLES = Arrays.asList(
|
||||
private static final List<String> 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);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -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 <T> CommandNodeBuilder<S, ArgCommand<S, List<T>>> argManyValue(String nam
|
|||
}
|
||||
|
||||
public <T> CommandNodeBuilder<S, ArgCommand<S, List<T>>> argManyValue(String name, ArgumentType<T> type, T defaultValue) {
|
||||
return argManyValue(name, type, Collections.singletonList(defaultValue));
|
||||
return argManyValue(name, type, List.of(defaultValue));
|
||||
}
|
||||
|
||||
public <T> CommandNodeBuilder<S, ArgCommand<S, List<T>>> argMany(String name, ArgumentType<T> type, Supplier<List<T>> empty) {
|
||||
|
|
|
@ -134,12 +134,12 @@ public final long execAsync(ILuaContext context, String command) throws LuaExcep
|
|||
public final List<String> list(IArguments args) throws LuaException {
|
||||
var server = computer.getLevel().getServer();
|
||||
|
||||
if (server == null) return Collections.emptyList();
|
||||
if (server == null) return List.of();
|
||||
CommandNode<CommandSourceStack> 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<String> result = new ArrayList<>();
|
||||
|
|
|
@ -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<LootContextParam<?>> getReferencedContextParams() {
|
||||
return Collections.singleton(LootContextParams.BLOCK_ENTITY);
|
||||
return Set.of(LootContextParams.BLOCK_ENTITY);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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<LootContextParam<?>> getReferencedContextParams() {
|
||||
return Collections.singleton(LootContextParams.BLOCK_ENTITY);
|
||||
return Set.of(LootContextParams.BLOCK_ENTITY);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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<LootContextParam<?>> getReferencedContextParams() {
|
||||
return Collections.singleton(LootContextParams.THIS_ENTITY);
|
||||
return Set.of(LootContextParams.THIS_ENTITY);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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<ComputerFamily> MAIN_FAMILIES = Arrays.asList(ComputerFamily.NORMAL, ComputerFamily.ADVANCED);
|
||||
static final List<Supplier<TurtleItem>> TURTLES = List.of(ModRegistry.Items.TURTLE_NORMAL, ModRegistry.Items.TURTLE_ADVANCED);
|
||||
static final List<Supplier<PocketComputerItem>> POCKET_COMPUTERS = List.of(ModRegistry.Items.POCKET_COMPUTER_NORMAL, ModRegistry.Items.POCKET_COMPUTER_ADVANCED);
|
||||
|
||||
|
|
|
@ -114,7 +114,7 @@ public List<T> 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<T> recipes = new ArrayList<>();
|
||||
var ingredient = Ingredient.of(stack);
|
||||
|
@ -135,7 +135,7 @@ public List<T> 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<T> recipes = new ArrayList<>();
|
||||
var ingredient = Ingredient.of(stack);
|
||||
|
@ -148,7 +148,7 @@ public List<T> 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<T> recipes = null;
|
||||
var multiple = false;
|
||||
|
@ -169,7 +169,7 @@ public List<T> 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<T> findRecipesWithOutput(ItemStack stack) {
|
|||
|
||||
return Collections.unmodifiableList(recipes);
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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 <V> List<RecipeType<?>> getRecipeTypes(IFocus<V> 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 <T, V> List<T> getRecipes(IRecipeCategory<T> recipeCategory, IFocus<V> 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 <T> List<T> getRecipes(IRecipeCategory<T> recipeCategory) {
|
||||
return Collections.emptyList();
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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<String> getConnectedPeripheralNames() {
|
||||
if (!peripheralAccessAllowed) return Collections.emptySet();
|
||||
if (!peripheralAccessAllowed) return Set.of();
|
||||
|
||||
Set<String> peripherals = new HashSet<>(6);
|
||||
for (var peripheral : this.peripherals) {
|
||||
|
@ -258,7 +258,7 @@ private Set<String> getConnectedPeripheralNames() {
|
|||
}
|
||||
|
||||
private Map<String, IPeripheral> getConnectedPeripherals() {
|
||||
if (!peripheralAccessAllowed) return Collections.emptyMap();
|
||||
if (!peripheralAccessAllowed) return Map.of();
|
||||
|
||||
Map<String, IPeripheral> peripherals = new HashMap<>(6);
|
||||
for (var peripheral : this.peripherals) peripheral.extendMap(peripherals);
|
||||
|
|
|
@ -103,7 +103,7 @@ public void extendMap(Map<String, IPeripheral> peripherals) {
|
|||
|
||||
public Map<String, IPeripheral> toMap() {
|
||||
return peripheral == null
|
||||
? Collections.emptyMap()
|
||||
? Map.of()
|
||||
: Collections.singletonMap(type + "_" + id, peripheral);
|
||||
}
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ public Level getLevel() {
|
|||
|
||||
@Override
|
||||
public Set<String> getAdditionalTypes() {
|
||||
return Collections.singleton("peripheral_hub");
|
||||
return Set.of("peripheral_hub");
|
||||
}
|
||||
|
||||
//region Peripheral methods
|
||||
|
@ -88,7 +88,7 @@ public Set<String> getAdditionalTypes() {
|
|||
@LuaFunction
|
||||
public final Collection<String> getNamesRemote(IComputerAccess computer) {
|
||||
var wrappers = getWrappers(computer);
|
||||
return wrappers == null ? Collections.emptySet() : wrappers.keySet();
|
||||
return wrappers == null ? Set.of() : wrappers.keySet();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -107,7 +107,7 @@ public void invalidatePeripheral() {
|
|||
@Override
|
||||
@Deprecated(forRemoval = true)
|
||||
public Map<ResourceLocation, IPeripheral> 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<IPocketUpgrade> getUpgrade() {
|
||||
|
|
|
@ -70,7 +70,7 @@ public List<ItemStack> 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();
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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<FileUpload> receive(List<UploadFileMessage> packets) {
|
|||
@Provide
|
||||
Arbitrary<FileUpload> 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)
|
||||
|
|
|
@ -52,8 +52,8 @@ public void setInput(int pos, Ingredient ingredient, Set<Item> trackedItems) {
|
|||
inputs[pos] = itemIds;
|
||||
}
|
||||
|
||||
private static final Set<Item> canonicalItem = new HashSet<>(Arrays.asList(
|
||||
private static final Set<Item> canonicalItem = Set.of(
|
||||
Items.GLASS_PANE, Items.STONE, Items.CHEST
|
||||
));
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ fun Ensures_valid_on_place(context: GameTestHelper) = context.sequence {
|
|||
|
||||
val toSet = BlockInput(
|
||||
ModRegistry.Blocks.MONITOR_ADVANCED.get().defaultBlockState(),
|
||||
Collections.emptySet(),
|
||||
emptySet(),
|
||||
tag,
|
||||
)
|
||||
|
||||
|
|
|
@ -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<String> getAdditionalTypes() {
|
||||
return Collections.emptySet();
|
||||
return Set.of();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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<String> 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<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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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<String, String> getResponseHeaders() {
|
|||
|
||||
@Override
|
||||
public Iterable<Object> getExtra() {
|
||||
return Collections.singletonList(reader);
|
||||
return List.of(reader);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Object> getExtra() {
|
||||
return Collections.singleton(handle);
|
||||
return List.of(handle);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<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.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<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 @@ 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<String> 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<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 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<Object> getExtra() {
|
||||
return Collections.singletonList(new GeneratorTest.Basic());
|
||||
return List.of(new GeneratorTest.Basic());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<ByteBuffer> generator(int genSize) {
|
|||
|
||||
@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)
|
||||
));
|
||||
|
|
|
@ -74,7 +74,7 @@ private static final class Internal {
|
|||
.build(CacheLoader.from(Internal::getMethodsImpl));
|
||||
|
||||
private static final StaticGenerator<LuaMethod> GENERATOR = new StaticGenerator<>(
|
||||
LuaMethod.class, Collections.singletonList(ILuaContext.class), Internal::createClass
|
||||
LuaMethod.class, List.of(ILuaContext.class), Internal::createClass
|
||||
);
|
||||
|
||||
static List<NamedMethod<ReflectClass<LuaMethod>>> getMethods(Class<?> klass) {
|
||||
|
|
Loading…
Reference in New Issue