3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-17 05:20:14 +01:00

Checkstyle, CappedCollection -> CappedSet

Dieser Commit ist enthalten in:
Andrew Steinborn 2019-05-10 07:42:47 -04:00
Ursprung 74afcee9ba
Commit 5f0470fb0b
3 geänderte Dateien mit 21 neuen und 17 gelöschten Zeilen

Datei anzeigen

@ -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;

Datei anzeigen

@ -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<T> extends ForwardingCollection<T> {
public class CappedSet<T> extends ForwardingSet<T> {
private final Collection<T> delegate;
private final Set<T> delegate;
private final int upperSize;
private CappedCollection(Collection<T> delegate, int upperSize) {
private CappedSet(Set<T> delegate, int upperSize) {
this.delegate = delegate;
this.upperSize = upperSize;
}
@ -25,12 +26,12 @@ public class CappedCollection<T> extends ForwardingCollection<T> {
* @param <T> the type of elements in the collection
* @return the new collection
*/
public static <T> Collection<T> newCappedSet(int maxSize) {
return new CappedCollection<>(new HashSet<>(), maxSize);
public static <T> Set<T> newCappedSet(int maxSize) {
return new CappedSet<>(new HashSet<>(), maxSize);
}
@Override
protected Collection<T> delegate() {
protected Set<T> delegate() {
return delegate;
}

Datei anzeigen

@ -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<String> coll = CappedCollection.newCappedSet(1);
Collection<String> 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<String> doesFill2 = ImmutableSet.of("chocolate");
Set<String> overfill = ImmutableSet.of("Coke", "Pepsi");
Collection<String> coll = CappedCollection.newCappedSet(3);
Collection<String> 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<String> doesFill2 = ImmutableSet.of("coffee", "chocolate");
Set<String> overfill = ImmutableSet.of("coffee", "Coke", "Pepsi");
Collection<String> coll = CappedCollection.newCappedSet(3);
Collection<String> 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),