Fix ExceptionSet Ambiguity and add default TypeItemStack constructor.
This commit is contained in:
parent
5082f535e4
commit
8357b9f65e
@ -1,7 +1,5 @@
|
||||
package com.massivecraft.massivecore.collections;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.massivecraft.massivecore.comparator.ComparatorCaseInsensitive;
|
||||
|
||||
public class ExceptionSet<T>
|
||||
@ -29,47 +27,52 @@ public class ExceptionSet<T>
|
||||
this.standard = standard;
|
||||
}
|
||||
|
||||
public ExceptionSet(boolean standard, String... exceptions)
|
||||
{
|
||||
this.standard = standard;
|
||||
this.exceptions.addAll(Arrays.asList(exceptions));
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public ExceptionSet(boolean standard, T... exceptions)
|
||||
public <X extends Object> ExceptionSet(boolean standard, X... exceptions)
|
||||
{
|
||||
this.standard = standard;
|
||||
for (T exception : exceptions)
|
||||
if (exceptions.length == 0) return;
|
||||
for (Object exception : exceptions)
|
||||
{
|
||||
this.exceptions.add(convert(exception));
|
||||
String string = asString(exception);
|
||||
this.exceptions.add(string);
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONTAINS
|
||||
// AS STRING
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean containsString(String item)
|
||||
public String asString(Object exception)
|
||||
{
|
||||
if (this.exceptions.contains(item)) return ! this.standard;
|
||||
return this.standard;
|
||||
if (exception == null) return null;
|
||||
|
||||
if (exception instanceof String) return (String)exception;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
T t = (T)exception;
|
||||
return this.convert(t);
|
||||
}
|
||||
|
||||
public boolean contains(String item)
|
||||
{
|
||||
return this.containsString(item);
|
||||
}
|
||||
|
||||
public boolean contains(T item)
|
||||
{
|
||||
if (item == null) return ! this.standard;
|
||||
|
||||
return this.contains(convert(item));
|
||||
}
|
||||
// -------------------------------------------- //
|
||||
// CONVERT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public String convert(T item)
|
||||
{
|
||||
return item.toString();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONTAINS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean contains(Object object)
|
||||
{
|
||||
if (object == null) return ! this.standard;
|
||||
String string = asString(object);
|
||||
if (this.exceptions.contains(string)) return ! this.standard;
|
||||
return this.standard;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ public class TypeItemStack extends TypeAbstract<ItemStack>
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static TypeItemStack i = new TypeItemStack(new ExceptionSet<Material>(true));
|
||||
private static TypeItemStack i = new TypeItemStack();
|
||||
public static TypeItemStack get() { return i; }
|
||||
|
||||
public static TypeItemStack get(Material... materialWhitelist)
|
||||
@ -39,6 +39,11 @@ public class TypeItemStack extends TypeAbstract<ItemStack>
|
||||
this.materialsAllowed = materialsAllowed;
|
||||
}
|
||||
|
||||
public TypeItemStack()
|
||||
{
|
||||
this(new ExceptionSet<Material>(true));
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
Loading…
Reference in New Issue
Block a user