diff --git a/projects/common-api/src/main/java/dan200/computercraft/api/upgrades/UpgradeDataProvider.java b/projects/common-api/src/main/java/dan200/computercraft/api/upgrades/UpgradeDataProvider.java index 8e634239e..eae2be3d5 100644 --- a/projects/common-api/src/main/java/dan200/computercraft/api/upgrades/UpgradeDataProvider.java +++ b/projects/common-api/src/main/java/dan200/computercraft/api/upgrades/UpgradeDataProvider.java @@ -19,8 +19,6 @@ import net.minecraft.data.PackOutput; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.Item; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import javax.annotation.Nullable; import java.util.*; @@ -36,8 +34,6 @@ import java.util.function.Function; * @param The upgrade serialiser to register for. */ public abstract class UpgradeDataProvider> implements DataProvider { - private static final Logger LOGGER = LogManager.getLogger(); - private final PackOutput output; private final String name; private final String folder; diff --git a/projects/common/src/client/java/dan200/computercraft/client/render/monitor/MonitorTextureBufferShader.java b/projects/common/src/client/java/dan200/computercraft/client/render/monitor/MonitorTextureBufferShader.java index bda4ee17b..9d0b5ef96 100644 --- a/projects/common/src/client/java/dan200/computercraft/client/render/monitor/MonitorTextureBufferShader.java +++ b/projects/common/src/client/java/dan200/computercraft/client/render/monitor/MonitorTextureBufferShader.java @@ -14,10 +14,10 @@ import dan200.computercraft.core.terminal.TextBuffer; import dan200.computercraft.core.util.Colour; import net.minecraft.client.renderer.ShaderInstance; import net.minecraft.server.packs.resources.ResourceProvider; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.lwjgl.opengl.GL13; import org.lwjgl.opengl.GL31; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.annotation.Nullable; import java.io.IOException; @@ -36,12 +36,12 @@ import static dan200.computercraft.client.render.text.FixedWidthFontRenderer.get * @see RenderTypes#getMonitorTextureBufferShader() */ public class MonitorTextureBufferShader extends ShaderInstance { + private static final Logger LOG = LoggerFactory.getLogger(MonitorTextureBufferShader.class); + public static final int UNIFORM_SIZE = 4 * 4 * 16 + 4 + 4 + 2 * 4 + 4; static final int TEXTURE_INDEX = GL13.GL_TEXTURE3; - private static final Logger LOGGER = LogManager.getLogger(); - private final int monitorData; private int uniformBuffer = 0; @@ -75,7 +75,7 @@ public class MonitorTextureBufferShader extends ShaderInstance { private Uniform getUniformChecked(String name) { var uniform = getUniform(name); if (uniform == null) { - LOGGER.warn("Monitor shader {} should have uniform {}, but it was not present.", getName(), name); + LOG.warn("Monitor shader {} should have uniform {}, but it was not present.", getName(), name); } return uniform; 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 a3e25eae5..d9b0fe367 100644 --- a/projects/common/src/main/java/dan200/computercraft/impl/UpgradeManager.java +++ b/projects/common/src/main/java/dan200/computercraft/impl/UpgradeManager.java @@ -18,8 +18,8 @@ import net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener; import net.minecraft.util.GsonHelper; import net.minecraft.util.profiling.ProfilerFiller; import net.minecraft.world.item.ItemStack; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.annotation.Nullable; import java.util.Collection; @@ -37,7 +37,7 @@ import java.util.stream.Collectors; * @see PocketUpgrades */ public class UpgradeManager, T extends UpgradeBase> extends SimpleJsonResourceReloadListener { - private static final Logger LOGGER = LogManager.getLogger(); + private static final Logger LOG = LoggerFactory.getLogger(UpgradeManager.class); private static final Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create(); public record UpgradeWrapper, T extends UpgradeBase>( @@ -103,13 +103,13 @@ public class UpgradeManager, T extends try { loadUpgrade(newUpgrades, element.getKey(), element.getValue()); } catch (IllegalArgumentException | JsonParseException e) { - LOGGER.error("Error loading {} {} from JSON file", kind, element.getKey(), e); + LOG.error("Error loading {} {} from JSON file", kind, element.getKey(), e); } } current = Collections.unmodifiableMap(newUpgrades); currentWrappers = newUpgrades.values().stream().collect(Collectors.toUnmodifiableMap(UpgradeWrapper::upgrade, x -> x)); - LOGGER.info("Loaded {} {}s", current.size(), kind); + LOG.info("Loaded {} {}s", current.size(), kind); } private void loadUpgrade(Map> current, ResourceLocation id, JsonElement json) { 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 d28641d56..7e9df786f 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 @@ -4,7 +4,6 @@ package dan200.computercraft.impl.network.wired; -import com.google.common.collect.ImmutableMap; import dan200.computercraft.api.network.Packet; import dan200.computercraft.api.network.wired.WiredNetwork; import dan200.computercraft.api.network.wired.WiredNode; @@ -260,7 +259,7 @@ final class WiredNetworkImpl implements WiredNetwork { var change = WiredNetworkChangeImpl.changeOf(oldPeripherals, newPeripherals); if (change.isEmpty()) return; - wired.peripherals = ImmutableMap.copyOf(newPeripherals); + wired.peripherals = Map.copyOf(newPeripherals); // Detach the old peripherals then remove them. peripherals.keySet().removeAll(change.peripheralsRemoved().keySet()); diff --git a/projects/common/src/main/java/dan200/computercraft/impl/network/wired/WiredNodeImpl.java b/projects/common/src/main/java/dan200/computercraft/impl/network/wired/WiredNodeImpl.java index 889c3839b..d402053cf 100644 --- a/projects/common/src/main/java/dan200/computercraft/impl/network/wired/WiredNodeImpl.java +++ b/projects/common/src/main/java/dan200/computercraft/impl/network/wired/WiredNodeImpl.java @@ -13,13 +13,16 @@ import dan200.computercraft.api.network.wired.WiredSender; import dan200.computercraft.api.peripheral.IPeripheral; import javax.annotation.Nullable; -import java.util.*; +import java.util.HashSet; +import java.util.Map; +import java.util.Objects; +import java.util.Set; public final class WiredNodeImpl implements WiredNode { private @Nullable Set receivers; final WiredElement element; - Map peripherals = Collections.emptyMap(); + Map peripherals = Map.of(); final HashSet neighbours = new HashSet<>(); volatile WiredNetworkImpl network; diff --git a/projects/common/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/CableBlock.java b/projects/common/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/CableBlock.java index 0a51bbc8b..fe6a67453 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/CableBlock.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/CableBlock.java @@ -4,12 +4,12 @@ package dan200.computercraft.shared.peripheral.modem.wired; -import com.google.common.collect.ImmutableMap; import dan200.computercraft.annotations.ForgeOverride; import dan200.computercraft.shared.ModRegistry; import dan200.computercraft.shared.platform.PlatformHelper; import dan200.computercraft.shared.util.WaterloggableHelpers; import dan200.computercraft.shared.util.WorldUtil; +import net.minecraft.Util; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.server.level.ServerLevel; @@ -52,12 +52,14 @@ public class CableBlock extends Block implements SimpleWaterloggedBlock, EntityB public static final BooleanProperty UP = BooleanProperty.create("up"); public static final BooleanProperty DOWN = BooleanProperty.create("down"); - static final EnumMap CONNECTIONS = - new EnumMap<>(new ImmutableMap.Builder() - .put(Direction.DOWN, DOWN).put(Direction.UP, UP) - .put(Direction.NORTH, NORTH).put(Direction.SOUTH, SOUTH) - .put(Direction.WEST, WEST).put(Direction.EAST, EAST) - .build()); + static final EnumMap CONNECTIONS = Util.make(new EnumMap<>(Direction.class), m -> { + m.put(Direction.DOWN, DOWN); + m.put(Direction.UP, UP); + m.put(Direction.NORTH, NORTH); + m.put(Direction.SOUTH, SOUTH); + m.put(Direction.WEST, WEST); + m.put(Direction.EAST, EAST); + }); public CableBlock(Properties settings) { super(settings); 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 f0083418f..4584e76df 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 @@ -4,7 +4,6 @@ package dan200.computercraft.shared.peripheral.modem.wired; -import com.google.common.base.Objects; import dan200.computercraft.api.network.wired.WiredElement; import dan200.computercraft.api.network.wired.WiredNode; import dan200.computercraft.api.peripheral.IPeripheral; @@ -32,6 +31,7 @@ import net.minecraft.world.phys.Vec3; import javax.annotation.Nullable; import java.util.Collections; +import java.util.Objects; public class CableBlockEntity extends BlockEntity { private static final String NBT_PERIPHERAL_ENABLED = "PeripheralAccess"; @@ -181,7 +181,7 @@ public class CableBlockEntity extends BlockEntity { var oldName = peripheral.getConnectedName(); togglePeripheralAccess(); var newName = peripheral.getConnectedName(); - if (!Objects.equal(newName, oldName)) { + if (!Objects.equals(newName, oldName)) { if (oldName != null) { player.displayClientMessage(Component.translatable("chat.computercraft.wired_modem.peripheral_disconnected", ChatHelpers.copy(oldName)), false); diff --git a/projects/common/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/CableShapes.java b/projects/common/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/CableShapes.java index 10f35e32e..d1d21160d 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/CableShapes.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/CableShapes.java @@ -4,9 +4,9 @@ package dan200.computercraft.shared.peripheral.modem.wired; -import com.google.common.collect.ImmutableMap; import dan200.computercraft.shared.peripheral.modem.ModemShapes; import dan200.computercraft.shared.util.DirectionUtil; +import net.minecraft.Util; import net.minecraft.core.Direction; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.shapes.Shapes; @@ -21,16 +21,14 @@ public final class CableShapes { private static final double MAX = 1 - MIN; private static final VoxelShape SHAPE_CABLE_CORE = Shapes.box(MIN, MIN, MIN, MAX, MAX, MAX); - private static final EnumMap SHAPE_CABLE_ARM = - new EnumMap<>(new ImmutableMap.Builder() - .put(Direction.DOWN, Shapes.box(MIN, 0, MIN, MAX, MIN, MAX)) - .put(Direction.UP, Shapes.box(MIN, MAX, MIN, MAX, 1, MAX)) - .put(Direction.NORTH, Shapes.box(MIN, MIN, 0, MAX, MAX, MIN)) - .put(Direction.SOUTH, Shapes.box(MIN, MIN, MAX, MAX, MAX, 1)) - .put(Direction.WEST, Shapes.box(0, MIN, MIN, MIN, MAX, MAX)) - .put(Direction.EAST, Shapes.box(MAX, MIN, MIN, 1, MAX, MAX)) - .build() - ); + private static final EnumMap SHAPE_CABLE_ARM = Util.make(new EnumMap<>(Direction.class), m -> { + m.put(Direction.DOWN, Shapes.box(MIN, 0, MIN, MAX, MIN, MAX)); + m.put(Direction.UP, Shapes.box(MIN, MAX, MIN, MAX, 1, MAX)); + m.put(Direction.NORTH, Shapes.box(MIN, MIN, 0, MAX, MAX, MIN)); + m.put(Direction.SOUTH, Shapes.box(MIN, MIN, MAX, MAX, MAX, 1)); + m.put(Direction.WEST, Shapes.box(0, MIN, MIN, MIN, MAX, MAX)); + m.put(Direction.EAST, Shapes.box(MAX, MIN, MIN, 1, MAX, MAX)); + }); private static final VoxelShape[] SHAPES = new VoxelShape[(1 << 6) * 7]; private static final VoxelShape[] CABLE_SHAPES = new VoxelShape[1 << 6]; 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 a219e7f39..dca62cd74 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 @@ -4,7 +4,6 @@ package dan200.computercraft.shared.peripheral.modem.wired; -import com.google.common.base.Objects; import dan200.computercraft.api.network.wired.WiredElement; import dan200.computercraft.api.network.wired.WiredNode; import dan200.computercraft.api.peripheral.IPeripheral; @@ -133,7 +132,7 @@ public class WiredModemFullBlockEntity extends BlockEntity { togglePeripheralAccess(); var periphNames = getConnectedPeripheralNames(); - if (!Objects.equal(periphNames, oldPeriphNames)) { + if (!Objects.equals(periphNames, oldPeriphNames)) { sendPeripheralChanges(player, "chat.computercraft.wired_modem.peripheral_disconnected", oldPeriphNames); sendPeripheralChanges(player, "chat.computercraft.wired_modem.peripheral_connected", periphNames); } 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 8e0a6f8bb..ee8719f91 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 @@ -4,7 +4,6 @@ package dan200.computercraft.shared.peripheral.modem.wired; -import com.google.common.collect.ImmutableMap; import dan200.computercraft.api.filesystem.Mount; import dan200.computercraft.api.filesystem.WritableMount; import dan200.computercraft.api.lua.*; @@ -429,7 +428,7 @@ public abstract class WiredModemPeripheral extends ModemPeripheral implements Wi public Map getAvailablePeripherals() { if (!attached) throw new NotAttachedException(); synchronized (element.getRemotePeripherals()) { - return ImmutableMap.copyOf(element.getRemotePeripherals()); + return Map.copyOf(element.getRemotePeripherals()); } } diff --git a/projects/common/src/main/java/dan200/computercraft/shared/pocket/items/PocketComputerItem.java b/projects/common/src/main/java/dan200/computercraft/shared/pocket/items/PocketComputerItem.java index 25a976e81..c35265e42 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/pocket/items/PocketComputerItem.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/pocket/items/PocketComputerItem.java @@ -4,7 +4,6 @@ package dan200.computercraft.shared.pocket.items; -import com.google.common.base.Objects; import dan200.computercraft.annotations.ForgeOverride; import dan200.computercraft.api.ComputerCraftAPI; import dan200.computercraft.api.filesystem.Mount; @@ -44,6 +43,7 @@ import net.minecraft.world.level.Level; import javax.annotation.Nullable; import java.util.List; +import java.util.Objects; public class PocketComputerItem extends Item implements IComputerItem, IMedia, IColouredItem { private static final String NBT_UPGRADE = "Upgrade"; @@ -97,7 +97,7 @@ public class PocketComputerItem extends Item implements IComputerItem, IMedia, I // Sync label var label = computer.getLabel(); - if (!Objects.equal(label, getLabel(stack))) { + if (!Objects.equals(label, getLabel(stack))) { changed = true; setLabel(stack, label); } diff --git a/projects/common/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java b/projects/common/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java index 23e5cc977..1b5728ed2 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java @@ -4,7 +4,6 @@ package dan200.computercraft.shared.turtle.core; -import com.google.common.base.Objects; import com.mojang.authlib.GameProfile; import dan200.computercraft.api.lua.ILuaCallback; import dan200.computercraft.api.lua.MethodResult; @@ -455,7 +454,7 @@ public class TurtleBrain implements TurtleAccessInternal { } public void setOverlay(@Nullable ResourceLocation overlay) { - if (!Objects.equal(this.overlay, overlay)) { + if (!Objects.equals(this.overlay, overlay)) { this.overlay = overlay; BlockEntityHelpers.updateBlock(owner); } @@ -573,7 +572,7 @@ public class TurtleBrain implements TurtleAccessInternal { public float getToolRenderAngle(TurtleSide side, float f) { return (side == TurtleSide.LEFT && animation == TurtleAnimation.SWING_LEFT_TOOL) || - (side == TurtleSide.RIGHT && animation == TurtleAnimation.SWING_RIGHT_TOOL) + (side == TurtleSide.RIGHT && animation == TurtleAnimation.SWING_RIGHT_TOOL) ? 45.0f * (float) Math.sin(getAnimationFraction(f) * Math.PI) : 0.0f; } diff --git a/projects/common/src/test/java/dan200/computercraft/impl/network/wired/NetworkTest.java b/projects/common/src/test/java/dan200/computercraft/impl/network/wired/NetworkTest.java index 3a6f39276..090a5d1b1 100644 --- a/projects/common/src/test/java/dan200/computercraft/impl/network/wired/NetworkTest.java +++ b/projects/common/src/test/java/dan200/computercraft/impl/network/wired/NetworkTest.java @@ -4,8 +4,6 @@ package dan200.computercraft.impl.network.wired; -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; import dan200.computercraft.api.network.wired.WiredElement; import dan200.computercraft.api.network.wired.WiredNetwork; import dan200.computercraft.api.network.wired.WiredNetworkChange; @@ -19,6 +17,7 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import javax.annotation.Nullable; +import java.util.HashMap; import java.util.Map; import java.util.Set; import java.util.function.BiConsumer; @@ -47,24 +46,24 @@ public class NetworkTest { assertFalse(aN.getNetwork().connect(aN, bN), "Cannot add connection twice"); assertEquals(aN.getNetwork(), bN.getNetwork(), "A's and B's network must be equal"); - assertEquals(Sets.newHashSet(aN, bN), nodes(aN.getNetwork()), "A's network should be A and B"); + assertEquals(Set.of(aN, bN), nodes(aN.getNetwork()), "A's network should be A and B"); - assertEquals(Sets.newHashSet("a", "b"), aE.allPeripherals().keySet(), "A's peripheral set should be A, B"); - assertEquals(Sets.newHashSet("a", "b"), bE.allPeripherals().keySet(), "B's peripheral set should be A, B"); + assertEquals(Set.of("a", "b"), aE.allPeripherals().keySet(), "A's peripheral set should be A, B"); + assertEquals(Set.of("a", "b"), bE.allPeripherals().keySet(), "B's peripheral set should be A, B"); aN.getNetwork().connect(aN, cN); assertEquals(aN.getNetwork(), bN.getNetwork(), "A's and B's network must be equal"); assertEquals(aN.getNetwork(), cN.getNetwork(), "A's and C's network must be equal"); - assertEquals(Sets.newHashSet(aN, bN, cN), nodes(aN.getNetwork()), "A's network should be A, B and C"); + assertEquals(Set.of(aN, bN, cN), nodes(aN.getNetwork()), "A's network should be A, B and C"); - assertEquals(Sets.newHashSet(bN, cN), neighbours(aN), "A's neighbour set should be B, C"); - assertEquals(Sets.newHashSet(aN), neighbours(bN), "B's neighbour set should be A"); - assertEquals(Sets.newHashSet(aN), neighbours(cN), "C's neighbour set should be A"); + assertEquals(Set.of(bN, cN), neighbours(aN), "A's neighbour set should be B, C"); + assertEquals(Set.of(aN), neighbours(bN), "B's neighbour set should be A"); + assertEquals(Set.of(aN), neighbours(cN), "C's neighbour set should be A"); - assertEquals(Sets.newHashSet("a", "b", "c"), aE.allPeripherals().keySet(), "A's peripheral set should be A, B, C"); - assertEquals(Sets.newHashSet("a", "b", "c"), bE.allPeripherals().keySet(), "B's peripheral set should be A, B, C"); - assertEquals(Sets.newHashSet("a", "b", "c"), cE.allPeripherals().keySet(), "C's peripheral set should be A, B, C"); + assertEquals(Set.of("a", "b", "c"), aE.allPeripherals().keySet(), "A's peripheral set should be A, B, C"); + assertEquals(Set.of("a", "b", "c"), bE.allPeripherals().keySet(), "B's peripheral set should be A, B, C"); + assertEquals(Set.of("a", "b", "c"), cE.allPeripherals().keySet(), "C's peripheral set should be A, B, C"); } @Test @@ -87,11 +86,11 @@ public class NetworkTest { assertEquals(aN.getNetwork(), bN.getNetwork(), "A's and B's network must be equal"); assertEquals(aN.getNetwork(), cN.getNetwork(), "A's and C's network must be equal"); - assertEquals(Sets.newHashSet(aN, bN, cN), nodes(aN.getNetwork()), "A's network should be A, B and C"); + assertEquals(Set.of(aN, bN, cN), nodes(aN.getNetwork()), "A's network should be A, B and C"); - assertEquals(Sets.newHashSet("a", "b", "c"), aE.allPeripherals().keySet(), "A's peripheral set should be A, B, C"); - assertEquals(Sets.newHashSet("a", "b", "c"), bE.allPeripherals().keySet(), "B's peripheral set should be A, B, C"); - assertEquals(Sets.newHashSet("a", "b", "c"), cE.allPeripherals().keySet(), "C's peripheral set should be A, B, C"); + assertEquals(Set.of("a", "b", "c"), aE.allPeripherals().keySet(), "A's peripheral set should be A, B, C"); + assertEquals(Set.of("a", "b", "c"), bE.allPeripherals().keySet(), "B's peripheral set should be A, B, C"); + assertEquals(Set.of("a", "b", "c"), cE.allPeripherals().keySet(), "C's peripheral set should be A, B, C"); } @Test @@ -113,12 +112,12 @@ public class NetworkTest { assertNotEquals(aN.getNetwork(), bN.getNetwork(), "A's and B's network must not be equal"); assertEquals(aN.getNetwork(), cN.getNetwork(), "A's and C's network must be equal"); - assertEquals(Sets.newHashSet(aN, cN), nodes(aN.getNetwork()), "A's network should be A and C"); - assertEquals(Sets.newHashSet(bN), nodes(bN.getNetwork()), "B's network should be B"); + assertEquals(Set.of(aN, cN), nodes(aN.getNetwork()), "A's network should be A and C"); + assertEquals(Set.of(bN), nodes(bN.getNetwork()), "B's network should be B"); - assertEquals(Sets.newHashSet("a", "c"), aE.allPeripherals().keySet(), "A's peripheral set should be A, C"); - assertEquals(Sets.newHashSet("b"), bE.allPeripherals().keySet(), "B's peripheral set should be B"); - assertEquals(Sets.newHashSet("a", "c"), cE.allPeripherals().keySet(), "C's peripheral set should be A, C"); + assertEquals(Set.of("a", "c"), aE.allPeripherals().keySet(), "A's peripheral set should be A, C"); + assertEquals(Set.of("b"), bE.allPeripherals().keySet(), "B's peripheral set should be B"); + assertEquals(Set.of("a", "c"), cE.allPeripherals().keySet(), "C's peripheral set should be A, C"); } @Test @@ -146,11 +145,11 @@ public class NetworkTest { assertEquals(aN.getNetwork(), aaN.getNetwork(), "A's and A_'s network must be equal"); assertEquals(bN.getNetwork(), bbN.getNetwork(), "B's and B_'s network must be equal"); - assertEquals(Sets.newHashSet(aN, aaN), nodes(aN.getNetwork()), "A's network should be A and A_"); - assertEquals(Sets.newHashSet(bN, bbN), nodes(bN.getNetwork()), "B's network should be B and B_"); + assertEquals(Set.of(aN, aaN), nodes(aN.getNetwork()), "A's network should be A and A_"); + assertEquals(Set.of(bN, bbN), nodes(bN.getNetwork()), "B's network should be B and B_"); - assertEquals(Sets.newHashSet("a", "a_"), aE.allPeripherals().keySet(), "A's peripheral set should be A and A_"); - assertEquals(Sets.newHashSet("b", "b_"), bE.allPeripherals().keySet(), "B's peripheral set should be B and B_"); + assertEquals(Set.of("a", "a_"), aE.allPeripherals().keySet(), "A's peripheral set should be A and A_"); + assertEquals(Set.of("b", "b_"), bE.allPeripherals().keySet(), "B's peripheral set should be B and B_"); } @Test @@ -184,12 +183,12 @@ public class NetworkTest { assertNotEquals(aN.getNetwork(), bN.getNetwork(), "A's and B's network must not be equal"); assertEquals(aN.getNetwork(), cN.getNetwork(), "A's and C's network must be equal"); - assertEquals(Sets.newHashSet(aN, cN), nodes(aN.getNetwork()), "A's network should be A and C"); - assertEquals(Sets.newHashSet(bN), nodes(bN.getNetwork()), "B's network should be B"); + assertEquals(Set.of(aN, cN), nodes(aN.getNetwork()), "A's network should be A and C"); + assertEquals(Set.of(bN), nodes(bN.getNetwork()), "B's network should be B"); - assertEquals(Sets.newHashSet("a", "c"), aE.allPeripherals().keySet(), "A's peripheral set should be A, C"); - assertEquals(Sets.newHashSet(), bE.allPeripherals().keySet(), "B's peripheral set should be empty"); - assertEquals(Sets.newHashSet("a", "c"), cE.allPeripherals().keySet(), "C's peripheral set should be A, C"); + assertEquals(Set.of("a", "c"), aE.allPeripherals().keySet(), "A's peripheral set should be A, C"); + assertEquals(Set.of(), bE.allPeripherals().keySet(), "B's peripheral set should be empty"); + assertEquals(Set.of("a", "c"), cE.allPeripherals().keySet(), "C's peripheral set should be A, C"); } @Test @@ -220,13 +219,13 @@ public class NetworkTest { assertEquals(aN.getNetwork(), aaN.getNetwork(), "A's and A_'s network must be equal"); assertEquals(bN.getNetwork(), bbN.getNetwork(), "B's and B_'s network must be equal"); - assertEquals(Sets.newHashSet(aN, aaN), nodes(aN.getNetwork()), "A's network should be A and A_"); - assertEquals(Sets.newHashSet(bN, bbN), nodes(bN.getNetwork()), "B's network should be B and B_"); - assertEquals(Sets.newHashSet(cN), nodes(cN.getNetwork()), "C's network should be C"); + assertEquals(Set.of(aN, aaN), nodes(aN.getNetwork()), "A's network should be A and A_"); + assertEquals(Set.of(bN, bbN), nodes(bN.getNetwork()), "B's network should be B and B_"); + assertEquals(Set.of(cN), nodes(cN.getNetwork()), "C's network should be C"); - assertEquals(Sets.newHashSet("a", "a_"), aE.allPeripherals().keySet(), "A's peripheral set should be A and A_"); - assertEquals(Sets.newHashSet("b", "b_"), bE.allPeripherals().keySet(), "B's peripheral set should be B and B_"); - assertEquals(Sets.newHashSet(), cE.allPeripherals().keySet(), "C's peripheral set should be empty"); + assertEquals(Set.of("a", "a_"), aE.allPeripherals().keySet(), "A's peripheral set should be A and A_"); + assertEquals(Set.of("b", "b_"), bE.allPeripherals().keySet(), "B's peripheral set should be B and B_"); + assertEquals(Set.of(), cE.allPeripherals().keySet(), "C's peripheral set should be empty"); } private static final int BRUTE_SIZE = 16; @@ -300,8 +299,8 @@ public class NetworkTest { private final Vec3 position; private final String id; private final WiredNode node; - private final Map localPeripherals = Maps.newHashMap(); - private final Map remotePeripherals = Maps.newHashMap(); + private final Map localPeripherals = new HashMap<>(); + private final Map remotePeripherals = new HashMap<>(); private NetworkElement(Level world, Vec3 position, String id) { this.world = world; diff --git a/projects/common/src/testMod/kotlin/dan200/computercraft/gametest/core/ManagedComputers.kt b/projects/common/src/testMod/kotlin/dan200/computercraft/gametest/core/ManagedComputers.kt index b4e1f6abb..05a06ee4f 100644 --- a/projects/common/src/testMod/kotlin/dan200/computercraft/gametest/core/ManagedComputers.kt +++ b/projects/common/src/testMod/kotlin/dan200/computercraft/gametest/core/ManagedComputers.kt @@ -17,7 +17,7 @@ import net.minecraft.gametest.framework.GameTestAssertException import net.minecraft.gametest.framework.GameTestAssertPosException import net.minecraft.gametest.framework.GameTestInfo import net.minecraft.gametest.framework.GameTestSequence -import org.apache.logging.log4j.LogManager +import org.slf4j.LoggerFactory import java.io.InputStream import java.util.* import java.util.concurrent.CancellationException @@ -33,7 +33,7 @@ import java.util.concurrent.atomic.AtomicReference * @see GameTestSequence.thenOnComputer */ object ManagedComputers : ILuaMachine.Factory { - private val LOGGER = LogManager.getLogger(ManagedComputers::class.java) + private val LOGGER = LoggerFactory.getLogger(ManagedComputers::class.java) private val computers: MutableMap Unit>> = mutableMapOf() internal fun enqueue(test: GameTestInfo, label: String, task: suspend LuaTaskContext.() -> Unit): Monitor { diff --git a/projects/core/src/main/java/dan200/computercraft/core/apis/http/websocket/WebsocketHandle.java b/projects/core/src/main/java/dan200/computercraft/core/apis/http/websocket/WebsocketHandle.java index ab4932d5c..7e4f18d85 100644 --- a/projects/core/src/main/java/dan200/computercraft/core/apis/http/websocket/WebsocketHandle.java +++ b/projects/core/src/main/java/dan200/computercraft/core/apis/http/websocket/WebsocketHandle.java @@ -4,12 +4,12 @@ package dan200.computercraft.core.apis.http.websocket; -import com.google.common.base.Objects; import dan200.computercraft.api.lua.*; import dan200.computercraft.core.apis.IAPIEnvironment; import dan200.computercraft.core.apis.http.options.Options; import java.util.Arrays; +import java.util.Objects; import java.util.Optional; import static dan200.computercraft.api.lua.LuaValues.checkFinite; @@ -106,12 +106,12 @@ public class WebsocketHandle { @Override public MethodResult resume(Object[] event) { - if (event.length >= 3 && Objects.equal(event[0], MESSAGE_EVENT) && Objects.equal(event[1], address)) { + if (event.length >= 3 && Objects.equals(event[0], MESSAGE_EVENT) && Objects.equals(event[1], address)) { return MethodResult.of(Arrays.copyOfRange(event, 2, event.length)); - } else if (event.length >= 2 && Objects.equal(event[0], CLOSE_EVENT) && Objects.equal(event[1], address) && websocket.isClosed()) { + } else if (event.length >= 2 && Objects.equals(event[0], CLOSE_EVENT) && Objects.equals(event[1], address) && websocket.isClosed()) { // If the socket is closed abort. return MethodResult.of(); - } else if (event.length >= 2 && timeoutId != -1 && Objects.equal(event[0], TIMER_EVENT) + } else if (event.length >= 2 && timeoutId != -1 && Objects.equals(event[0], TIMER_EVENT) && event[1] instanceof Number id && id.intValue() == timeoutId) { // If we received a matching timer event then abort. return MethodResult.of(); diff --git a/projects/core/src/main/java/dan200/computercraft/core/computer/Computer.java b/projects/core/src/main/java/dan200/computercraft/core/computer/Computer.java index b96a8223a..fb285a67e 100644 --- a/projects/core/src/main/java/dan200/computercraft/core/computer/Computer.java +++ b/projects/core/src/main/java/dan200/computercraft/core/computer/Computer.java @@ -4,7 +4,6 @@ package dan200.computercraft.core.computer; -import com.google.common.base.Objects; import dan200.computercraft.api.lua.ILuaAPI; import dan200.computercraft.api.lua.ILuaContext; import dan200.computercraft.api.lua.LuaTask; @@ -16,6 +15,7 @@ import dan200.computercraft.core.filesystem.FileSystem; import dan200.computercraft.core.terminal.Terminal; import javax.annotation.Nullable; +import java.util.Objects; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicLong; @@ -140,7 +140,7 @@ public class Computer { } public void setLabel(@Nullable String label) { - if (!Objects.equal(label, this.label)) { + if (!Objects.equals(label, this.label)) { this.label = label; externalOutputChanged.set(true); } diff --git a/projects/core/src/main/java/dan200/computercraft/core/filesystem/WritableFileMount.java b/projects/core/src/main/java/dan200/computercraft/core/filesystem/WritableFileMount.java index bb7b33f91..47ac4482c 100644 --- a/projects/core/src/main/java/dan200/computercraft/core/filesystem/WritableFileMount.java +++ b/projects/core/src/main/java/dan200/computercraft/core/filesystem/WritableFileMount.java @@ -4,7 +4,6 @@ package dan200.computercraft.core.filesystem; -import com.google.common.collect.Sets; import dan200.computercraft.api.filesystem.FileOperationException; import dan200.computercraft.api.filesystem.WritableMount; import org.slf4j.Logger; @@ -28,8 +27,8 @@ public class WritableFileMount extends FileMount implements WritableMount { private static final Logger LOG = LoggerFactory.getLogger(WritableFileMount.class); static final long MINIMUM_FILE_SIZE = 500; - private static final Set WRITE_OPTIONS = Sets.newHashSet(StandardOpenOption.WRITE, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); - private static final Set APPEND_OPTIONS = Sets.newHashSet(StandardOpenOption.WRITE, StandardOpenOption.CREATE, StandardOpenOption.APPEND); + private static final Set WRITE_OPTIONS = Set.of(StandardOpenOption.WRITE, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); + private static final Set APPEND_OPTIONS = Set.of(StandardOpenOption.WRITE, StandardOpenOption.CREATE, StandardOpenOption.APPEND); protected final File rootFile; private final long capacity;