From 5f0470fb0b12b62337d4bcc5c222d277c4b23583 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Fri, 10 May 2019 07:42:47 -0400 Subject: [PATCH] Checkstyle, CappedCollection -> CappedSet --- .../proxy/connection/client/ConnectedPlayer.java | 14 +++++++++----- .../{CappedCollection.java => CappedSet.java} | 15 ++++++++------- ...ppedCollectionTest.java => CappedSetTest.java} | 9 ++++----- 3 files changed, 21 insertions(+), 17 deletions(-) rename proxy/src/main/java/com/velocitypowered/proxy/util/collect/{CappedCollection.java => CappedSet.java} (72%) rename proxy/src/test/java/com/velocitypowered/proxy/util/collect/{CappedCollectionTest.java => CappedSetTest.java} (86%) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java index 837217778..e77c20fd4 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java @@ -46,10 +46,14 @@ import com.velocitypowered.proxy.protocol.packet.TitlePacket; import com.velocitypowered.proxy.server.VelocityRegisteredServer; import com.velocitypowered.proxy.tablist.VelocityTabList; import com.velocitypowered.proxy.util.VelocityMessages; -import com.velocitypowered.proxy.util.collect.CappedCollection; +import com.velocitypowered.proxy.util.collect.CappedSet; import io.netty.buffer.ByteBufUtil; import java.net.InetSocketAddress; -import java.util.*; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import java.util.UUID; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; import java.util.concurrent.ThreadLocalRandom; @@ -103,7 +107,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { this.virtualHost = virtualHost; this.permissionFunction = PermissionFunction.ALWAYS_UNDEFINED; this.connectionPhase = minecraftConnection.getType().getInitialClientPhase(); - this.knownChannels = CappedCollection.newCappedSet(MAX_PLUGIN_CHANNELS); + this.knownChannels = CappedSet.newCappedSet(MAX_PLUGIN_CHANNELS); } @Override @@ -650,8 +654,8 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { * @return {@code true} if the message can be forwarded, {@code false} otherwise */ public boolean canForwardPluginMessage(PluginMessage message) { - // If we're forwarding a plugin message onto the client, that implies that we have a backend connection - // already. + // If we're forwarding a plugin message onto the client, that implies that we have a backend + // connection already. MinecraftConnection mc = ensureBackendConnection(); boolean minecraftOrFmlMessage; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/collect/CappedCollection.java b/proxy/src/main/java/com/velocitypowered/proxy/util/collect/CappedSet.java similarity index 72% rename from proxy/src/main/java/com/velocitypowered/proxy/util/collect/CappedCollection.java rename to proxy/src/main/java/com/velocitypowered/proxy/util/collect/CappedSet.java index 01645e973..eeacda6a0 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/collect/CappedCollection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/collect/CappedSet.java @@ -1,20 +1,21 @@ package com.velocitypowered.proxy.util.collect; import com.google.common.base.Preconditions; -import com.google.common.collect.ForwardingCollection; +import com.google.common.collect.ForwardingSet; import java.util.Collection; import java.util.HashSet; +import java.util.Set; /** * An unsynchronized collection that puts an upper bound on the size of the collection. */ -public class CappedCollection extends ForwardingCollection { +public class CappedSet extends ForwardingSet { - private final Collection delegate; + private final Set delegate; private final int upperSize; - private CappedCollection(Collection delegate, int upperSize) { + private CappedSet(Set delegate, int upperSize) { this.delegate = delegate; this.upperSize = upperSize; } @@ -25,12 +26,12 @@ public class CappedCollection extends ForwardingCollection { * @param the type of elements in the collection * @return the new collection */ - public static Collection newCappedSet(int maxSize) { - return new CappedCollection<>(new HashSet<>(), maxSize); + public static Set newCappedSet(int maxSize) { + return new CappedSet<>(new HashSet<>(), maxSize); } @Override - protected Collection delegate() { + protected Set delegate() { return delegate; } diff --git a/proxy/src/test/java/com/velocitypowered/proxy/util/collect/CappedCollectionTest.java b/proxy/src/test/java/com/velocitypowered/proxy/util/collect/CappedSetTest.java similarity index 86% rename from proxy/src/test/java/com/velocitypowered/proxy/util/collect/CappedCollectionTest.java rename to proxy/src/test/java/com/velocitypowered/proxy/util/collect/CappedSetTest.java index d9bcab45d..8444961d0 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/util/collect/CappedCollectionTest.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/util/collect/CappedSetTest.java @@ -2,17 +2,16 @@ package com.velocitypowered.proxy.util.collect; import static org.junit.jupiter.api.Assertions.*; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import java.util.Collection; import java.util.Set; import org.junit.jupiter.api.Test; -class CappedCollectionTest { +class CappedSetTest { @Test void basicVerification() { - Collection coll = CappedCollection.newCappedSet(1); + Collection coll = CappedSet.newCappedSet(1); assertTrue(coll.add("coffee"), "did not add single item"); assertThrows(IllegalStateException.class, () -> coll.add("tea"), "item was added to collection although it is too full"); @@ -25,7 +24,7 @@ class CappedCollectionTest { Set doesFill2 = ImmutableSet.of("chocolate"); Set overfill = ImmutableSet.of("Coke", "Pepsi"); - Collection coll = CappedCollection.newCappedSet(3); + Collection coll = CappedSet.newCappedSet(3); assertTrue(coll.addAll(doesFill1), "did not add items"); assertTrue(coll.addAll(doesFill2), "did not add items"); assertThrows(IllegalStateException.class, () -> coll.addAll(overfill), @@ -39,7 +38,7 @@ class CappedCollectionTest { Set doesFill2 = ImmutableSet.of("coffee", "chocolate"); Set overfill = ImmutableSet.of("coffee", "Coke", "Pepsi"); - Collection coll = CappedCollection.newCappedSet(3); + Collection coll = CappedSet.newCappedSet(3); assertTrue(coll.addAll(doesFill1), "did not add items"); assertTrue(coll.addAll(doesFill2), "did not add items"); assertThrows(IllegalStateException.class, () -> coll.addAll(overfill),