Add generic ExceptionSet.
This commit is contained in:
parent
121dc67365
commit
b66c35b000
@ -0,0 +1,51 @@
|
||||
package com.massivecraft.massivecore.collections;
|
||||
|
||||
import com.massivecraft.massivecore.CaseInsensitiveComparator;
|
||||
|
||||
public class ExceptionSet<T>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean standard = true;
|
||||
|
||||
public MassiveTreeSet<String, CaseInsensitiveComparator> exceptions = new MassiveTreeSet<String, CaseInsensitiveComparator>(CaseInsensitiveComparator.get());
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public ExceptionSet()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public ExceptionSet(boolean standard)
|
||||
{
|
||||
this.standard = standard;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONTAINS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean contains(String item)
|
||||
{
|
||||
if (this.exceptions.contains(item)) return ! this.standard;
|
||||
return this.standard;
|
||||
}
|
||||
|
||||
public boolean contains(T item)
|
||||
{
|
||||
if (item == null) return ! this.standard;
|
||||
|
||||
return this.contains(convert(item));
|
||||
}
|
||||
|
||||
public String convert(T item)
|
||||
{
|
||||
return item.toString();
|
||||
}
|
||||
|
||||
}
|
@ -4,19 +4,10 @@ import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
import com.massivecraft.massivecore.CaseInsensitiveComparator;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
|
||||
public class WorldExceptionSet
|
||||
public class WorldExceptionSet extends ExceptionSet<World>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean standard = true;
|
||||
|
||||
public MassiveTreeSet<String, CaseInsensitiveComparator> exceptions = new MassiveTreeSet<String, CaseInsensitiveComparator>(CaseInsensitiveComparator.get());
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
@ -28,17 +19,17 @@ public class WorldExceptionSet
|
||||
|
||||
public WorldExceptionSet(boolean standard)
|
||||
{
|
||||
this.standard = standard;
|
||||
super(standard);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONTAINS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean contains(String world)
|
||||
@Override
|
||||
public String convert(World world)
|
||||
{
|
||||
if (this.exceptions.contains(world)) return !this.standard;
|
||||
return this.standard;
|
||||
return world.getName();
|
||||
}
|
||||
|
||||
public boolean contains(PS ps)
|
||||
@ -46,11 +37,6 @@ public class WorldExceptionSet
|
||||
return this.contains(ps.getWorld());
|
||||
}
|
||||
|
||||
public boolean contains(World world)
|
||||
{
|
||||
return this.contains(world.getName());
|
||||
}
|
||||
|
||||
public boolean contains(Location loc)
|
||||
{
|
||||
return this.contains(loc.getWorld());
|
||||
|
Loading…
Reference in New Issue
Block a user