diff --git a/src/com/massivecraft/massivecore/CaseInsensitiveComparator.java b/src/com/massivecraft/massivecore/CaseInsensitiveComparator.java deleted file mode 100644 index 3715dbb7..00000000 --- a/src/com/massivecraft/massivecore/CaseInsensitiveComparator.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.massivecraft.massivecore; - -import java.util.Comparator; - -public class CaseInsensitiveComparator implements Comparator -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static CaseInsensitiveComparator i = new CaseInsensitiveComparator(); - public static CaseInsensitiveComparator get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public int compare(String o1, String o2) - { - return String.CASE_INSENSITIVE_ORDER.compare(o1, o2); - } - -} diff --git a/src/com/massivecraft/massivecore/HashCodeComparator.java b/src/com/massivecraft/massivecore/HashCodeComparator.java deleted file mode 100644 index 31f88d85..00000000 --- a/src/com/massivecraft/massivecore/HashCodeComparator.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.massivecraft.massivecore; - -import java.util.*; - -public class HashCodeComparator implements Comparator -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static transient HashCodeComparator i = new HashCodeComparator(); - public static HashCodeComparator get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public int compare(Object o1, Object o2) - { - return o2.hashCode() - o1.hashCode(); - } - -} diff --git a/src/com/massivecraft/massivecore/PriorityComparator.java b/src/com/massivecraft/massivecore/PriorityComparator.java deleted file mode 100644 index 40f8c859..00000000 --- a/src/com/massivecraft/massivecore/PriorityComparator.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.massivecraft.massivecore; - -import java.util.Comparator; - -import com.massivecraft.massivecore.store.ComparatorEntityId; -import com.massivecraft.massivecore.store.Entity; - -public class PriorityComparator implements Comparator -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static PriorityComparator i = new PriorityComparator(); - public static PriorityComparator get() { return i; } - - // -------------------------------------------- // - // OVERRIDE: COMPARATOR - // -------------------------------------------- // - - @Override - public int compare(Prioritized p1, Prioritized p2) - { - // Null - if (p1 == null && p2 == null) return 0; - if (p1 == null) return -1; - if (p2 == null) return +1; - - // Equals - if (p1.equals(p2)) return 0; - - // Priority - int ret = Integer.compare(p1.getPriority(), p2.getPriority()); - if (ret != 0) return ret; - - // Entity Id - if (p1 instanceof Entity && p2 instanceof Entity) - { - Entity e1 = (Entity)p1; - Entity e2 = (Entity)p2; - return ComparatorEntityId.get().compare(e1, e2); - } - - // We should only return 0 if the items actually are equal. - return p2.hashCode() - p1.hashCode(); - } - -} diff --git a/src/com/massivecraft/massivecore/PriorityLines.java b/src/com/massivecraft/massivecore/PriorityLines.java index 56daba25..98311f5f 100644 --- a/src/com/massivecraft/massivecore/PriorityLines.java +++ b/src/com/massivecraft/massivecore/PriorityLines.java @@ -5,6 +5,7 @@ import java.util.Collections; import java.util.LinkedList; import java.util.List; +import com.massivecraft.massivecore.comparator.ComparatorHashCode; import com.massivecraft.massivecore.util.MUtil; public class PriorityLines implements Prioritized, Comparable @@ -66,7 +67,7 @@ public class PriorityLines implements Prioritized, Comparable if (ret != 0) return ret; if (MUtil.equals(this.lines, that.lines)) return 0; - ret = HashCodeComparator.get().compare(this.lines, that.lines); + ret = ComparatorHashCode.get().compare(this.lines, that.lines); if (ret != 0) return ret; return ret; diff --git a/src/com/massivecraft/massivecore/ReversePriorityComparator.java b/src/com/massivecraft/massivecore/ReversePriorityComparator.java deleted file mode 100644 index 23eaf904..00000000 --- a/src/com/massivecraft/massivecore/ReversePriorityComparator.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.massivecraft.massivecore; - -import java.util.Comparator; - -public class ReversePriorityComparator implements Comparator -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static ReversePriorityComparator i = new ReversePriorityComparator(); - public static ReversePriorityComparator get() { return i; } - - // -------------------------------------------- // - // OVERRIDE: COMPARATOR - // -------------------------------------------- // - - @Override - public int compare(Prioritized one, Prioritized two) - { - if (one == null && two == null) return 0; - if (two == null) return -1; - if (one == null) return 1; - - int ret = Integer.valueOf(two.getPriority()).compareTo(one.getPriority()); - - // We should only return 0 if the items actually are equal. - if (ret == 0 && ! one.equals(two)) - { - ret = one.hashCode() - two.hashCode(); - } - - return ret; - } - -} diff --git a/src/com/massivecraft/massivecore/collections/ExceptionSet.java b/src/com/massivecraft/massivecore/collections/ExceptionSet.java index e4d7a6b4..1f98a3b5 100644 --- a/src/com/massivecraft/massivecore/collections/ExceptionSet.java +++ b/src/com/massivecraft/massivecore/collections/ExceptionSet.java @@ -2,7 +2,7 @@ package com.massivecraft.massivecore.collections; import java.util.Arrays; -import com.massivecraft.massivecore.CaseInsensitiveComparator; +import com.massivecraft.massivecore.comparator.ComparatorCaseInsensitive; public class ExceptionSet { @@ -13,7 +13,7 @@ public class ExceptionSet public boolean standard = true; public boolean isStandard() { return this.standard; } - public MassiveTreeSet exceptions = new MassiveTreeSet(CaseInsensitiveComparator.get()); + public MassiveTreeSet exceptions = new MassiveTreeSet(ComparatorCaseInsensitive.get()); // -------------------------------------------- // // CONSTRUCT diff --git a/src/com/massivecraft/massivecore/command/MassiveCommand.java b/src/com/massivecraft/massivecore/command/MassiveCommand.java index fb317d83..b9caee1a 100644 --- a/src/com/massivecraft/massivecore/command/MassiveCommand.java +++ b/src/com/massivecraft/massivecore/command/MassiveCommand.java @@ -19,7 +19,6 @@ import org.bukkit.plugin.Plugin; import com.massivecraft.massivecore.Lang; import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.PredicateStartsWithIgnoreCase; import com.massivecraft.massivecore.collections.MassiveList; import com.massivecraft.massivecore.collections.MassiveMap; import com.massivecraft.massivecore.command.requirement.Requirement; @@ -27,6 +26,7 @@ import com.massivecraft.massivecore.command.requirement.RequirementHasPerm; import com.massivecraft.massivecore.command.type.Type; import com.massivecraft.massivecore.mixin.Mixin; import com.massivecraft.massivecore.mson.Mson; +import com.massivecraft.massivecore.predicate.PredicateStartsWithIgnoreCase; import com.massivecraft.massivecore.util.PermUtil; import com.massivecraft.massivecore.util.Txt; diff --git a/src/com/massivecraft/massivecore/command/editor/CommandEditAbstract.java b/src/com/massivecraft/massivecore/command/editor/CommandEditAbstract.java index b3e46e65..99bcc852 100644 --- a/src/com/massivecraft/massivecore/command/editor/CommandEditAbstract.java +++ b/src/com/massivecraft/massivecore/command/editor/CommandEditAbstract.java @@ -12,7 +12,6 @@ import com.massivecraft.massivecore.command.requirement.RequirementEditorUse; import com.massivecraft.massivecore.command.requirement.RequirementHasPerm; import com.massivecraft.massivecore.command.type.Type; import com.massivecraft.massivecore.event.EventMassiveCoreEditorEdit; -import com.massivecraft.massivecore.util.MUtil; import com.massivecraft.massivecore.util.PermUtil; public class CommandEditAbstract extends MassiveCommand @@ -109,7 +108,7 @@ public class CommandEditAbstract extends MassiveCommand // NoChange // We check, inform and cancel on equality. - if (MUtil.equals(before, after)) + if (this.getValueType().equals(before, after, true)) { msg("%s for %s already: %s", descProperty, descObject, descValue); return; diff --git a/src/com/massivecraft/massivecore/command/editor/CommandEditCollection.java b/src/com/massivecraft/massivecore/command/editor/CommandEditCollection.java deleted file mode 100644 index e51e3b8d..00000000 --- a/src/com/massivecraft/massivecore/command/editor/CommandEditCollection.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.massivecraft.massivecore.command.editor; - -import java.util.Collection; - -public class CommandEditCollection> extends CommandEditAbstract -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CommandEditCollection(EditSettings settings, Property property) - { - // Super - super(settings, property, null); - - // Children - this.addChild(new CommandEditShow(settings, property)); - - if (property.isNullable()) - { - this.addChild(new CommandEditCreate(settings, property)); - this.addChild(new CommandEditDelete(settings, property)); - } - - this.addChild(new CommandEditCollectionAdd(settings, property)); - this.addChild(new CommandEditCollectionInsert(settings, property)); - this.addChild(new CommandEditCollectionSet(settings, property)); - this.addChild(new CommandEditCollectionRemove(settings, property)); - this.addChild(new CommandEditCollectionMove(settings, property)); - this.addChild(new CommandEditCollectionSwap(settings, property)); - this.addChild(new CommandEditCollectionClear(settings, property)); - } - -} diff --git a/src/com/massivecraft/massivecore/command/editor/CommandEditCollectionAbstract.java b/src/com/massivecraft/massivecore/command/editor/CommandEditCollectionAbstract.java deleted file mode 100644 index f7783a94..00000000 --- a/src/com/massivecraft/massivecore/command/editor/CommandEditCollectionAbstract.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.massivecraft.massivecore.command.editor; - -import java.util.Collection; -import java.util.List; - -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.collections.MassiveList; -import com.massivecraft.massivecore.command.requirement.RequirementEditorPropertyCreated; - -public abstract class CommandEditCollectionAbstract> extends CommandEditAbstract -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CommandEditCollectionAbstract(EditSettings settings, Property property) - { - // Super - super(settings, property, true); - - // Aliases - String alias = this.createCommandAlias(); - this.setAliases(alias); - - // Desc - this.setDesc(alias + " " + this.getPropertyName()); - - // Requirements - this.addRequirements(RequirementEditorPropertyCreated.get(true)); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @SuppressWarnings("unchecked") - @Override - public void perform() throws MassiveException - { - // Create - List after = this.getShallowCopy(); - - // Alter - try - { - this.alter(after); - } - catch (MassiveException e) - { - throw e; - } - catch (Exception e) - { - throw new MassiveException().addMsg("%s", e.getMessage()); - } - - // Apply - Collection toSet = null; - if (after != null) - { - toSet = (Collection) this.getProperty().getValueType().createNewInstance(); - toSet.addAll(after); - } - - this.attemptSet((V) toSet); - } - - // -------------------------------------------- // - // ABSTRACT - // -------------------------------------------- // - - public abstract void alter(List list) throws MassiveException; - - // -------------------------------------------- // - // UTIL - // -------------------------------------------- // - - public List getShallowCopy() - { - V ret = this.getProperty().getRaw(this.getObject()); - if (ret == null) return null; - return new MassiveList(ret); - } - -} diff --git a/src/com/massivecraft/massivecore/command/editor/CommandEditContainer.java b/src/com/massivecraft/massivecore/command/editor/CommandEditContainer.java new file mode 100644 index 00000000..7cfc117e --- /dev/null +++ b/src/com/massivecraft/massivecore/command/editor/CommandEditContainer.java @@ -0,0 +1,38 @@ +package com.massivecraft.massivecore.command.editor; + +public class CommandEditContainer extends CommandEditAbstract +{ + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CommandEditContainer(EditSettings settings, Property property) + { + // Super + super(settings, property, null); + + // Children + this.addChild(new CommandEditShow(settings, property)); + + if (property.isNullable()) + { + this.addChild(new CommandEditCreate(settings, property)); + this.addChild(new CommandEditDelete(settings, property)); + } + + this.addChild(new CommandEditContainerAdd(settings, property)); + this.addChild(new CommandEditContainerInsert(settings, property)); + this.addChild(new CommandEditContainerSet(settings, property)); + this.addChild(new CommandEditContainerRemove(settings, property)); + this.addChild(new CommandEditContainerRemoveIndex(settings, property)); + + if ( ! property.getValueType().isContainerSorted() && property.getValueType().getContainerComparator() == null) + { + this.addChild(new CommandEditContainerMove(settings, property)); + this.addChild(new CommandEditContainerSwap(settings, property)); + } + + this.addChild(new CommandEditContainerClear(settings, property)); + } + +} diff --git a/src/com/massivecraft/massivecore/command/editor/CommandEditContainerAbstract.java b/src/com/massivecraft/massivecore/command/editor/CommandEditContainerAbstract.java new file mode 100644 index 00000000..31cf3f0d --- /dev/null +++ b/src/com/massivecraft/massivecore/command/editor/CommandEditContainerAbstract.java @@ -0,0 +1,143 @@ +package com.massivecraft.massivecore.command.editor; + +import java.util.List; +import java.util.AbstractMap.SimpleEntry; + +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.requirement.RequirementEditorPropertyCreated; +import com.massivecraft.massivecore.command.type.Type; +import com.massivecraft.massivecore.command.type.TypeNullable; + +public abstract class CommandEditContainerAbstract extends CommandEditAbstract +{ + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CommandEditContainerAbstract(EditSettings settings, Property property) + { + // Super + super(settings, property, true); + + // Aliases + String alias = this.createCommandAlias(); + this.setAliases(alias); + + // Desc + this.setDesc(alias + " " + this.getPropertyName()); + + // Requirements + this.addRequirements(RequirementEditorPropertyCreated.get(true)); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException + { + // Type + + // Create + V container = this.getProperty().getRaw(this.getObject()); + List elements = this.getValueType().getContainerElementsOrdered(container); + + // Alter + try + { + this.alter(elements); + } + catch (MassiveException e) + { + throw e; + } + catch (Exception e) + { + throw new MassiveException().addMsg("%s", e.getMessage()); + } + + // After + V after = this.getValueType().createNewInstance(); + this.getValueType().addContainerElements(after, elements); + + // Order + elements = this.getValueType().getContainerElementsOrdered(after); + this.getValueType().setContainerElements(after, elements); + + // Apply + this.attemptSet(after); + } + + // -------------------------------------------- // + // ABSTRACT + // -------------------------------------------- // + + public abstract void alter(List elements) throws MassiveException; + + // -------------------------------------------- // + // MAP + // -------------------------------------------- // + + public boolean isCollection() + { + Type type = this.getValueType(); + if (type.isContainerCollection()) + { + return true; + } + else if (type.isContainerMap()) + { + return false; + } + else + { + throw new RuntimeException("Neither Collection nor Map."); + } + } + + public void addParametersElement(boolean strict) + { + Type type = this.getValueType(); + Type innerType = type.getInnerType(); + + if (type.isContainerCollection()) + { + this.addParameter(innerType, innerType.getTypeName(), true); + } + else if (type.isContainerMap()) + { + Type keyType = innerType.getInnerType(0); + Type valueType = innerType.getInnerType(1); + if (strict) + { + this.addParameter(keyType, keyType.getTypeName()); + this.addParameter(valueType, valueType.getTypeName()); + } + else + { + this.addParameter(null, TypeNullable.get(keyType, "any", "all"), keyType.getTypeName(), "any"); + this.addParameter(null, TypeNullable.get(valueType, "any", "all"), valueType.getTypeName(), "any"); + } + } + else + { + throw new RuntimeException("Neither Collection nor Map."); + } + } + + public Object readElement() throws MassiveException + { + if (this.isCollection()) + { + return this.readArg(); + } + else + { + Object key = this.readArg(); + Object value = this.readArg(); + return new SimpleEntry(key, value); + } + } + +} diff --git a/src/com/massivecraft/massivecore/command/editor/CommandEditCollectionAdd.java b/src/com/massivecraft/massivecore/command/editor/CommandEditContainerAdd.java similarity index 52% rename from src/com/massivecraft/massivecore/command/editor/CommandEditCollectionAdd.java rename to src/com/massivecraft/massivecore/command/editor/CommandEditContainerAdd.java index 172b744c..dad9edf9 100644 --- a/src/com/massivecraft/massivecore/command/editor/CommandEditCollectionAdd.java +++ b/src/com/massivecraft/massivecore/command/editor/CommandEditContainerAdd.java @@ -1,23 +1,25 @@ package com.massivecraft.massivecore.command.editor; -import java.util.Collection; import java.util.List; import com.massivecraft.massivecore.MassiveException; -public class CommandEditCollectionAdd> extends CommandEditCollectionAbstract +public class CommandEditContainerAdd extends CommandEditContainerAbstract { // -------------------------------------------- // // CONSTRUCT // -------------------------------------------- // - public CommandEditCollectionAdd(EditSettings settings, Property property) + public CommandEditContainerAdd(EditSettings settings, Property property) { - // Super + // Super super(settings, property); + // Aliases + this.setAliases("add", "put"); + // Parameters - this.addParameter(this.getValueInnerType(), this.getProperty().getName(), true); + this.addParametersElement(true); } // -------------------------------------------- // @@ -25,13 +27,13 @@ public class CommandEditCollectionAdd> extends Comman // -------------------------------------------- // @Override - public void alter(List list) throws MassiveException + public void alter(List elements) throws MassiveException { // Args - Object element = this.readArg(); + Object element = this.readElement(); // Alter - list.add(element); + elements.add(element); } } diff --git a/src/com/massivecraft/massivecore/command/editor/CommandEditCollectionClear.java b/src/com/massivecraft/massivecore/command/editor/CommandEditContainerClear.java similarity index 59% rename from src/com/massivecraft/massivecore/command/editor/CommandEditCollectionClear.java rename to src/com/massivecraft/massivecore/command/editor/CommandEditContainerClear.java index b2bc1048..417b4814 100644 --- a/src/com/massivecraft/massivecore/command/editor/CommandEditCollectionClear.java +++ b/src/com/massivecraft/massivecore/command/editor/CommandEditContainerClear.java @@ -1,20 +1,22 @@ package com.massivecraft.massivecore.command.editor; -import java.util.Collection; import java.util.List; import com.massivecraft.massivecore.MassiveException; -public class CommandEditCollectionClear> extends CommandEditCollectionAbstract +public class CommandEditContainerClear extends CommandEditContainerAbstract { // -------------------------------------------- // // CONSTRUCT // -------------------------------------------- // - public CommandEditCollectionClear(EditSettings settings, Property property) + public CommandEditContainerClear(EditSettings settings, Property property) { // Super super(settings, property); + + // Aliases + this.setAliases("clear"); } // -------------------------------------------- // @@ -22,10 +24,10 @@ public class CommandEditCollectionClear> extends Comm // -------------------------------------------- // @Override - public void alter(List list) throws MassiveException + public void alter(List elements) throws MassiveException { // Apply - list.clear(); + elements.clear(); } } diff --git a/src/com/massivecraft/massivecore/command/editor/CommandEditCollectionSet.java b/src/com/massivecraft/massivecore/command/editor/CommandEditContainerInsert.java similarity index 59% rename from src/com/massivecraft/massivecore/command/editor/CommandEditCollectionSet.java rename to src/com/massivecraft/massivecore/command/editor/CommandEditContainerInsert.java index 043e8555..d9bdbe4f 100644 --- a/src/com/massivecraft/massivecore/command/editor/CommandEditCollectionSet.java +++ b/src/com/massivecraft/massivecore/command/editor/CommandEditContainerInsert.java @@ -1,25 +1,27 @@ package com.massivecraft.massivecore.command.editor; -import java.util.Collection; import java.util.List; import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.command.type.primitive.TypeInteger; -public class CommandEditCollectionSet> extends CommandEditCollectionAbstract +public class CommandEditContainerInsert extends CommandEditContainerAbstract { // -------------------------------------------- // // CONSTRUCT // -------------------------------------------- // - public CommandEditCollectionSet(EditSettings settings, Property property) + public CommandEditContainerInsert(EditSettings settings, Property property) { // Super super(settings, property); + // Aliases + this.setAliases("insert"); + // Parameters this.addParameter(TypeInteger.get(), "index"); - this.addParameter(this.getValueInnerType(), this.getProperty().getName(), true); + this.addParametersElement(true); } // -------------------------------------------- // @@ -27,14 +29,14 @@ public class CommandEditCollectionSet> extends Comman // -------------------------------------------- // @Override - public void alter(List list) throws MassiveException + public void alter(List elements) throws MassiveException { // Args int index = this.readArg(); - Object element = this.readArg(); + Object element = this.readElement(); // Alter - list.set(index, element); + elements.add(index, element); } } diff --git a/src/com/massivecraft/massivecore/command/editor/CommandEditCollectionMove.java b/src/com/massivecraft/massivecore/command/editor/CommandEditContainerMove.java similarity index 66% rename from src/com/massivecraft/massivecore/command/editor/CommandEditCollectionMove.java rename to src/com/massivecraft/massivecore/command/editor/CommandEditContainerMove.java index 78999a9d..03918887 100644 --- a/src/com/massivecraft/massivecore/command/editor/CommandEditCollectionMove.java +++ b/src/com/massivecraft/massivecore/command/editor/CommandEditContainerMove.java @@ -1,22 +1,24 @@ package com.massivecraft.massivecore.command.editor; -import java.util.Collection; import java.util.List; import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.command.type.primitive.TypeInteger; -public class CommandEditCollectionMove> extends CommandEditCollectionAbstract +public class CommandEditContainerMove extends CommandEditContainerAbstract { // -------------------------------------------- // // CONSTRUCT // -------------------------------------------- // - public CommandEditCollectionMove(EditSettings settings, Property property) + public CommandEditContainerMove(EditSettings settings, Property property) { // Super super(settings, property); + // Aliases + this.setAliases("move"); + // Parameters this.addParameter(TypeInteger.get(), "indexFrom"); this.addParameter(TypeInteger.get(), "indexTo"); @@ -27,15 +29,15 @@ public class CommandEditCollectionMove> extends Comma // -------------------------------------------- // @Override - public void alter(List list) throws MassiveException + public void alter(List elements) throws MassiveException { // Args int indexFrom = this.readArg(); int indexTo = this.readArg(); // Alter - Object element = list.remove(indexFrom); - list.add(indexTo, element); + Object element = elements.remove(indexFrom); + elements.add(indexTo, element); } } diff --git a/src/com/massivecraft/massivecore/command/editor/CommandEditContainerRemove.java b/src/com/massivecraft/massivecore/command/editor/CommandEditContainerRemove.java new file mode 100644 index 00000000..4cddbc7e --- /dev/null +++ b/src/com/massivecraft/massivecore/command/editor/CommandEditContainerRemove.java @@ -0,0 +1,91 @@ +package com.massivecraft.massivecore.command.editor; + +import java.util.Iterator; +import java.util.List; +import java.util.Map.Entry; + +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.util.MUtil; + +public class CommandEditContainerRemove extends CommandEditContainerAbstract +{ + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CommandEditContainerRemove(EditSettings settings, Property property) + { + // Super + super(settings, property); + + // Aliases + this.setAliases("remove"); + + // Parameters + this.addParametersElement(false); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void alter(List elements) throws MassiveException + { + if (this.isCollection()) + { + this.alterCollection(elements); + } + else + { + this.alterMap(elements); + } + } + + // -------------------------------------------- // + // OVERRIDE > COLLECTION + // -------------------------------------------- // + + public void alterCollection(List elements) throws MassiveException + { + // Args + Object element = this.readElement(); + + // Alter + Iterator iterator = elements.iterator(); + while (iterator.hasNext()) + { + Object other = iterator.hasNext(); + if ( ! this.getValueInnerType().equals(other, element, false)) continue; + iterator.remove(); + } + } + + // -------------------------------------------- // + // OVERRIDE > MAP + // -------------------------------------------- // + + @SuppressWarnings("unchecked") + public void alterMap(List elements) throws MassiveException + { + // Args + Object key = this.readArg(); + Object value = this.readArg(); + + // Validate + if (key == null && value == null) throw new MassiveException().addMsg("Please supply key and/or value."); + + // Alter + Iterator iterator = elements.iterator(); + while (iterator.hasNext()) + { + Entry other = (Entry) iterator.next(); + + if (key != null && ! MUtil.equals(key, other.getKey())) continue; + if (value != null && ! MUtil.equals(value, other.getValue())) continue; + + iterator.remove(); + } + } + +} diff --git a/src/com/massivecraft/massivecore/command/editor/CommandEditCollectionRemove.java b/src/com/massivecraft/massivecore/command/editor/CommandEditContainerRemoveIndex.java similarity index 66% rename from src/com/massivecraft/massivecore/command/editor/CommandEditCollectionRemove.java rename to src/com/massivecraft/massivecore/command/editor/CommandEditContainerRemoveIndex.java index aa2bcb7c..39e6823e 100644 --- a/src/com/massivecraft/massivecore/command/editor/CommandEditCollectionRemove.java +++ b/src/com/massivecraft/massivecore/command/editor/CommandEditContainerRemoveIndex.java @@ -1,22 +1,24 @@ package com.massivecraft.massivecore.command.editor; -import java.util.Collection; import java.util.List; import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.command.type.primitive.TypeInteger; -public class CommandEditCollectionRemove> extends CommandEditCollectionAbstract +public class CommandEditContainerRemoveIndex extends CommandEditContainerAbstract { // -------------------------------------------- // // CONSTRUCT // -------------------------------------------- // - public CommandEditCollectionRemove(EditSettings settings, Property property) + public CommandEditContainerRemoveIndex(EditSettings settings, Property property) { // Super super(settings, property); + // Aliases + this.setAliases("removeIndex"); + // Parameters this.addParameter(TypeInteger.get(), "index"); } @@ -26,13 +28,13 @@ public class CommandEditCollectionRemove> extends Com // -------------------------------------------- // @Override - public void alter(List list) throws MassiveException + public void alter(List elements) throws MassiveException { // Args int index = this.readArg(); // Alter - list.remove(index); + elements.remove(index); } } diff --git a/src/com/massivecraft/massivecore/command/editor/CommandEditCollectionInsert.java b/src/com/massivecraft/massivecore/command/editor/CommandEditContainerSet.java similarity index 59% rename from src/com/massivecraft/massivecore/command/editor/CommandEditCollectionInsert.java rename to src/com/massivecraft/massivecore/command/editor/CommandEditContainerSet.java index c4349c1c..f9718f22 100644 --- a/src/com/massivecraft/massivecore/command/editor/CommandEditCollectionInsert.java +++ b/src/com/massivecraft/massivecore/command/editor/CommandEditContainerSet.java @@ -1,25 +1,27 @@ package com.massivecraft.massivecore.command.editor; -import java.util.Collection; import java.util.List; import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.command.type.primitive.TypeInteger; -public class CommandEditCollectionInsert> extends CommandEditCollectionAbstract +public class CommandEditContainerSet extends CommandEditContainerAbstract { // -------------------------------------------- // // CONSTRUCT // -------------------------------------------- // - public CommandEditCollectionInsert(EditSettings settings, Property property) + public CommandEditContainerSet(EditSettings settings, Property property) { // Super super(settings, property); + // Aliases + this.setAliases("set"); + // Parameters this.addParameter(TypeInteger.get(), "index"); - this.addParameter(this.getValueInnerType(), this.getProperty().getName(), true); + this.addParametersElement(true); } // -------------------------------------------- // @@ -27,14 +29,14 @@ public class CommandEditCollectionInsert> extends Com // -------------------------------------------- // @Override - public void alter(List list) throws MassiveException + public void alter(List elements) throws MassiveException { // Args int index = this.readArg(); - Object element = this.readArg(); + Object element = this.readElement(); // Alter - list.add(index, element); + elements.set(index, element); } } diff --git a/src/com/massivecraft/massivecore/command/editor/CommandEditCollectionSwap.java b/src/com/massivecraft/massivecore/command/editor/CommandEditContainerSwap.java similarity index 61% rename from src/com/massivecraft/massivecore/command/editor/CommandEditCollectionSwap.java rename to src/com/massivecraft/massivecore/command/editor/CommandEditContainerSwap.java index e36949d3..40fb4421 100644 --- a/src/com/massivecraft/massivecore/command/editor/CommandEditCollectionSwap.java +++ b/src/com/massivecraft/massivecore/command/editor/CommandEditContainerSwap.java @@ -1,22 +1,24 @@ package com.massivecraft.massivecore.command.editor; -import java.util.Collection; import java.util.List; import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.command.type.primitive.TypeInteger; -public class CommandEditCollectionSwap> extends CommandEditCollectionAbstract +public class CommandEditContainerSwap extends CommandEditContainerAbstract { // -------------------------------------------- // // CONSTRUCT // -------------------------------------------- // - public CommandEditCollectionSwap(EditSettings settings, Property property) + public CommandEditContainerSwap(EditSettings settings, Property property) { // Super super(settings, property); + // Aliases + this.setAliases("swap"); + // Parameters this.addParameter(TypeInteger.get(), "indexOne"); this.addParameter(TypeInteger.get(), "indexTwo"); @@ -27,17 +29,17 @@ public class CommandEditCollectionSwap> extends Comma // -------------------------------------------- // @Override - public void alter(List list) throws MassiveException + public void alter(List elements) throws MassiveException { // Args int indexOne = this.readArg(); int indexTwo = this.readArg(); // Alter - Object one = list.get(indexOne); - Object two = list.get(indexTwo); - list.set(indexOne, two); - list.set(indexTwo, one); + Object elementOne = elements.get(indexOne); + Object elementTwo = elements.get(indexTwo); + elements.set(indexOne, elementTwo); + elements.set(indexTwo, elementOne); } } diff --git a/src/com/massivecraft/massivecore/command/editor/CommandEditMap.java b/src/com/massivecraft/massivecore/command/editor/CommandEditMap.java deleted file mode 100644 index 1d76a6f1..00000000 --- a/src/com/massivecraft/massivecore/command/editor/CommandEditMap.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.massivecraft.massivecore.command.editor; - -import java.util.Map; - -public class CommandEditMap> extends CommandEditAbstract -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CommandEditMap(EditSettings settings, Property property) - { - // Super - super(settings, property, null); - - // Children - this.addChild(new CommandEditShow(settings, property)); - - if (property.isNullable()) - { - this.addChild(new CommandEditCreate(settings, property)); - this.addChild(new CommandEditDelete(settings, property)); - } - - this.addChild(new CommandEditMapPut(settings, property)); - this.addChild(new CommandEditMapRemove(settings, property)); - this.addChild(new CommandEditMapClear(settings, property)); - } - -} diff --git a/src/com/massivecraft/massivecore/command/editor/CommandEditMapAbstract.java b/src/com/massivecraft/massivecore/command/editor/CommandEditMapAbstract.java deleted file mode 100644 index b2f6b721..00000000 --- a/src/com/massivecraft/massivecore/command/editor/CommandEditMapAbstract.java +++ /dev/null @@ -1,103 +0,0 @@ -package com.massivecraft.massivecore.command.editor; - -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.requirement.RequirementEditorPropertyCreated; -import com.massivecraft.massivecore.command.type.Type; - -import java.util.Map; - -public abstract class CommandEditMapAbstract> extends CommandEditAbstract -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CommandEditMapAbstract(EditSettings settings, Property property) - { - // Super - super(settings, property, true); - - // Aliases - String alias = this.createCommandAlias(); - this.setAliases(alias); - - // Desc - this.setDesc(alias + " " + this.getPropertyName()); - - // Requirements - this.addRequirements(RequirementEditorPropertyCreated.get(true)); - } - - // -------------------------------------------- // - // SHORTCUTS > PROPERTY > TYPE - // -------------------------------------------- // - - // Only to be used with map type properties. - public Type getMapKeyType() - { - return this.getProperty().getValueType().getInnerType(0); - } - - public Type getMapValueType() - { - return this.getProperty().getValueType().getInnerType(1); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @SuppressWarnings("unchecked") - @Override - public void perform() throws MassiveException - { - // Create - Map after = this.getShallowCopy(); - - // Alter - try - { - this.alter(after); - } - catch (MassiveException e) - { - throw e; - } - catch (Exception e) - { - throw new MassiveException().addMsg("%s", e.getMessage()); - } - - // Apply - this.attemptSet((V) after); - } - - // -------------------------------------------- // - // ABSTRACT - // -------------------------------------------- // - - public abstract void alter(Map map) throws MassiveException; - - // -------------------------------------------- // - // UTIL - // -------------------------------------------- // - - @SuppressWarnings("unchecked") - public Map getShallowCopy() - { - // Create - V ret = this.getProperty().getRaw(this.getObject()); - if (ret == null) return null; - - // Fill - Map copy = (Map) this.getProperty().getValueType().createNewInstance(); - for (Map.Entry entry : ((Map) ret).entrySet()) - { - copy.put(entry.getKey(), entry.getValue()); - } - - // Return - return copy; - } - -} diff --git a/src/com/massivecraft/massivecore/command/editor/CommandEditMapClear.java b/src/com/massivecraft/massivecore/command/editor/CommandEditMapClear.java deleted file mode 100644 index d4037bf4..00000000 --- a/src/com/massivecraft/massivecore/command/editor/CommandEditMapClear.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.massivecraft.massivecore.command.editor; - -import com.massivecraft.massivecore.MassiveException; - -import java.util.Map; - -public class CommandEditMapClear> extends CommandEditMapAbstract -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CommandEditMapClear(EditSettings settings, Property property) - { - // Super - super(settings, property); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void alter(Map map) throws MassiveException - { - // Alter - map.clear(); - } - -} diff --git a/src/com/massivecraft/massivecore/command/editor/CommandEditMapPut.java b/src/com/massivecraft/massivecore/command/editor/CommandEditMapPut.java deleted file mode 100644 index 49371663..00000000 --- a/src/com/massivecraft/massivecore/command/editor/CommandEditMapPut.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.massivecraft.massivecore.command.editor; - -import com.massivecraft.massivecore.MassiveException; - -import java.util.Map; - -public class CommandEditMapPut> extends CommandEditMapAbstract -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CommandEditMapPut(EditSettings settings, Property property) - { - // Super - super(settings, property); - - // Parameters - this.addParameter(this.getMapKeyType(), this.getMapKeyType().getTypeName()); - this.addParameter(this.getMapValueType(), this.getMapValueType().getTypeName()); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void alter(Map map) throws MassiveException - { - // Args - Object key = this.readArg(); - Object value = this.readArg(); - - // Alter - map.put(key, value); - } - -} diff --git a/src/com/massivecraft/massivecore/command/editor/CommandEditMapRemove.java b/src/com/massivecraft/massivecore/command/editor/CommandEditMapRemove.java deleted file mode 100644 index e8ef98c1..00000000 --- a/src/com/massivecraft/massivecore/command/editor/CommandEditMapRemove.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.massivecraft.massivecore.command.editor; - -import com.massivecraft.massivecore.MassiveException; - -import java.util.Map; - -public class CommandEditMapRemove> extends CommandEditMapAbstract -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CommandEditMapRemove(EditSettings settings, Property property) - { - // Super - super(settings, property); - - // Parameters - this.addParameter(this.getMapKeyType(), this.getMapKeyType().getTypeName(), true); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void alter(Map map) throws MassiveException - { - // Args - Object key = this.readArg(); - - // Alter - map.remove(key); - } - -} diff --git a/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreHearsound.java b/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreHearsound.java index 3ae36ee1..39fa44d1 100644 --- a/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreHearsound.java +++ b/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreHearsound.java @@ -8,8 +8,8 @@ import com.massivecraft.massivecore.SoundEffect; import com.massivecraft.massivecore.command.MassiveCommand; import com.massivecraft.massivecore.command.requirement.RequirementHasPerm; import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer; -import com.massivecraft.massivecore.command.type.collection.TypeList; import com.massivecraft.massivecore.command.type.combined.TypeSoundEffect; +import com.massivecraft.massivecore.command.type.container.TypeList; public class CmdMassiveCoreHearsound extends MassiveCommand { diff --git a/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreStoreListcolls.java b/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreStoreListcolls.java index 6c3cd2c7..11c72486 100644 --- a/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreStoreListcolls.java +++ b/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreStoreListcolls.java @@ -6,10 +6,10 @@ import java.util.TreeSet; import com.massivecraft.massivecore.ConfServer; import com.massivecraft.massivecore.MassiveCorePerm; import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.NaturalOrderComparator; import com.massivecraft.massivecore.command.MassiveCommand; import com.massivecraft.massivecore.command.requirement.RequirementHasPerm; import com.massivecraft.massivecore.command.type.primitive.TypeString; +import com.massivecraft.massivecore.comparator.ComparatorNaturalOrder; import com.massivecraft.massivecore.store.Coll; import com.massivecraft.massivecore.store.Db; import com.massivecraft.massivecore.store.MStore; @@ -50,7 +50,7 @@ public class CmdMassiveCoreStoreListcolls extends MassiveCommand } // Prepare - Set collnames = new TreeSet(NaturalOrderComparator.get()); + Set collnames = new TreeSet(ComparatorNaturalOrder.get()); collnames.addAll(db.getCollnames()); // Do it! diff --git a/src/com/massivecraft/massivecore/command/requirement/Requirement.java b/src/com/massivecraft/massivecore/command/requirement/Requirement.java index e31b7f10..8e07ec6e 100644 --- a/src/com/massivecraft/massivecore/command/requirement/Requirement.java +++ b/src/com/massivecraft/massivecore/command/requirement/Requirement.java @@ -2,8 +2,8 @@ package com.massivecraft.massivecore.command.requirement; import org.bukkit.command.CommandSender; -import com.massivecraft.massivecore.Predicate; import com.massivecraft.massivecore.command.MassiveCommand; +import com.massivecraft.massivecore.predicate.Predicate; public interface Requirement extends Predicate { diff --git a/src/com/massivecraft/massivecore/command/type/Type.java b/src/com/massivecraft/massivecore/command/type/Type.java index c7e27bac..13ba87ac 100644 --- a/src/com/massivecraft/massivecore/command/type/Type.java +++ b/src/com/massivecraft/massivecore/command/type/Type.java @@ -1,9 +1,9 @@ package com.massivecraft.massivecore.command.type; import java.util.Collection; +import java.util.Comparator; import java.util.List; import java.util.Set; - import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; @@ -25,9 +25,9 @@ public interface Type // INNER // -------------------------------------------- // - public , X extends Object> List getInnerTypes(); - public Type getInnerType(int index); - public Type getInnerType(); + public > List getInnerTypes(); + public > I getInnerType(int index); + public > I getInnerType(); public void setInnerTypes(Collection> innerTypes); public void setInnerTypes(Type... innerTypes); @@ -106,6 +106,42 @@ public interface Type // Default is true; public boolean allowSpaceAfterTab(); + // -------------------------------------------- // + // CONTAINER + // -------------------------------------------- // + // The "Container" is an imaginary super type for "Collection" and "Map". + // The Element class E is the entry for a map. + + public boolean isContainer(); + public boolean isContainerMap(); + public boolean isContainerCollection(); + + public boolean isContainerIndexed(); + public boolean isContainerOrdered(); + public boolean isContainerSorted(); + + public Comparator getContainerComparator(); + public void setContainerComparator(Comparator container); + + public List getContainerElementsOrdered(Iterable elements); + public List getContainerElementsOrdered(T container); + + public boolean isContainerEmpty(T container); + public void clearContainer(T container); + + public Collection getContainerElements(T container); + public void setContainerElements(T container, Iterable elements); + + public boolean addContainerElement(T container, E element); + public void addContainerElements(T container, Iterable elements); + + // -------------------------------------------- // + // EQUALS + // -------------------------------------------- // + + public boolean equals(T type1, T type2, boolean strict); + public boolean equalsInner(T type1, T type2, boolean strict); + // -------------------------------------------- // // EDITOR // -------------------------------------------- // diff --git a/src/com/massivecraft/massivecore/command/type/TypeAbstract.java b/src/com/massivecraft/massivecore/command/type/TypeAbstract.java index 14355325..558a71d5 100644 --- a/src/com/massivecraft/massivecore/command/type/TypeAbstract.java +++ b/src/com/massivecraft/massivecore/command/type/TypeAbstract.java @@ -4,10 +4,16 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.Comparator; +import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.ListIterator; +import java.util.Map; import java.util.Set; +import java.util.SortedMap; +import java.util.SortedSet; +import java.util.Map.Entry; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; @@ -19,8 +25,10 @@ import com.massivecraft.massivecore.command.editor.CommandEditAbstract; import com.massivecraft.massivecore.command.editor.CommandEditSimple; import com.massivecraft.massivecore.command.editor.EditSettings; import com.massivecraft.massivecore.command.editor.Property; +import com.massivecraft.massivecore.comparator.ComparatorHashCode; import com.massivecraft.massivecore.store.Entity; import com.massivecraft.massivecore.store.SenderEntity; +import com.massivecraft.massivecore.util.MUtil; import com.massivecraft.massivecore.util.Txt; public abstract class TypeAbstract implements Type @@ -61,10 +69,10 @@ public abstract class TypeAbstract implements Type protected List> innerTypes = new MassiveList>(); @SuppressWarnings("unchecked") - public , X extends Object> List getInnerTypes() { return (List) this.innerTypes; } + public > List getInnerTypes() { return (List) this.innerTypes; } @SuppressWarnings("unchecked") - public Type getInnerType(int index) { return (Type) this.getInnerTypes().get(index); } - public Type getInnerType() { return this.getInnerType(0); } + public > I getInnerType(int index) { return (I) this.getInnerTypes().get(index); } + public > I getInnerType() { return this.getInnerType(0); } @SuppressWarnings({ "unchecked", "rawtypes" }) public void setInnerTypes(Collection> innerTypes) { this.innerTypes = new MassiveList(innerTypes); } @@ -393,6 +401,197 @@ public abstract class TypeAbstract implements Type return new ArrayList(ret); } + // -------------------------------------------- // + // CONTAINER + // -------------------------------------------- // + + public boolean isContainer() + { + return this.isContainerCollection() || this.isContainerMap(); + } + + private Boolean containerMap = null; + public boolean isContainerMap() + { + if (this.containerMap == null) this.containerMap = this.calcContainerMap(); + return this.containerMap; + } + protected boolean calcContainerMap() + { + T instance = this.createNewInstance(); + if (instance instanceof Map) return true; + return false; + } + + private Boolean containerCollection = null; + public boolean isContainerCollection() + { + if (this.containerCollection == null) this.containerCollection = this.calcContainerCollection(); + return this.containerCollection; + } + protected boolean calcContainerCollection() + { + T instance = this.createNewInstance(); + if (instance instanceof Collection) return true; + return false; + } + + public boolean isContainerIndexed() + { + return this.isContainerOrdered() || this.isContainerSorted(); + } + + private Boolean collectionOrdered = null; + public boolean isContainerOrdered() + { + if (this.collectionOrdered == null) this.collectionOrdered = this.calcContainerOrdered(); + return this.collectionOrdered; + } + protected boolean calcContainerOrdered() + { + T instance = this.createNewInstance(); + if (instance instanceof List) return true; + if (instance instanceof LinkedHashMap) return true; + return false; + } + + private Boolean collectionSorted = null; + public boolean isContainerSorted() + { + if (this.collectionSorted == null) this.collectionSorted = this.calcContainerSorted(); + return this.collectionSorted; + } + protected boolean calcContainerSorted() + { + T instance = this.createNewInstance(); + if (instance instanceof SortedSet) return true; + if (instance instanceof SortedMap) return true; + return false; + } + + private Comparator elementComparator = null; + @SuppressWarnings("unchecked") + public Comparator getContainerComparator() + { + if (this.elementComparator != null) return (Comparator) this.elementComparator; + if (this.isContainerIndexed()) return null; + return (Comparator) ComparatorHashCode.get().getLenient(); + } + @SuppressWarnings("unchecked") + public void setContainerComparator(Comparator comparator) { this.elementComparator = (Comparator) comparator; } + + public List getContainerElementsOrdered(Iterable elements) + { + if (elements == null) return null; + + List ret; + if (elements instanceof Collection) + { + ret = new MassiveList((Collection)elements); + } + else + { + ret = new MassiveList(); + for (E element : elements) + { + ret.add(element); + } + } + + Comparator elementComparator = this.getContainerComparator(); + if (elementComparator != null) ret.sort(elementComparator); + + return ret; + } + + @Override + public List getContainerElementsOrdered(T container) + { + Collection elements = this.getContainerElements(container); + return this.getContainerElementsOrdered(elements); + } + + public boolean isContainerEmpty(T container) + { + return this.getContainerElements(container).isEmpty(); + } + + @Override + public void clearContainer(T container) + { + this.getContainerElements(container).clear(); + } + + @SuppressWarnings("unchecked") + public Collection getContainerElements(T container) + { + if (container instanceof Collection) + { + Collection collection = (Collection)container; + return collection; + } + + if (container instanceof Map) + { + Map map = (Map)container; + return (Collection) map.entrySet(); + } + + throw new UnsupportedOperationException("not implemented"); + } + + public void setContainerElements(T container, Iterable elements) + { + this.clearContainer(container); + this.addContainerElements(container, elements); + } + + @SuppressWarnings("unchecked") + public boolean addContainerElement(T container, E element) + { + if (container instanceof Collection) + { + Collection collection = (Collection)container; + return collection.add(element); + } + + if (container instanceof Map) + { + Map map = (Map)container; + Entry entry = (Entry)element; + Object key = entry.getKey(); + Object after = entry.getValue(); + Object before = map.put(key, after); + return ! MUtil.equals(after, before); + } + + throw new UnsupportedOperationException("not implemented"); + } + + public void addContainerElements(T container, Iterable elements) + { + for (E element : elements) + { + this.addContainerElement(container, element); + } + } + + // -------------------------------------------- // + // EQUALS + // -------------------------------------------- // + + public boolean equals(T type1, T type2, boolean strict) + { + if (type1 == null) return type2 == null; + if (type2 == null) return type1 == null; + return this.equalsInner(type1, type2, strict); + } + + public boolean equalsInner(T type1, T type2, boolean strict) + { + return type1.equals(type2); + } + // -------------------------------------------- // // EDITOR // -------------------------------------------- // @@ -404,7 +603,7 @@ public abstract class TypeAbstract implements Type public T createNewInstance() { - throw new RuntimeException("Not implemented"); + return null; } } diff --git a/src/com/massivecraft/massivecore/command/type/TypeAbstractChoice.java b/src/com/massivecraft/massivecore/command/type/TypeAbstractChoice.java index 7427f30c..0dd8752d 100644 --- a/src/com/massivecraft/massivecore/command/type/TypeAbstractChoice.java +++ b/src/com/massivecraft/massivecore/command/type/TypeAbstractChoice.java @@ -12,13 +12,13 @@ import java.util.Set; import org.apache.commons.lang.StringUtils; import org.bukkit.command.CommandSender; -import com.massivecraft.massivecore.CaseInsensitiveComparator; import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.collections.MassiveList; import com.massivecraft.massivecore.collections.MassiveMap; import com.massivecraft.massivecore.collections.MassiveSet; import com.massivecraft.massivecore.collections.MassiveTreeSet; -import com.massivecraft.massivecore.command.type.collection.AllAble; +import com.massivecraft.massivecore.command.type.container.AllAble; +import com.massivecraft.massivecore.comparator.ComparatorCaseInsensitive; import com.massivecraft.massivecore.util.ReflectionUtil; import com.massivecraft.massivecore.util.Txt; @@ -405,7 +405,7 @@ public abstract class TypeAbstractChoice extends TypeAbstract implements A public Set createTabs(T value) { // Create - Set ret = new MassiveTreeSet(CaseInsensitiveComparator.get()); + Set ret = new MassiveTreeSet(ComparatorCaseInsensitive.get()); // Fill String string; diff --git a/src/com/massivecraft/massivecore/command/type/TypeAbstractSelect.java b/src/com/massivecraft/massivecore/command/type/TypeAbstractSelect.java index 7f1450f0..1478f886 100644 --- a/src/com/massivecraft/massivecore/command/type/TypeAbstractSelect.java +++ b/src/com/massivecraft/massivecore/command/type/TypeAbstractSelect.java @@ -9,7 +9,7 @@ import org.apache.commons.lang.StringUtils; import org.bukkit.command.CommandSender; import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.type.collection.AllAble; +import com.massivecraft.massivecore.command.type.container.AllAble; import com.massivecraft.massivecore.util.Txt; public abstract class TypeAbstractSelect extends TypeAbstract implements AllAble diff --git a/src/com/massivecraft/massivecore/command/type/TypeWrapper.java b/src/com/massivecraft/massivecore/command/type/TypeWrapper.java index 2fc2298d..8ce78135 100644 --- a/src/com/massivecraft/massivecore/command/type/TypeWrapper.java +++ b/src/com/massivecraft/massivecore/command/type/TypeWrapper.java @@ -13,10 +13,10 @@ public class TypeWrapper extends TypeAbstract // CONSTRUCT // -------------------------------------------- // - public TypeWrapper(Type inner) + public TypeWrapper(Type innerType) { - if (inner == null) throw new NullPointerException("inner"); - this.setInnerType(inner); + if (innerType == null) throw new NullPointerException("inner"); + this.setInnerType(innerType); } // -------------------------------------------- // @@ -32,19 +32,22 @@ public class TypeWrapper extends TypeAbstract @Override public String getVisualInner(T value, CommandSender sender) { - return this.getInnerType().getVisualInner(value, sender); + Type innerType = this.getInnerType(); + return innerType.getVisualInner(value, sender); } @Override public String getNameInner(T value) { - return this.getInnerType().getNameInner(value); + Type innerType = this.getInnerType(); + return innerType.getNameInner(value); } @Override public String getIdInner(T value) { - return this.getInnerType().getIdInner(value); + Type innerType = this.getInnerType(); + return innerType.getIdInner(value); } @Override diff --git a/src/com/massivecraft/massivecore/command/type/collection/TypeMap.java b/src/com/massivecraft/massivecore/command/type/collection/TypeMap.java deleted file mode 100644 index d4d75cd0..00000000 --- a/src/com/massivecraft/massivecore/command/type/collection/TypeMap.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.massivecraft.massivecore.command.type.collection; - -import java.util.HashMap; -import java.util.Map; - -import com.massivecraft.massivecore.collections.MassiveMap; -import com.massivecraft.massivecore.command.type.Type; - -public class TypeMap extends TypeMapAbstract, K, V> -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - public static TypeMap get(Type keyType, Type valueType) - { - return new TypeMap(keyType, valueType); - } - - public TypeMap(Type keyType, Type valueType) - { - super(keyType, valueType); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public HashMap createNewInstance() - { - return new MassiveMap(); - } - -} diff --git a/src/com/massivecraft/massivecore/command/type/collection/TypeMapAbstract.java b/src/com/massivecraft/massivecore/command/type/collection/TypeMapAbstract.java deleted file mode 100644 index 3f467cc2..00000000 --- a/src/com/massivecraft/massivecore/command/type/collection/TypeMapAbstract.java +++ /dev/null @@ -1,210 +0,0 @@ -package com.massivecraft.massivecore.command.type.collection; - -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.collections.MassiveList; -import com.massivecraft.massivecore.command.editor.CommandEditAbstract; -import com.massivecraft.massivecore.command.editor.CommandEditMap; -import com.massivecraft.massivecore.command.editor.EditSettings; -import com.massivecraft.massivecore.command.editor.Property; -import com.massivecraft.massivecore.command.type.Type; -import com.massivecraft.massivecore.command.type.TypeAbstract; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.command.CommandSender; - -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -public abstract class TypeMapAbstract, K, V> extends TypeAbstract -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public TypeMapAbstract(Type mapKeyType, Type mapValueType) - { - this.setInnerTypes(mapKeyType, mapValueType); - } - - // -------------------------------------------- // - // INNER TYPES - // -------------------------------------------- // - - public Type getMapKeyType() { return this.getInnerType(0); } - public Type getMapValueType() { return this.getInnerType(1); } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getTypeName() - { - return "Map: " + this.getMapKeyType().getTypeName() + " -> " + this.getMapValueType().getTypeName(); - } - - @Override - public String getVisualInner(C value, CommandSender sender) - { - // Empty - if (value.isEmpty()) return EMPTY; - - List parts = new MassiveList(); - - for (Entry entry : value.entrySet()) - { - K entryKey = entry.getKey(); - String visualKey = this.getMapKeyType().getVisual(entryKey, sender); - - V entryValue = entry.getValue(); - String visualValue = this.getMapValueType().getVisual(entryValue, sender); - - String part = Txt.parse("# %s: %s", visualKey, visualValue); - parts.add(part); - } - - return Txt.implode(parts, "\n"); - } - - @Override - public String getNameInner(C value) - { - // Empty - if (value.isEmpty()) return EMPTY; - - // Create - StringBuilder builder = new StringBuilder(); - boolean first = true; - - // Fill - for (Entry entry : value.entrySet()) - { - if ( ! first) builder.append(", "); - - // Append key - K entryKey = entry.getKey(); - builder.append(this.getInnerType().getName(entryKey)); - - // Add Colon & Space - builder.append(':'); - builder.append(' '); - - // Append value - V entryValue = entry.getValue(); - builder.append(this.getMapValueType().getName(entryValue)); - first = false; - } - - // Return - return builder.toString(); - } - - @Override - public String getIdInner(C value) - { - // Empty - if (value.isEmpty()) return EMPTY; - - // Create - StringBuilder builder = new StringBuilder(); - boolean first = true; - - // Fill - for (Entry entry : value.entrySet()) - { - if ( ! first) builder.append(", "); - - // Append key - K entryKey = entry.getKey(); - builder.append(this.getInnerType().getId(entryKey)); - - // Add Colon & Space - builder.append(':'); - builder.append(' '); - - // Append value - V entryValue = entry.getValue(); - builder.append(this.getMapValueType().getId(entryValue)); - first = false; - } - - // Return - return builder.toString(); - } - - @Override - public C read(String arg, CommandSender sender) throws MassiveException - { - // Create - C ret = this.createNewInstance(); - - // Prepare - List args = new MassiveList<>(Txt.PATTERN_WHITESPACE.split(arg)); - if (args.size() % 2 != 0) - { - throw new MassiveException().setMsg("There must be an even amount of arguments for a map."); - } - - // Fill - for (Iterator it = args.iterator(); it.hasNext(); ) - { - // Get Key - String keyString = it.next(); - K key = this.getMapKeyType().read(keyString, sender); - - // Get Value - String valueString = it.next(); - V value = this.getMapValueType().read(valueString, sender); - - ret.put(key, value); - } - - // Return - return ret; - } - - @Override - public Collection getTabList(CommandSender sender, String arg) - { - // Because we accept multiple arguments pairs of the same type. - // The passed arg might be more than one. We only want the latest. - List args = TypeCollection.getArgs(arg); - String lastArg = args.isEmpty() ? null : args.get(args.size() - 1); - - // Type - Type type = args.size() % 2 == 1 ? this.getMapKeyType() : this.getMapValueType(); - - // Return - return type.getTabList(sender, lastArg); - } - - @Override - public List getTabListFiltered(CommandSender sender, String arg) - { - // Because we accept multiple arguments pairs of the same type. - // The passed arg might be more than one. We only want the latest. - List args = TypeCollection.getArgs(arg); - String lastArg = args.isEmpty() ? null : args.get(args.size() - 1); - - // Type - Type type = args.size() % 2 == 1 ? this.getMapKeyType() : this.getMapValueType(); - - // Return - return type.getTabListFiltered(sender, lastArg); - } - - @Override - public boolean allowSpaceAfterTab() - { - return this.getMapKeyType().allowSpaceAfterTab() && this.getMapValueType().allowSpaceAfterTab(); - } - - @Override - public CommandEditAbstract createEditCommand(EditSettings settings, Property property) - { - return new CommandEditMap(settings, property); - } - -} diff --git a/src/com/massivecraft/massivecore/command/type/combined/TypeCombined.java b/src/com/massivecraft/massivecore/command/type/combined/TypeCombined.java index 2ff68023..04474b23 100644 --- a/src/com/massivecraft/massivecore/command/type/combined/TypeCombined.java +++ b/src/com/massivecraft/massivecore/command/type/combined/TypeCombined.java @@ -16,25 +16,18 @@ import com.massivecraft.massivecore.util.Txt; public abstract class TypeCombined extends TypeAbstract { - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - protected List> types; - public List> getTypes() { return this.types; } - // -------------------------------------------- // // INSTANCE & CONSTRUCT // -------------------------------------------- // - public TypeCombined(Collection> types) + public TypeCombined(Collection> innerTypes) { - this.types = new MassiveList>(types); + this.setInnerTypes(innerTypes); } - public TypeCombined(Type... types) + public TypeCombined(Type... innerTypes) { - this(Arrays.asList(types)); + this.setInnerTypes(innerTypes); } // -------------------------------------------- // @@ -52,10 +45,10 @@ public abstract class TypeCombined extends TypeAbstract // Fill List parts = this.split(value); - if (parts.size() > this.getTypes().size()) throw new RuntimeException("Too many parts!"); + if (parts.size() > this.getInnerTypes().size()) throw new RuntimeException("Too many parts!"); for (int i = 0; i < parts.size(); i++) { - Type type = this.getTypes().get(i); + Type type = this.getInnerTypes().get(i); Object part = parts.get(i); SimpleEntry, Object> entry = new SimpleEntry, Object>(type, part); ret.add(entry); @@ -76,7 +69,7 @@ public abstract class TypeCombined extends TypeAbstract List parts = new MassiveList(); // Fill - for (Type type : this.getTypes()) + for (Type type : this.getInnerTypes()) { parts.add(type.getTypeName()); } @@ -157,7 +150,7 @@ public abstract class TypeCombined extends TypeAbstract // Fill List argParts = Arrays.asList(arg.split("[, ]+")); - if (argParts.size() > this.getTypes().size()) + if (argParts.size() > this.getInnerTypes().size()) { throw new MassiveException().addMsg("Too many parts!"); } @@ -165,7 +158,7 @@ public abstract class TypeCombined extends TypeAbstract for (int i = 0; i < argParts.size(); i++) { String argPart = argParts.get(i); - Type type = this.getTypes().get(i); + Type type = this.getInnerTypes().get(i); Object part = type.read(argPart, sender); diff --git a/src/com/massivecraft/massivecore/command/type/combined/TypeEntry.java b/src/com/massivecraft/massivecore/command/type/combined/TypeEntry.java new file mode 100644 index 00000000..d75ce93d --- /dev/null +++ b/src/com/massivecraft/massivecore/command/type/combined/TypeEntry.java @@ -0,0 +1,96 @@ +package com.massivecraft.massivecore.command.type.combined; + +import java.util.List; +import java.util.Map.Entry; + +import java.util.AbstractMap.SimpleEntry; + +import com.massivecraft.massivecore.collections.MassiveList; +import com.massivecraft.massivecore.command.type.Type; + +public class TypeEntry extends TypeCombined> +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + public static TypeEntry get(Type keyType, Type valueType) { return new TypeEntry(keyType, valueType); } + public TypeEntry(Type keyType, Type valueType) + { + super(keyType, valueType); + } + + // -------------------------------------------- // + // INNER TYPES + // -------------------------------------------- // + + public Type getKeyType() { return this.getInnerType(0); } + public Type getValueType() { return this.getInnerType(1); } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getTypeName() + { + return this.getKeyType().getTypeName() + " and " + this.getValueType().getTypeName(); + } + + @SuppressWarnings("unchecked") + @Override + public Entry combine(List parts) + { + // Create + K key = null; + V value = null; + + // Fill + for (int i = 0 ; i < parts.size() ; i++) + { + Object part = parts.get(i); + + if (i == 0) + { + key = (K)part; + } + else if (i == 1) + { + value = (V)part; + } + } + + // Return + return new SimpleEntry(key, value); + } + + @Override + public List split(Entry entry) + { + return new MassiveList( + entry.getKey(), + entry.getValue() + ); + } + + @Override + public boolean equalsInner(Entry type1, Entry type2, boolean strict) + { + // Compare Keys + K key1 = type1.getKey(); + K key2 = type2.getKey(); + if ( ! this.getKeyType().equals(key1, key2, strict)) return false; + + // Strict + if ( ! strict) return true; + + // Compare Values + V value1 = type1.getValue(); + V value2 = type2.getValue(); + if ( ! this.getValueType().equals(value1, value2, strict)) return false; + + // Done + return true; + } + +} diff --git a/src/com/massivecraft/massivecore/command/type/collection/AllAble.java b/src/com/massivecraft/massivecore/command/type/container/AllAble.java similarity index 71% rename from src/com/massivecraft/massivecore/command/type/collection/AllAble.java rename to src/com/massivecraft/massivecore/command/type/container/AllAble.java index edebad29..94dfbc3e 100644 --- a/src/com/massivecraft/massivecore/command/type/collection/AllAble.java +++ b/src/com/massivecraft/massivecore/command/type/container/AllAble.java @@ -1,4 +1,4 @@ -package com.massivecraft.massivecore.command.type.collection; +package com.massivecraft.massivecore.command.type.container; import java.util.Collection; diff --git a/src/com/massivecraft/massivecore/command/type/collection/TypeCollection.java b/src/com/massivecraft/massivecore/command/type/container/TypeContainer.java similarity index 55% rename from src/com/massivecraft/massivecore/command/type/collection/TypeCollection.java rename to src/com/massivecraft/massivecore/command/type/container/TypeContainer.java index c920b77e..7d4886db 100644 --- a/src/com/massivecraft/massivecore/command/type/collection/TypeCollection.java +++ b/src/com/massivecraft/massivecore/command/type/container/TypeContainer.java @@ -1,4 +1,4 @@ -package com.massivecraft.massivecore.command.type.collection; +package com.massivecraft.massivecore.command.type.container; import java.util.Arrays; import java.util.Collection; @@ -9,26 +9,26 @@ import org.bukkit.command.CommandSender; import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.collections.MassiveList; import com.massivecraft.massivecore.command.editor.CommandEditAbstract; -import com.massivecraft.massivecore.command.editor.CommandEditCollection; +import com.massivecraft.massivecore.command.editor.CommandEditContainer; import com.massivecraft.massivecore.command.editor.EditSettings; import com.massivecraft.massivecore.command.editor.Property; import com.massivecraft.massivecore.command.type.Type; import com.massivecraft.massivecore.command.type.TypeAbstract; import com.massivecraft.massivecore.util.Txt; -public abstract class TypeCollection, E> extends TypeAbstract +public abstract class TypeContainer extends TypeAbstract { // -------------------------------------------- // // CONSTRUCT // -------------------------------------------- // - public TypeCollection(Type innerType) + public TypeContainer(Type innerType) { this.setInnerType(innerType); } // -------------------------------------------- // - // OVERRIDE + // META // -------------------------------------------- // @Override @@ -39,41 +39,56 @@ public abstract class TypeCollection, E> extends TypeAbs public String getCollectionTypeName() { - return "Collection"; + return "Container"; } + // -------------------------------------------- // + // WRITE VISUAL + // -------------------------------------------- // + @Override - public String getVisualInner(C value, CommandSender sender) + public String getVisualInner(C container, CommandSender sender) { // Empty - if (value.isEmpty()) return EMPTY; + if (this.isContainerEmpty(container)) return EMPTY; + // Create List parts = new MassiveList(); + // Fill + List elements = this.getContainerElementsOrdered(container); + Type innerType = this.getInnerType(); int index = -1; - for (E element : value) + for (E element : elements) { index++; - String part = Txt.parse("%d %s", index, this.getInnerType().getVisualInner(element, sender)); + String part = Txt.parse("%d %s", index, innerType.getVisualInner(element, sender)); parts.add(part); } + // Return return Txt.implode(parts, "\n"); } + // -------------------------------------------- // + // WRITE NAME + // -------------------------------------------- // + @Override - public String getNameInner(C value) + public String getNameInner(C container) { // Empty - if (value.isEmpty()) return ""; + if (this.isContainerEmpty(container)) return ""; // Create List parts = new MassiveList(); // Fill - for (E element : value) + List elements = this.getContainerElementsOrdered(container); + Type innerType = this.getInnerType(); + for (E element : elements) { - String part = this.getInnerType().getNameInner(element); + String part = innerType.getNameInner(element); parts.add(part); } @@ -81,19 +96,25 @@ public abstract class TypeCollection, E> extends TypeAbs return Txt.implode(parts, " "); } + // -------------------------------------------- // + // WRITE ID + // -------------------------------------------- // + @Override - public String getIdInner(C value) + public String getIdInner(C container) { // Empty - if (value.isEmpty()) return ""; + if (this.isContainerEmpty(container)) return ""; // Create List parts = new MassiveList(); // Fill - for (E element : value) + List elements = this.getContainerElementsOrdered(container); + Type innerType = this.getInnerType(); + for (E element : elements) { - String part = this.getInnerType().getIdInner(element); + String part = innerType.getIdInner(element); parts.add(part); } @@ -101,6 +122,10 @@ public abstract class TypeCollection, E> extends TypeAbs return Txt.implode(parts, " "); } + // -------------------------------------------- // + // READ + // -------------------------------------------- // + @SuppressWarnings("unchecked") @Override public C read(String arg, CommandSender sender) throws MassiveException @@ -114,7 +139,7 @@ public abstract class TypeCollection, E> extends TypeAbs AllAble allAble = (AllAble)this.getInnerType(); if (arg.equalsIgnoreCase("all")) { - ret.addAll(allAble.getAll(sender)); + this.addContainerElements(ret, allAble.getAll(sender)); return ret; } } @@ -125,13 +150,17 @@ public abstract class TypeCollection, E> extends TypeAbs { Type innerType = this.getInnerType(); E element = innerType.read(elementArg, sender); - ret.add(element); + this.addContainerElement(ret, element); } // Return return ret; } + // -------------------------------------------- // + // TAB LIST + // -------------------------------------------- // + @Override public Collection getTabList(CommandSender sender, String arg) { @@ -154,14 +183,42 @@ public abstract class TypeCollection, E> extends TypeAbs return this.getInnerType().allowSpaceAfterTab(); } + // -------------------------------------------- // + // EQUALS + // -------------------------------------------- // + @Override - public CommandEditAbstract createEditCommand(EditSettings settings, Property property) + public boolean equalsInner(C container1, C container2, boolean strict) { - return new CommandEditCollection(settings, property); + List ordered1 = this.getContainerElementsOrdered(container1); + List ordered2 = this.getContainerElementsOrdered(container2); + + if (ordered1.size() != ordered2.size()) return false; + + Type innerType = this.getInnerType(); + for (int index = 0; index < ordered1.size(); index++) + { + E element1 = ordered1.get(index); + E element2 = ordered2.get(index); + + if ( ! innerType.equals(element1, element2, strict)) return false; + } + + return true; } // -------------------------------------------- // - // UTIL + // EDITOR + // -------------------------------------------- // + + @Override + public CommandEditAbstract createEditCommand(EditSettings settings, Property property) + { + return new CommandEditContainer(settings, property); + } + + // -------------------------------------------- // + // ARGS // -------------------------------------------- // public static List getArgs(String string) diff --git a/src/com/massivecraft/massivecore/command/type/collection/TypeItemStacks.java b/src/com/massivecraft/massivecore/command/type/container/TypeItemStacks.java similarity index 95% rename from src/com/massivecraft/massivecore/command/type/collection/TypeItemStacks.java rename to src/com/massivecraft/massivecore/command/type/container/TypeItemStacks.java index 45bafc25..b0053451 100644 --- a/src/com/massivecraft/massivecore/command/type/collection/TypeItemStacks.java +++ b/src/com/massivecraft/massivecore/command/type/container/TypeItemStacks.java @@ -1,4 +1,4 @@ -package com.massivecraft.massivecore.command.type.collection; +package com.massivecraft.massivecore.command.type.container; import java.util.List; diff --git a/src/com/massivecraft/massivecore/command/type/collection/TypeList.java b/src/com/massivecraft/massivecore/command/type/container/TypeList.java similarity index 81% rename from src/com/massivecraft/massivecore/command/type/collection/TypeList.java rename to src/com/massivecraft/massivecore/command/type/container/TypeList.java index ecfa7985..8ceb8fb4 100644 --- a/src/com/massivecraft/massivecore/command/type/collection/TypeList.java +++ b/src/com/massivecraft/massivecore/command/type/container/TypeList.java @@ -1,11 +1,11 @@ -package com.massivecraft.massivecore.command.type.collection; +package com.massivecraft.massivecore.command.type.container; import java.util.List; import com.massivecraft.massivecore.collections.MassiveList; import com.massivecraft.massivecore.command.type.Type; -public class TypeList extends TypeCollection, E> +public class TypeList extends TypeContainer, E> { // -------------------------------------------- // // INSTANCE & CONSTRUCT diff --git a/src/com/massivecraft/massivecore/command/type/container/TypeMap.java b/src/com/massivecraft/massivecore/command/type/container/TypeMap.java new file mode 100644 index 00000000..32cd2a6b --- /dev/null +++ b/src/com/massivecraft/massivecore/command/type/container/TypeMap.java @@ -0,0 +1,50 @@ +package com.massivecraft.massivecore.command.type.container; + +import java.util.Map; +import java.util.Map.Entry; + +import com.massivecraft.massivecore.collections.MassiveMap; +import com.massivecraft.massivecore.command.type.Type; +import com.massivecraft.massivecore.command.type.combined.TypeEntry; + +public class TypeMap extends TypeContainer, Entry> +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + public static TypeMap get(Type keyType, Type valueType) + { + return new TypeMap(keyType, valueType); + } + + public TypeMap(Type keyType, Type valueType) + { + super(TypeEntry.get(keyType, valueType)); + } + + // -------------------------------------------- // + // INNER TYPES + // -------------------------------------------- // + + public TypeEntry getEntryType() { return this.getInnerType(); } + public Type getKeyType() { return this.getEntryType().getKeyType(); } + public Type getValueType() { return this.getEntryType().getValueType(); } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getCollectionTypeName() + { + return "Map"; + } + + @Override + public Map createNewInstance() + { + return new MassiveMap(); + } + +} diff --git a/src/com/massivecraft/massivecore/command/type/collection/TypeSet.java b/src/com/massivecraft/massivecore/command/type/container/TypeSet.java similarity index 81% rename from src/com/massivecraft/massivecore/command/type/collection/TypeSet.java rename to src/com/massivecraft/massivecore/command/type/container/TypeSet.java index 2dac5b30..6d5e4b0f 100644 --- a/src/com/massivecraft/massivecore/command/type/collection/TypeSet.java +++ b/src/com/massivecraft/massivecore/command/type/container/TypeSet.java @@ -1,11 +1,11 @@ -package com.massivecraft.massivecore.command.type.collection; +package com.massivecraft.massivecore.command.type.container; import java.util.Set; import com.massivecraft.massivecore.collections.MassiveSet; import com.massivecraft.massivecore.command.type.Type; -public class TypeSet extends TypeCollection, E> +public class TypeSet extends TypeContainer, E> { // -------------------------------------------- // // INSTANCE & CONSTRUCT diff --git a/src/com/massivecraft/massivecore/comparator/ComparatorAbstract.java b/src/com/massivecraft/massivecore/comparator/ComparatorAbstract.java new file mode 100644 index 00000000..1f1b0936 --- /dev/null +++ b/src/com/massivecraft/massivecore/comparator/ComparatorAbstract.java @@ -0,0 +1,61 @@ +package com.massivecraft.massivecore.comparator; + +import java.util.Comparator; + +import com.massivecraft.massivecore.util.MUtil; + +public class ComparatorAbstract implements Comparator +{ + // -------------------------------------------- // + // REVERSED + // -------------------------------------------- // + + private ComparatorReversed reversed = null; + public ComparatorAbstract getReversed() + { + if (this.reversed == null) this.reversed = ComparatorReversed.get(this); + return this.reversed; + } + + // -------------------------------------------- // + // LENIENT + // -------------------------------------------- // + + private ComparatorLenient lenient = null; + public ComparatorAbstract getLenient() + { + if (this.lenient == null) this.lenient = ComparatorLenient.get(this); + return this.lenient; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public int compare(T type1, T type2) + { + // Create + Integer ret; + + // Null + ret = MUtil.compareNulls(type1, type2); + if (ret != null) return ret; + + // Inner + ret = this.compareInner(type1, type2); + + // Return + return ret; + } + + // -------------------------------------------- // + // INNER + // -------------------------------------------- // + + public int compareInner(T type1, T type2) + { + throw new UnsupportedOperationException("not implemented"); + } + +} diff --git a/src/com/massivecraft/massivecore/comparator/ComparatorAbstractTransformer.java b/src/com/massivecraft/massivecore/comparator/ComparatorAbstractTransformer.java new file mode 100644 index 00000000..9fbed9c6 --- /dev/null +++ b/src/com/massivecraft/massivecore/comparator/ComparatorAbstractTransformer.java @@ -0,0 +1,35 @@ +package com.massivecraft.massivecore.comparator; + +import java.util.Comparator; + +public abstract class ComparatorAbstractTransformer extends ComparatorAbstractWrapper +{ + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public ComparatorAbstractTransformer(Comparator comparator) + { + super(comparator); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public int compareInner(T type1, T type2) + { + X x1 = this.transform(type1); + X x2 = this.transform(type2); + + return this.getComparator().compare(x1, x2); + } + + // -------------------------------------------- // + // ABSTRACT + // -------------------------------------------- // + + public abstract X transform(T type); + +} diff --git a/src/com/massivecraft/massivecore/comparator/ComparatorAbstractWrapper.java b/src/com/massivecraft/massivecore/comparator/ComparatorAbstractWrapper.java new file mode 100644 index 00000000..ead79aae --- /dev/null +++ b/src/com/massivecraft/massivecore/comparator/ComparatorAbstractWrapper.java @@ -0,0 +1,24 @@ +package com.massivecraft.massivecore.comparator; + +import java.util.Comparator; + +public abstract class ComparatorAbstractWrapper extends ComparatorAbstract +{ + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private Comparator comparator; + public Comparator getComparator() { return this.comparator; } + public void setComparator(Comparator comparator) { this.comparator = comparator; } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public ComparatorAbstractWrapper(Comparator comparator) + { + this.comparator = comparator; + } + +} diff --git a/src/com/massivecraft/massivecore/comparator/ComparatorCaseInsensitive.java b/src/com/massivecraft/massivecore/comparator/ComparatorCaseInsensitive.java new file mode 100644 index 00000000..d0ca4314 --- /dev/null +++ b/src/com/massivecraft/massivecore/comparator/ComparatorCaseInsensitive.java @@ -0,0 +1,22 @@ +package com.massivecraft.massivecore.comparator; + +public class ComparatorCaseInsensitive extends ComparatorAbstract +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ComparatorCaseInsensitive i = new ComparatorCaseInsensitive(); + public static ComparatorCaseInsensitive get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public int compareInner(String string1, String string2) + { + return String.CASE_INSENSITIVE_ORDER.compare(string1, string2); + } + +} diff --git a/src/com/massivecraft/massivecore/comparator/ComparatorEntryKey.java b/src/com/massivecraft/massivecore/comparator/ComparatorEntryKey.java new file mode 100644 index 00000000..5eabe1ce --- /dev/null +++ b/src/com/massivecraft/massivecore/comparator/ComparatorEntryKey.java @@ -0,0 +1,28 @@ +package com.massivecraft.massivecore.comparator; + +import java.util.Comparator; +import java.util.Map.Entry; + +public class ComparatorEntryKey extends ComparatorAbstractTransformer, K> +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + public static ComparatorEntryKey get(Comparator comparator) { return new ComparatorEntryKey(comparator); } + public ComparatorEntryKey(Comparator comparator) + { + super(comparator); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public K transform(Entry type) + { + return type.getKey(); + } + +} diff --git a/src/com/massivecraft/massivecore/comparator/ComparatorEntryValue.java b/src/com/massivecraft/massivecore/comparator/ComparatorEntryValue.java new file mode 100644 index 00000000..b319edc1 --- /dev/null +++ b/src/com/massivecraft/massivecore/comparator/ComparatorEntryValue.java @@ -0,0 +1,28 @@ +package com.massivecraft.massivecore.comparator; + +import java.util.Comparator; +import java.util.Map.Entry; + +public class ComparatorEntryValue extends ComparatorAbstractTransformer, V> +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + public static ComparatorEntryValue get(Comparator comparator) { return new ComparatorEntryValue(comparator); } + public ComparatorEntryValue(Comparator comparator) + { + super(comparator); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public V transform(Entry type) + { + return type.getValue(); + } + +} diff --git a/src/com/massivecraft/massivecore/comparator/ComparatorHashCode.java b/src/com/massivecraft/massivecore/comparator/ComparatorHashCode.java new file mode 100644 index 00000000..89c31bfb --- /dev/null +++ b/src/com/massivecraft/massivecore/comparator/ComparatorHashCode.java @@ -0,0 +1,32 @@ +package com.massivecraft.massivecore.comparator; + +import java.util.Objects; + +public class ComparatorHashCode extends ComparatorAbstract +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static transient ComparatorHashCode i = new ComparatorHashCode(); + public static ComparatorHashCode get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public int compareInner(Object object1, Object object2) + { + int ret; + + ret = Integer.compare(Objects.hashCode(object1), Objects.hashCode(object2)); + if (ret != 0) return ret; + + ret = Integer.compare(System.identityHashCode(object1), System.identityHashCode(object2)); + if (ret != 0) return ret; + + return ret; + } + +} diff --git a/src/com/massivecraft/massivecore/comparator/ComparatorLenient.java b/src/com/massivecraft/massivecore/comparator/ComparatorLenient.java new file mode 100644 index 00000000..9eace19c --- /dev/null +++ b/src/com/massivecraft/massivecore/comparator/ComparatorLenient.java @@ -0,0 +1,42 @@ +package com.massivecraft.massivecore.comparator; + +import java.util.Comparator; + +public class ComparatorLenient extends ComparatorAbstractWrapper +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + public static ComparatorLenient get(Comparator comparator) { return new ComparatorLenient(comparator); } + public ComparatorLenient(Comparator comparator) + { + super(comparator); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public int compare(T type1, T type2) + { + int ret = this.getComparator().compare(type1, type2); + if (ret != 0) return ret; + + int hash1 = type1.hashCode(); + int hash2 = type2.hashCode(); + + ret = Integer.compare(hash1, hash2); + if (ret != 0) return ret; + + return 1; + } + + @Override + public ComparatorAbstract getLenient() + { + return this; + } + +} diff --git a/src/com/massivecraft/massivecore/NaturalOrderComparator.java b/src/com/massivecraft/massivecore/comparator/ComparatorNaturalOrder.java similarity index 88% rename from src/com/massivecraft/massivecore/NaturalOrderComparator.java rename to src/com/massivecraft/massivecore/comparator/ComparatorNaturalOrder.java index 466b3ea4..8ec3d5df 100644 --- a/src/com/massivecraft/massivecore/NaturalOrderComparator.java +++ b/src/com/massivecraft/massivecore/comparator/ComparatorNaturalOrder.java @@ -27,33 +27,27 @@ This version has been slightly modified for usage in the MassiveCore library. Check out the original at: https://github.com/paour/natorder/blob/master/NaturalOrderComparator.java */ -package com.massivecraft.massivecore; +package com.massivecraft.massivecore.comparator; -import java.util.*; - -public class NaturalOrderComparator implements Comparator +public class ComparatorNaturalOrder extends ComparatorAbstract { // -------------------------------------------- // // INSTANCE & CONSTRUCT // -------------------------------------------- // - private static transient NaturalOrderComparator i = new NaturalOrderComparator(); - public static NaturalOrderComparator get() { return i; } + private static transient ComparatorNaturalOrder i = new ComparatorNaturalOrder(); + public static ComparatorNaturalOrder get() { return i; } // -------------------------------------------- // // OVERRIDE // -------------------------------------------- // @Override - public int compare(Object o1, Object o2) + public int compareInner(Object object1, Object object2) { - // Null (MassiveCore Modification) - if (o1 == null && o2 == null) return 0; - if (o2 == null) return 1; - if (o1 == null) return -1; - - String a = o1.toString(); - String b = o2.toString(); + // Martin Pool + String a = object1.toString(); + String b = object2.toString(); int ia = 0, ib = 0; int nza = 0, nzb = 0; @@ -190,4 +184,5 @@ public class NaturalOrderComparator implements Comparator return s.charAt(i); } } + } \ No newline at end of file diff --git a/src/com/massivecraft/massivecore/comparator/ComparatorPriority.java b/src/com/massivecraft/massivecore/comparator/ComparatorPriority.java new file mode 100644 index 00000000..c79ac683 --- /dev/null +++ b/src/com/massivecraft/massivecore/comparator/ComparatorPriority.java @@ -0,0 +1,42 @@ +package com.massivecraft.massivecore.comparator; + +import com.massivecraft.massivecore.Prioritized; +import com.massivecraft.massivecore.store.ComparatorEntityId; +import com.massivecraft.massivecore.store.Entity; + +public class ComparatorPriority extends ComparatorAbstract +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ComparatorPriority i = new ComparatorPriority(); + public static ComparatorPriority get() { return i; } + + // -------------------------------------------- // + // OVERRIDE: COMPARATOR + // -------------------------------------------- // + + @Override + public int compareInner(Prioritized prioritized1, Prioritized prioritized2) + { + // Equals + if (prioritized1.equals(prioritized2)) return 0; + + // Priority + Integer ret = Integer.compare(prioritized1.getPriority(), prioritized2.getPriority()); + if (ret != 0) return ret; + + // Entity Id + if (prioritized1 instanceof Entity && prioritized2 instanceof Entity) + { + Entity entity1 = (Entity)prioritized1; + Entity entity2 = (Entity)prioritized2; + return ComparatorEntityId.get().compare(entity1, entity2); + } + + // We should only return 0 if the items actually are equal. + return Integer.compare(prioritized1.hashCode(), prioritized2.hashCode()); + } + +} diff --git a/src/com/massivecraft/massivecore/comparator/ComparatorReversed.java b/src/com/massivecraft/massivecore/comparator/ComparatorReversed.java new file mode 100644 index 00000000..d5ba8fb7 --- /dev/null +++ b/src/com/massivecraft/massivecore/comparator/ComparatorReversed.java @@ -0,0 +1,35 @@ +package com.massivecraft.massivecore.comparator; + +import java.util.Comparator; + +public class ComparatorReversed extends ComparatorAbstractWrapper +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + public static ComparatorReversed get(Comparator comparator) { return new ComparatorReversed(comparator); } + public ComparatorReversed(Comparator comparator) + { + super(comparator); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public int compare(T type1, T type2) + { + return - this.getComparator().compare(type1, type2); + } + + @Override + public ComparatorAbstract getReversed() + { + Comparator comparator = this.getComparator(); + if (comparator instanceof ComparatorAbstract) return (ComparatorAbstract) comparator; + return super.getReversed(); + } + +} diff --git a/src/com/massivecraft/massivecore/engine/EngineMassiveCoreMain.java b/src/com/massivecraft/massivecore/engine/EngineMassiveCoreMain.java index 2bc81b35..c15a911c 100644 --- a/src/com/massivecraft/massivecore/engine/EngineMassiveCoreMain.java +++ b/src/com/massivecraft/massivecore/engine/EngineMassiveCoreMain.java @@ -23,8 +23,6 @@ import org.bukkit.plugin.Plugin; import com.massivecraft.massivecore.EngineAbstract; import com.massivecraft.massivecore.MassiveCore; import com.massivecraft.massivecore.MassiveCoreMConf; -import com.massivecraft.massivecore.Predicate; -import com.massivecraft.massivecore.PredicateStartsWithIgnoreCase; import com.massivecraft.massivecore.SenderPresence; import com.massivecraft.massivecore.SenderType; import com.massivecraft.massivecore.event.EventMassiveCoreAfterPlayerRespawn; @@ -32,6 +30,8 @@ import com.massivecraft.massivecore.event.EventMassiveCoreAfterPlayerTeleport; import com.massivecraft.massivecore.event.EventMassiveCorePermissionDeniedFormat; import com.massivecraft.massivecore.event.EventMassiveCorePlayerToRecipientChat; import com.massivecraft.massivecore.mixin.Mixin; +import com.massivecraft.massivecore.predicate.Predicate; +import com.massivecraft.massivecore.predicate.PredicateStartsWithIgnoreCase; import com.massivecraft.massivecore.util.IdUtil; import com.massivecraft.massivecore.util.MUtil; import com.massivecraft.massivecore.util.SmokeUtil; diff --git a/src/com/massivecraft/massivecore/mixin/MessageMixin.java b/src/com/massivecraft/massivecore/mixin/MessageMixin.java index a0cfcb45..4012cb75 100644 --- a/src/com/massivecraft/massivecore/mixin/MessageMixin.java +++ b/src/com/massivecraft/massivecore/mixin/MessageMixin.java @@ -4,7 +4,7 @@ import java.util.Collection; import org.bukkit.command.CommandSender; -import com.massivecraft.massivecore.Predicate; +import com.massivecraft.massivecore.predicate.Predicate; public interface MessageMixin { diff --git a/src/com/massivecraft/massivecore/mixin/MessageMixinAbstract.java b/src/com/massivecraft/massivecore/mixin/MessageMixinAbstract.java index fc7689e1..4dcdb9f1 100644 --- a/src/com/massivecraft/massivecore/mixin/MessageMixinAbstract.java +++ b/src/com/massivecraft/massivecore/mixin/MessageMixinAbstract.java @@ -6,7 +6,7 @@ import java.util.Collections; import org.bukkit.command.CommandSender; -import com.massivecraft.massivecore.Predicate; +import com.massivecraft.massivecore.predicate.Predicate; import com.massivecraft.massivecore.util.Txt; public abstract class MessageMixinAbstract implements MessageMixin diff --git a/src/com/massivecraft/massivecore/mixin/MessageMixinDefault.java b/src/com/massivecraft/massivecore/mixin/MessageMixinDefault.java index da53d875..7630c991 100644 --- a/src/com/massivecraft/massivecore/mixin/MessageMixinDefault.java +++ b/src/com/massivecraft/massivecore/mixin/MessageMixinDefault.java @@ -5,9 +5,9 @@ import java.util.Collection; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import com.massivecraft.massivecore.Predicate; import com.massivecraft.massivecore.mson.Mson; import com.massivecraft.massivecore.nms.NmsPacket; +import com.massivecraft.massivecore.predicate.Predicate; import com.massivecraft.massivecore.util.IdUtil; public class MessageMixinDefault extends MessageMixinAbstract diff --git a/src/com/massivecraft/massivecore/mixin/Mixin.java b/src/com/massivecraft/massivecore/mixin/Mixin.java index 95abdddb..16d66d78 100644 --- a/src/com/massivecraft/massivecore/mixin/Mixin.java +++ b/src/com/massivecraft/massivecore/mixin/Mixin.java @@ -13,9 +13,9 @@ import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.PlayerInventory; import org.bukkit.permissions.Permissible; -import com.massivecraft.massivecore.Predicate; import com.massivecraft.massivecore.event.EventMassiveCorePlayerLeave; import com.massivecraft.massivecore.mson.Mson; +import com.massivecraft.massivecore.predicate.Predicate; import com.massivecraft.massivecore.ps.PS; import com.massivecraft.massivecore.store.Coll; import com.massivecraft.massivecore.store.Entity; diff --git a/src/com/massivecraft/massivecore/mson/Mson.java b/src/com/massivecraft/massivecore/mson/Mson.java index d0361210..d4888094 100644 --- a/src/com/massivecraft/massivecore/mson/Mson.java +++ b/src/com/massivecraft/massivecore/mson/Mson.java @@ -15,11 +15,11 @@ import org.bukkit.command.CommandSender; import org.bukkit.inventory.ItemStack; import com.google.common.collect.ImmutableList; -import com.massivecraft.massivecore.Predicate; import com.massivecraft.massivecore.adapter.LowercaseEnumAdapter; import com.massivecraft.massivecore.collections.MassiveList; import com.massivecraft.massivecore.command.MassiveCommand; import com.massivecraft.massivecore.mixin.Mixin; +import com.massivecraft.massivecore.predicate.Predicate; import com.massivecraft.massivecore.util.MUtil; import com.massivecraft.massivecore.util.Txt; import com.massivecraft.massivecore.xlib.gson.Gson; diff --git a/src/com/massivecraft/massivecore/Predicate.java b/src/com/massivecraft/massivecore/predicate/Predicate.java similarity index 55% rename from src/com/massivecraft/massivecore/Predicate.java rename to src/com/massivecraft/massivecore/predicate/Predicate.java index b3909f3f..12a52a58 100644 --- a/src/com/massivecraft/massivecore/Predicate.java +++ b/src/com/massivecraft/massivecore/predicate/Predicate.java @@ -1,4 +1,4 @@ -package com.massivecraft.massivecore; +package com.massivecraft.massivecore.predicate; public interface Predicate { diff --git a/src/com/massivecraft/massivecore/PredicateAnd.java b/src/com/massivecraft/massivecore/predicate/PredicateAnd.java similarity index 93% rename from src/com/massivecraft/massivecore/PredicateAnd.java rename to src/com/massivecraft/massivecore/predicate/PredicateAnd.java index a622b07d..07b5bdcc 100644 --- a/src/com/massivecraft/massivecore/PredicateAnd.java +++ b/src/com/massivecraft/massivecore/predicate/PredicateAnd.java @@ -1,4 +1,4 @@ -package com.massivecraft.massivecore; +package com.massivecraft.massivecore.predicate; import java.util.Collection; import java.util.List; diff --git a/src/com/massivecraft/massivecore/PredicateEqualsIgnoreCase.java b/src/com/massivecraft/massivecore/predicate/PredicateEqualsIgnoreCase.java similarity index 96% rename from src/com/massivecraft/massivecore/PredicateEqualsIgnoreCase.java rename to src/com/massivecraft/massivecore/predicate/PredicateEqualsIgnoreCase.java index cc3ebdd9..ae734435 100644 --- a/src/com/massivecraft/massivecore/PredicateEqualsIgnoreCase.java +++ b/src/com/massivecraft/massivecore/predicate/PredicateEqualsIgnoreCase.java @@ -1,4 +1,4 @@ -package com.massivecraft.massivecore; +package com.massivecraft.massivecore.predicate; // Inspired by: String#regionMatches(ignoreCase, toffset, other, ooffset, len) public class PredicateEqualsIgnoreCase implements Predicate diff --git a/src/com/massivecraft/massivecore/PredicateIsRegistered.java b/src/com/massivecraft/massivecore/predicate/PredicateIsRegistered.java similarity index 81% rename from src/com/massivecraft/massivecore/PredicateIsRegistered.java rename to src/com/massivecraft/massivecore/predicate/PredicateIsRegistered.java index 200346a6..f90d2bbd 100644 --- a/src/com/massivecraft/massivecore/PredicateIsRegistered.java +++ b/src/com/massivecraft/massivecore/predicate/PredicateIsRegistered.java @@ -1,4 +1,6 @@ -package com.massivecraft.massivecore; +package com.massivecraft.massivecore.predicate; + +import com.massivecraft.massivecore.Registerable; public class PredicateIsRegistered implements Predicate { diff --git a/src/com/massivecraft/massivecore/PredicateIsntDefaultEntity.java b/src/com/massivecraft/massivecore/predicate/PredicateIsntDefaultEntity.java similarity index 89% rename from src/com/massivecraft/massivecore/PredicateIsntDefaultEntity.java rename to src/com/massivecraft/massivecore/predicate/PredicateIsntDefaultEntity.java index cec446db..6648591f 100644 --- a/src/com/massivecraft/massivecore/PredicateIsntDefaultEntity.java +++ b/src/com/massivecraft/massivecore/predicate/PredicateIsntDefaultEntity.java @@ -1,4 +1,4 @@ -package com.massivecraft.massivecore; +package com.massivecraft.massivecore.predicate; import com.massivecraft.massivecore.store.Entity; diff --git a/src/com/massivecraft/massivecore/PredicateStartsWithIgnoreCase.java b/src/com/massivecraft/massivecore/predicate/PredicateStartsWithIgnoreCase.java similarity index 96% rename from src/com/massivecraft/massivecore/PredicateStartsWithIgnoreCase.java rename to src/com/massivecraft/massivecore/predicate/PredicateStartsWithIgnoreCase.java index 467b0683..6c2337af 100644 --- a/src/com/massivecraft/massivecore/PredicateStartsWithIgnoreCase.java +++ b/src/com/massivecraft/massivecore/predicate/PredicateStartsWithIgnoreCase.java @@ -1,4 +1,4 @@ -package com.massivecraft.massivecore; +package com.massivecraft.massivecore.predicate; // Inspired by: String#regionMatches(ignoreCase, toffset, other, ooffset, len) public class PredicateStartsWithIgnoreCase implements Predicate diff --git a/src/com/massivecraft/massivecore/PredicateVisibleTo.java b/src/com/massivecraft/massivecore/predicate/PredicateVisibleTo.java similarity index 95% rename from src/com/massivecraft/massivecore/PredicateVisibleTo.java rename to src/com/massivecraft/massivecore/predicate/PredicateVisibleTo.java index fa72ac4f..8ea69081 100644 --- a/src/com/massivecraft/massivecore/PredicateVisibleTo.java +++ b/src/com/massivecraft/massivecore/predicate/PredicateVisibleTo.java @@ -1,4 +1,4 @@ -package com.massivecraft.massivecore; +package com.massivecraft.massivecore.predicate; import java.lang.ref.WeakReference; import org.bukkit.command.CommandSender; diff --git a/src/com/massivecraft/massivecore/store/Coll.java b/src/com/massivecraft/massivecore/store/Coll.java index 8156914e..8bedc5c8 100644 --- a/src/com/massivecraft/massivecore/store/Coll.java +++ b/src/com/massivecraft/massivecore/store/Coll.java @@ -16,8 +16,8 @@ import org.bukkit.plugin.Plugin; import com.massivecraft.massivecore.MassiveCore; import com.massivecraft.massivecore.MassiveCoreMConf; import com.massivecraft.massivecore.MassivePlugin; -import com.massivecraft.massivecore.NaturalOrderComparator; import com.massivecraft.massivecore.collections.MassiveList; +import com.massivecraft.massivecore.comparator.ComparatorNaturalOrder; import com.massivecraft.massivecore.mixin.Mixin; import com.massivecraft.massivecore.util.Txt; import com.massivecraft.massivecore.xlib.gson.Gson; @@ -33,7 +33,7 @@ public class Coll> extends CollAbstract public final static String TOTAL = "*total*"; // All instances registered here are considered inited. - private static Map> name2instance = new ConcurrentSkipListMap>(NaturalOrderComparator.get()); + private static Map> name2instance = new ConcurrentSkipListMap>(ComparatorNaturalOrder.get()); private static Map> umap = Collections.unmodifiableMap(name2instance); private static Set unames = Collections.unmodifiableSet(name2instance.keySet()); diff --git a/src/com/massivecraft/massivecore/store/CollAbstract.java b/src/com/massivecraft/massivecore/store/CollAbstract.java index 5a1e2605..86af65d8 100644 --- a/src/com/massivecraft/massivecore/store/CollAbstract.java +++ b/src/com/massivecraft/massivecore/store/CollAbstract.java @@ -5,7 +5,7 @@ import java.util.Comparator; import java.util.List; import java.util.Map.Entry; -import com.massivecraft.massivecore.Predicate; +import com.massivecraft.massivecore.predicate.Predicate; import com.massivecraft.massivecore.util.MUtil; import com.massivecraft.massivecore.xlib.gson.JsonObject; diff --git a/src/com/massivecraft/massivecore/store/CollInterface.java b/src/com/massivecraft/massivecore/store/CollInterface.java index e15e69b4..ea4a3038 100644 --- a/src/com/massivecraft/massivecore/store/CollInterface.java +++ b/src/com/massivecraft/massivecore/store/CollInterface.java @@ -9,7 +9,7 @@ import java.util.Map.Entry; import org.bukkit.plugin.Plugin; import com.massivecraft.massivecore.Named; -import com.massivecraft.massivecore.Predicate; +import com.massivecraft.massivecore.predicate.Predicate; import com.massivecraft.massivecore.xlib.gson.JsonObject; public interface CollInterface> extends Named diff --git a/src/com/massivecraft/massivecore/store/ComparatorEntityId.java b/src/com/massivecraft/massivecore/store/ComparatorEntityId.java index 6f16a8aa..c79dce73 100644 --- a/src/com/massivecraft/massivecore/store/ComparatorEntityId.java +++ b/src/com/massivecraft/massivecore/store/ComparatorEntityId.java @@ -2,7 +2,7 @@ package com.massivecraft.massivecore.store; import java.util.Comparator; -import com.massivecraft.massivecore.NaturalOrderComparator; +import com.massivecraft.massivecore.comparator.ComparatorNaturalOrder; public class ComparatorEntityId implements Comparator> { @@ -29,7 +29,7 @@ public class ComparatorEntityId implements Comparator> String id1 = e1.getId(); String id2 = e2.getId(); - int ret = NaturalOrderComparator.get().compare(id1, id2); + int ret = ComparatorNaturalOrder.get().compare(id1, id2); if (ret != 0) return ret; // We should only return 0 if the items actually are equal. diff --git a/src/com/massivecraft/massivecore/store/SenderColl.java b/src/com/massivecraft/massivecore/store/SenderColl.java index 32beecd5..8c223e1f 100644 --- a/src/com/massivecraft/massivecore/store/SenderColl.java +++ b/src/com/massivecraft/massivecore/store/SenderColl.java @@ -7,11 +7,11 @@ import java.util.List; import org.bukkit.command.CommandSender; import org.bukkit.plugin.Plugin; -import com.massivecraft.massivecore.Predicate; import com.massivecraft.massivecore.SenderPresence; import com.massivecraft.massivecore.SenderType; import com.massivecraft.massivecore.command.type.sender.TypeSenderEntity; import com.massivecraft.massivecore.command.type.sender.TypeSenderId; +import com.massivecraft.massivecore.predicate.Predicate; import com.massivecraft.massivecore.util.IdUtil; import com.massivecraft.massivecore.util.MUtil; diff --git a/src/com/massivecraft/massivecore/util/MUtil.java b/src/com/massivecraft/massivecore/util/MUtil.java index b1527f3f..2d6cbdf2 100644 --- a/src/com/massivecraft/massivecore/util/MUtil.java +++ b/src/com/massivecraft/massivecore/util/MUtil.java @@ -24,7 +24,6 @@ import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; -import com.massivecraft.massivecore.PredicateStartsWithIgnoreCase; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.DyeColor; @@ -59,16 +58,17 @@ import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.projectiles.ProjectileSource; -import com.massivecraft.massivecore.CaseInsensitiveComparator; import com.massivecraft.massivecore.MassiveCore; -import com.massivecraft.massivecore.Predicate; import com.massivecraft.massivecore.collections.MassiveList; import com.massivecraft.massivecore.collections.MassiveSet; import com.massivecraft.massivecore.collections.MassiveTreeSet; +import com.massivecraft.massivecore.comparator.ComparatorCaseInsensitive; import com.massivecraft.massivecore.engine.EngineMassiveCoreDatabase; import com.massivecraft.massivecore.engine.EngineMassiveCoreMain; import com.massivecraft.massivecore.engine.EngineMassiveCoreWorldNameSet; import com.massivecraft.massivecore.nms.NmsEntity; +import com.massivecraft.massivecore.predicate.Predicate; +import com.massivecraft.massivecore.predicate.PredicateStartsWithIgnoreCase; import com.massivecraft.massivecore.util.extractor.Extractor; import com.massivecraft.massivecore.util.extractor.ExtractorPlayer; import com.massivecraft.massivecore.util.extractor.ExtractorPlayerName; @@ -1501,7 +1501,7 @@ public class MUtil public static Set treeset(String... items) { - return new MassiveTreeSet(CaseInsensitiveComparator.get(), Arrays.asList(items)); + return new MassiveTreeSet(ComparatorCaseInsensitive.get(), Arrays.asList(items)); } @SuppressWarnings("unchecked") diff --git a/src/com/massivecraft/massivecore/util/ReflectionUtil.java b/src/com/massivecraft/massivecore/util/ReflectionUtil.java index ba5fc22c..8300f515 100644 --- a/src/com/massivecraft/massivecore/util/ReflectionUtil.java +++ b/src/com/massivecraft/massivecore/util/ReflectionUtil.java @@ -8,7 +8,7 @@ import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.List; -import com.massivecraft.massivecore.Predicate; +import com.massivecraft.massivecore.predicate.Predicate; public class ReflectionUtil { diff --git a/src/com/massivecraft/massivecore/util/Txt.java b/src/com/massivecraft/massivecore/util/Txt.java index f7c6aa2d..273659bc 100644 --- a/src/com/massivecraft/massivecore/util/Txt.java +++ b/src/com/massivecraft/massivecore/util/Txt.java @@ -19,11 +19,11 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -import com.massivecraft.massivecore.Predicate; -import com.massivecraft.massivecore.PredicateStartsWithIgnoreCase; import com.massivecraft.massivecore.collections.MassiveList; import com.massivecraft.massivecore.command.MassiveCommand; import com.massivecraft.massivecore.mson.Mson; +import com.massivecraft.massivecore.predicate.Predicate; +import com.massivecraft.massivecore.predicate.PredicateStartsWithIgnoreCase; import static com.massivecraft.massivecore.mson.Mson.mson;