Make perms case insensitive - need to write unit test still

This commit is contained in:
md_5 2013-05-24 14:44:40 +10:00
parent 185dc97ca6
commit 7eac22d362
5 changed files with 50 additions and 20 deletions

View File

@ -36,6 +36,7 @@ import net.md_5.bungee.packet.Packet9Respawn;
import net.md_5.bungee.packet.PacketCCSettings; import net.md_5.bungee.packet.PacketCCSettings;
import net.md_5.bungee.packet.PacketFAPluginMessage; import net.md_5.bungee.packet.PacketFAPluginMessage;
import net.md_5.bungee.packet.PacketFFKick; import net.md_5.bungee.packet.PacketFFKick;
import net.md_5.bungee.util.CaseInsensitiveSet;
@RequiredArgsConstructor @RequiredArgsConstructor
public final class UserConnection implements ProxiedPlayer public final class UserConnection implements ProxiedPlayer
@ -72,8 +73,8 @@ public final class UserConnection implements ProxiedPlayer
@Setter @Setter
private int ping = 100; private int ping = 100;
/*========================================================================*/ /*========================================================================*/
private final Collection<String> groups = new HashSet<>(); private final Collection<String> groups = new CaseInsensitiveSet();
private final Collection<String> permissions = new HashSet<>(); private final Collection<String> permissions = new CaseInsensitiveSet();
/*========================================================================*/ /*========================================================================*/
@Getter @Getter
private int clientEntityId; private int clientEntityId;

View File

@ -0,0 +1,21 @@
package net.md_5.bungee.util;
import gnu.trove.strategy.HashingStrategy;
class CaseInsensitiveHashingStrategy implements HashingStrategy<String>
{
static final CaseInsensitiveHashingStrategy INSTANCE = new CaseInsensitiveHashingStrategy();
@Override
public int computeHashCode(String object)
{
return object.toLowerCase().hashCode();
}
@Override
public boolean equals(String o1, String o2)
{
return o1.toLowerCase().equals( o2.toLowerCase() );
}
}

View File

@ -1,34 +1,18 @@
package net.md_5.bungee.util; package net.md_5.bungee.util;
import gnu.trove.map.hash.TCustomHashMap; import gnu.trove.map.hash.TCustomHashMap;
import gnu.trove.strategy.HashingStrategy;
import java.util.Map; import java.util.Map;
public class CaseInsensitiveMap<V> extends TCustomHashMap<String, V> public class CaseInsensitiveMap<V> extends TCustomHashMap<String, V>
{ {
private static final HashingStrategy<String> hashingStrategy = new HashingStrategy<String>()
{
@Override
public int computeHashCode(String object)
{
return object.toLowerCase().hashCode();
}
@Override
public boolean equals(String o1, String o2)
{
return o1.toLowerCase().equals( o2.toLowerCase() );
}
};
public CaseInsensitiveMap() public CaseInsensitiveMap()
{ {
super( hashingStrategy ); super( CaseInsensitiveHashingStrategy.INSTANCE );
} }
public CaseInsensitiveMap(Map<? extends String, ? extends V> map) public CaseInsensitiveMap(Map<? extends String, ? extends V> map)
{ {
super( hashingStrategy, map ); super( CaseInsensitiveHashingStrategy.INSTANCE, map );
} }
} }

View File

@ -0,0 +1,18 @@
package net.md_5.bungee.util;
import gnu.trove.set.hash.TCustomHashSet;
import java.util.Collection;
public class CaseInsensitiveSet extends TCustomHashSet<String>
{
public CaseInsensitiveSet()
{
super( CaseInsensitiveHashingStrategy.INSTANCE );
}
public CaseInsensitiveSet(Collection<? extends String> collection)
{
super( CaseInsensitiveHashingStrategy.INSTANCE, collection );
}
}

View File

@ -16,4 +16,10 @@ public class CaseInsensitiveTest
Assert.assertTrue( map.contains( "foo" ) ); // Assert that it is case insensitive Assert.assertTrue( map.contains( "foo" ) ); // Assert that it is case insensitive
Assert.assertTrue( map.entrySet().iterator().next().getKey().equals( "FOO" ) ); // Asert that case is preserved Assert.assertTrue( map.entrySet().iterator().next().getKey().equals( "FOO" ) ); // Asert that case is preserved
} }
@Test
public void testSets()
{
throw new UnsupportedOperationException( "Need a unit test!!!" );
}
} }