From 8357b9f65e169ce950b94e11e5a846fa02ae574a Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Mon, 21 Mar 2016 19:48:26 +0100 Subject: [PATCH] Fix ExceptionSet Ambiguity and add default TypeItemStack constructor. --- .../massivecore/collections/ExceptionSet.java | 55 ++++++++++--------- .../command/type/TypeItemStack.java | 7 ++- 2 files changed, 35 insertions(+), 27 deletions(-) diff --git a/src/com/massivecraft/massivecore/collections/ExceptionSet.java b/src/com/massivecraft/massivecore/collections/ExceptionSet.java index 856606d9..2e745232 100644 --- a/src/com/massivecraft/massivecore/collections/ExceptionSet.java +++ b/src/com/massivecraft/massivecore/collections/ExceptionSet.java @@ -1,7 +1,5 @@ package com.massivecraft.massivecore.collections; -import java.util.Arrays; - import com.massivecraft.massivecore.comparator.ComparatorCaseInsensitive; public class ExceptionSet @@ -29,47 +27,52 @@ public class ExceptionSet 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 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; + } + } diff --git a/src/com/massivecraft/massivecore/command/type/TypeItemStack.java b/src/com/massivecraft/massivecore/command/type/TypeItemStack.java index d40233b5..0b15a20b 100644 --- a/src/com/massivecraft/massivecore/command/type/TypeItemStack.java +++ b/src/com/massivecraft/massivecore/command/type/TypeItemStack.java @@ -25,7 +25,7 @@ public class TypeItemStack extends TypeAbstract // INSTANCE & CONSTRUCT // -------------------------------------------- // - private static TypeItemStack i = new TypeItemStack(new ExceptionSet(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 this.materialsAllowed = materialsAllowed; } + public TypeItemStack() + { + this(new ExceptionSet(true)); + } + // -------------------------------------------- // // OVERRIDE // -------------------------------------------- //