Migrate from trove to fastutil
This commit is contained in:
parent
cd1ceb4c31
commit
5dad41034b
@ -1,22 +1,22 @@
|
|||||||
package net.md_5.bungee.util;
|
package net.md_5.bungee.util;
|
||||||
|
|
||||||
import gnu.trove.strategy.HashingStrategy;
|
import it.unimi.dsi.fastutil.Hash;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
class CaseInsensitiveHashingStrategy implements HashingStrategy
|
class CaseInsensitiveHashingStrategy implements Hash.Strategy<String>
|
||||||
{
|
{
|
||||||
|
|
||||||
static final CaseInsensitiveHashingStrategy INSTANCE = new CaseInsensitiveHashingStrategy();
|
static final CaseInsensitiveHashingStrategy INSTANCE = new CaseInsensitiveHashingStrategy();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int computeHashCode(Object object)
|
public int hashCode(String object)
|
||||||
{
|
{
|
||||||
return ( (String) object ).toLowerCase( Locale.ROOT ).hashCode();
|
return object.toLowerCase( Locale.ROOT ).hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o1, Object o2)
|
public boolean equals(String o1, String o2)
|
||||||
{
|
{
|
||||||
return o1.equals( o2 ) || ( o1 instanceof String && o2 instanceof String && ( (String) o1 ).toLowerCase( Locale.ROOT ).equals( ( (String) o2 ).toLowerCase( Locale.ROOT ) ) );
|
return o1.equals( o2 ) || ( o1 instanceof String && o2 instanceof String && o1.toLowerCase( Locale.ROOT ).equals( o2.toLowerCase( Locale.ROOT ) ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package net.md_5.bungee.util;
|
package net.md_5.bungee.util;
|
||||||
|
|
||||||
import gnu.trove.map.hash.TCustomHashMap;
|
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenCustomHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class CaseInsensitiveMap<V> extends TCustomHashMap<String, V>
|
public class CaseInsensitiveMap<V> extends Object2ObjectOpenCustomHashMap<String, V>
|
||||||
{
|
{
|
||||||
|
|
||||||
public CaseInsensitiveMap()
|
public CaseInsensitiveMap()
|
||||||
@ -13,6 +13,6 @@ public class CaseInsensitiveMap<V> extends TCustomHashMap<String, V>
|
|||||||
|
|
||||||
public CaseInsensitiveMap(Map<? extends String, ? extends V> map)
|
public CaseInsensitiveMap(Map<? extends String, ? extends V> map)
|
||||||
{
|
{
|
||||||
super( CaseInsensitiveHashingStrategy.INSTANCE, map );
|
super( map, CaseInsensitiveHashingStrategy.INSTANCE );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package net.md_5.bungee.util;
|
package net.md_5.bungee.util;
|
||||||
|
|
||||||
import gnu.trove.set.hash.TCustomHashSet;
|
import it.unimi.dsi.fastutil.objects.ObjectOpenCustomHashSet;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
public class CaseInsensitiveSet extends TCustomHashSet<String>
|
public class CaseInsensitiveSet extends ObjectOpenCustomHashSet<String>
|
||||||
{
|
{
|
||||||
|
|
||||||
public CaseInsensitiveSet()
|
public CaseInsensitiveSet()
|
||||||
@ -13,6 +13,6 @@ public class CaseInsensitiveSet extends TCustomHashSet<String>
|
|||||||
|
|
||||||
public CaseInsensitiveSet(Collection<? extends String> collection)
|
public CaseInsensitiveSet(Collection<? extends String> collection)
|
||||||
{
|
{
|
||||||
super( CaseInsensitiveHashingStrategy.INSTANCE, collection );
|
super( collection, CaseInsensitiveHashingStrategy.INSTANCE );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,12 +13,12 @@ public class CaseInsensitiveTest
|
|||||||
CaseInsensitiveMap<Object> map = new CaseInsensitiveMap<>();
|
CaseInsensitiveMap<Object> map = new CaseInsensitiveMap<>();
|
||||||
|
|
||||||
map.put( "FOO", obj );
|
map.put( "FOO", obj );
|
||||||
assertTrue( map.contains( "foo" ) ); // Assert that contains is case insensitive
|
assertTrue( map.containsKey( "foo" ) ); // Assert that contains is case insensitive
|
||||||
assertTrue( map.entrySet().iterator().next().getKey().equals( "FOO" ) ); // Assert that case is preserved
|
assertTrue( map.entrySet().iterator().next().getKey().equals( "FOO" ) ); // Assert that case is preserved
|
||||||
|
|
||||||
// Assert that remove is case insensitive
|
// Assert that remove is case insensitive
|
||||||
map.remove( "FoO" );
|
map.remove( "FoO" );
|
||||||
assertFalse( map.contains( "foo" ) );
|
assertFalse( map.containsKey( "foo" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -52,9 +52,9 @@
|
|||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.sf.trove4j</groupId>
|
<groupId>it.unimi.dsi</groupId>
|
||||||
<artifactId>core</artifactId>
|
<artifactId>fastutil-core</artifactId>
|
||||||
<version>3.1.0</version>
|
<version>8.5.15</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
@ -2,10 +2,10 @@ package net.md_5.bungee.protocol;
|
|||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import gnu.trove.map.TIntObjectMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
import gnu.trove.map.TObjectIntMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||||
import gnu.trove.map.hash.TIntObjectHashMap;
|
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||||
import gnu.trove.map.hash.TObjectIntHashMap;
|
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@ -922,7 +922,7 @@ public enum Protocol
|
|||||||
{
|
{
|
||||||
|
|
||||||
private final int protocolVersion;
|
private final int protocolVersion;
|
||||||
private final TObjectIntMap<Class<? extends DefinedPacket>> packetMap = new TObjectIntHashMap<>( MAX_PACKET_ID );
|
private final Object2IntMap<Class<? extends DefinedPacket>> packetMap = new Object2IntOpenHashMap<>( MAX_PACKET_ID );
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private final Supplier<? extends DefinedPacket>[] packetConstructors = new Supplier[ MAX_PACKET_ID ];
|
private final Supplier<? extends DefinedPacket>[] packetConstructors = new Supplier[ MAX_PACKET_ID ];
|
||||||
}
|
}
|
||||||
@ -944,7 +944,7 @@ public enum Protocol
|
|||||||
public static final class DirectionData
|
public static final class DirectionData
|
||||||
{
|
{
|
||||||
|
|
||||||
private final TIntObjectMap<ProtocolData> protocols = new TIntObjectHashMap<>();
|
private final Int2ObjectMap<ProtocolData> protocols = new Int2ObjectOpenHashMap<>();
|
||||||
//
|
//
|
||||||
private final Protocol protocolPhase;
|
private final Protocol protocolPhase;
|
||||||
@Getter
|
@Getter
|
||||||
@ -966,7 +966,7 @@ public enum Protocol
|
|||||||
ProtocolData protocol = protocols.get( version );
|
ProtocolData protocol = protocols.get( version );
|
||||||
if ( protocol == null && ( protocolPhase != Protocol.GAME ) )
|
if ( protocol == null && ( protocolPhase != Protocol.GAME ) )
|
||||||
{
|
{
|
||||||
protocol = Iterables.getFirst( protocols.valueCollection(), null );
|
protocol = Iterables.getFirst( protocols.values(), null );
|
||||||
}
|
}
|
||||||
return protocol;
|
return protocol;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package net.md_5.bungee.conf;
|
package net.md_5.bungee.conf;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import gnu.trove.map.TMap;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -42,7 +41,7 @@ public class Configuration implements ProxyConfig
|
|||||||
/**
|
/**
|
||||||
* Set of all servers.
|
* Set of all servers.
|
||||||
*/
|
*/
|
||||||
private TMap<String, ServerInfo> servers;
|
private Map<String, ServerInfo> servers;
|
||||||
/**
|
/**
|
||||||
* Should we check minecraft.net auth.
|
* Should we check minecraft.net auth.
|
||||||
*/
|
*/
|
||||||
|
@ -4,9 +4,9 @@ import com.google.common.base.Preconditions;
|
|||||||
import com.google.common.collect.HashMultimap;
|
import com.google.common.collect.HashMultimap;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
import com.google.common.collect.Multimaps;
|
import com.google.common.collect.Multimaps;
|
||||||
import gnu.trove.TCollections;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
import gnu.trove.map.TIntObjectMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMaps;
|
||||||
import gnu.trove.map.hash.TIntObjectHashMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
@ -21,7 +21,7 @@ public class BungeeScheduler implements TaskScheduler
|
|||||||
|
|
||||||
private final Object lock = new Object();
|
private final Object lock = new Object();
|
||||||
private final AtomicInteger taskCounter = new AtomicInteger();
|
private final AtomicInteger taskCounter = new AtomicInteger();
|
||||||
private final TIntObjectMap<BungeeTask> tasks = TCollections.synchronizedMap( new TIntObjectHashMap<BungeeTask>() );
|
private final Int2ObjectMap<BungeeTask> tasks = Int2ObjectMaps.synchronize( new Int2ObjectOpenHashMap<>() );
|
||||||
private final Multimap<Plugin, BungeeTask> tasksByPlugin = Multimaps.synchronizedMultimap( HashMultimap.<Plugin, BungeeTask>create() );
|
private final Multimap<Plugin, BungeeTask> tasksByPlugin = Multimaps.synchronizedMultimap( HashMultimap.<Plugin, BungeeTask>create() );
|
||||||
//
|
//
|
||||||
private final Unsafe unsafe = new Unsafe()
|
private final Unsafe unsafe = new Unsafe()
|
||||||
|
Loading…
Reference in New Issue
Block a user