From 938efaeed404e96afa08522c6ea87c5ce73279a1 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Mon, 13 Oct 2014 08:10:18 +0200 Subject: [PATCH] Add a case insensitive treeset builder and commonly used sets of strings meaning nothing and remove. --- .../massivecraft/massivecore/MassiveCore.java | 6 ++++++ .../massivecraft/massivecore/util/MUtil.java | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/main/java/com/massivecraft/massivecore/MassiveCore.java b/src/main/java/com/massivecraft/massivecore/MassiveCore.java index 6ac9a0f1..0b28d727 100644 --- a/src/main/java/com/massivecraft/massivecore/MassiveCore.java +++ b/src/main/java/com/massivecraft/massivecore/MassiveCore.java @@ -34,6 +34,7 @@ import com.massivecraft.massivecore.store.Coll; import com.massivecraft.massivecore.store.ExamineThread; import com.massivecraft.massivecore.teleport.EngineScheduledTeleport; import com.massivecraft.massivecore.util.IdUtil; +import com.massivecraft.massivecore.util.MUtil; import com.massivecraft.massivecore.util.PlayerUtil; import com.massivecraft.massivecore.util.Txt; import com.massivecraft.massivecore.xlib.gson.Gson; @@ -52,6 +53,11 @@ public class MassiveCore extends MassivePlugin public final static String INSTANCE = "instance"; public final static String DEFAULT = "default"; + public final static Set NOTHING = MUtil.treeset("", "none", "null", "nothing"); + public final static Set REMOVE = MUtil.treeset("clear", "c", "delete", "del", "d", "erase", "e", "remove", "rem", "r", "reset", "res"); + public final static Set NOTHING_REMOVE = MUtil.treeset("", "none", "null", "nothing", "clear", "c", "delete", "del", "d", "erase", "e", "remove", "rem", "r", "reset", "res"); + + // -------------------------------------------- // // INSTANCE & CONSTRUCT // -------------------------------------------- // diff --git a/src/main/java/com/massivecraft/massivecore/util/MUtil.java b/src/main/java/com/massivecraft/massivecore/util/MUtil.java index a635ece7..84335008 100644 --- a/src/main/java/com/massivecraft/massivecore/util/MUtil.java +++ b/src/main/java/com/massivecraft/massivecore/util/MUtil.java @@ -602,6 +602,23 @@ public class MUtil return new LinkedHashSet(Arrays.asList(items)); } + @SuppressWarnings("unchecked") + @SafeVarargs + public static Set treeset(T... items) + { + Set ret; + if (items[0] instanceof String) + { + ret = (Set) new TreeSet(String.CASE_INSENSITIVE_ORDER); + } + else + { + ret = new TreeSet(); + } + ret.addAll(Arrays.asList(items)); + return ret; + } + @SuppressWarnings("unchecked") public static Map map(K key1, V value1, Object... objects) {