MassiveCore - Comparators, Predicates and Map Editor
This commit is contained in:
parent
cd3a9e2bf2
commit
b3eab7df4c
@ -1,24 +0,0 @@
|
||||
package com.massivecraft.massivecore;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
public class CaseInsensitiveComparator implements Comparator<String>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// 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);
|
||||
}
|
||||
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
package com.massivecraft.massivecore;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class HashCodeComparator implements Comparator<Object>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// 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();
|
||||
}
|
||||
|
||||
}
|
@ -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<Prioritized>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// 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();
|
||||
}
|
||||
|
||||
}
|
@ -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<PriorityLines>
|
||||
@ -66,7 +67,7 @@ public class PriorityLines implements Prioritized, Comparable<PriorityLines>
|
||||
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;
|
||||
|
@ -1,36 +0,0 @@
|
||||
package com.massivecraft.massivecore;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
public class ReversePriorityComparator implements Comparator<Prioritized>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// 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;
|
||||
}
|
||||
|
||||
}
|
@ -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<T>
|
||||
{
|
||||
@ -13,7 +13,7 @@ public class ExceptionSet<T>
|
||||
public boolean standard = true;
|
||||
public boolean isStandard() { return this.standard; }
|
||||
|
||||
public MassiveTreeSet<String, CaseInsensitiveComparator> exceptions = new MassiveTreeSet<String, CaseInsensitiveComparator>(CaseInsensitiveComparator.get());
|
||||
public MassiveTreeSet<String, ComparatorCaseInsensitive> exceptions = new MassiveTreeSet<String, ComparatorCaseInsensitive>(ComparatorCaseInsensitive.get());
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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<O, V> extends MassiveCommand
|
||||
@ -109,7 +108,7 @@ public class CommandEditAbstract<O, V> extends MassiveCommand
|
||||
|
||||
// NoChange
|
||||
// We check, inform and cancel on equality.
|
||||
if (MUtil.equals(before, after))
|
||||
if (this.getValueType().equals(before, after, true))
|
||||
{
|
||||
msg("%s<silver> for %s<silver> already: %s", descProperty, descObject, descValue);
|
||||
return;
|
||||
|
@ -1,34 +0,0 @@
|
||||
package com.massivecraft.massivecore.command.editor;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class CommandEditCollection<O, V extends Collection<?>> extends CommandEditAbstract<O, V>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CommandEditCollection(EditSettings<O> settings, Property<O, V> property)
|
||||
{
|
||||
// Super
|
||||
super(settings, property, null);
|
||||
|
||||
// Children
|
||||
this.addChild(new CommandEditShow<O, V>(settings, property));
|
||||
|
||||
if (property.isNullable())
|
||||
{
|
||||
this.addChild(new CommandEditCreate<O, V>(settings, property));
|
||||
this.addChild(new CommandEditDelete<O, V>(settings, property));
|
||||
}
|
||||
|
||||
this.addChild(new CommandEditCollectionAdd<O, V>(settings, property));
|
||||
this.addChild(new CommandEditCollectionInsert<O, V>(settings, property));
|
||||
this.addChild(new CommandEditCollectionSet<O, V>(settings, property));
|
||||
this.addChild(new CommandEditCollectionRemove<O, V>(settings, property));
|
||||
this.addChild(new CommandEditCollectionMove<O, V>(settings, property));
|
||||
this.addChild(new CommandEditCollectionSwap<O, V>(settings, property));
|
||||
this.addChild(new CommandEditCollectionClear<O, V>(settings, property));
|
||||
}
|
||||
|
||||
}
|
@ -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<O, V extends Collection<?>> extends CommandEditAbstract<O, V>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CommandEditCollectionAbstract(EditSettings<O> settings, Property<O, V> 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<Object> after = this.getShallowCopy();
|
||||
|
||||
// Alter
|
||||
try
|
||||
{
|
||||
this.alter(after);
|
||||
}
|
||||
catch (MassiveException e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new MassiveException().addMsg("<b>%s", e.getMessage());
|
||||
}
|
||||
|
||||
// Apply
|
||||
Collection<Object> toSet = null;
|
||||
if (after != null)
|
||||
{
|
||||
toSet = (Collection<Object>) this.getProperty().getValueType().createNewInstance();
|
||||
toSet.addAll(after);
|
||||
}
|
||||
|
||||
this.attemptSet((V) toSet);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// ABSTRACT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public abstract void alter(List<Object> list) throws MassiveException;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// UTIL
|
||||
// -------------------------------------------- //
|
||||
|
||||
public List<Object> getShallowCopy()
|
||||
{
|
||||
V ret = this.getProperty().getRaw(this.getObject());
|
||||
if (ret == null) return null;
|
||||
return new MassiveList<Object>(ret);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.massivecraft.massivecore.command.editor;
|
||||
|
||||
public class CommandEditContainer<O, V> extends CommandEditAbstract<O, V>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CommandEditContainer(EditSettings<O> settings, Property<O, V> property)
|
||||
{
|
||||
// Super
|
||||
super(settings, property, null);
|
||||
|
||||
// Children
|
||||
this.addChild(new CommandEditShow<O, V>(settings, property));
|
||||
|
||||
if (property.isNullable())
|
||||
{
|
||||
this.addChild(new CommandEditCreate<O, V>(settings, property));
|
||||
this.addChild(new CommandEditDelete<O, V>(settings, property));
|
||||
}
|
||||
|
||||
this.addChild(new CommandEditContainerAdd<O, V>(settings, property));
|
||||
this.addChild(new CommandEditContainerInsert<O, V>(settings, property));
|
||||
this.addChild(new CommandEditContainerSet<O, V>(settings, property));
|
||||
this.addChild(new CommandEditContainerRemove<O, V>(settings, property));
|
||||
this.addChild(new CommandEditContainerRemoveIndex<O, V>(settings, property));
|
||||
|
||||
if ( ! property.getValueType().isContainerSorted() && property.getValueType().getContainerComparator() == null)
|
||||
{
|
||||
this.addChild(new CommandEditContainerMove<O, V>(settings, property));
|
||||
this.addChild(new CommandEditContainerSwap<O, V>(settings, property));
|
||||
}
|
||||
|
||||
this.addChild(new CommandEditContainerClear<O, V>(settings, property));
|
||||
}
|
||||
|
||||
}
|
@ -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<O, V> extends CommandEditAbstract<O, V>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CommandEditContainerAbstract(EditSettings<O> settings, Property<O, V> 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<Object> elements = this.getValueType().getContainerElementsOrdered(container);
|
||||
|
||||
// Alter
|
||||
try
|
||||
{
|
||||
this.alter(elements);
|
||||
}
|
||||
catch (MassiveException e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new MassiveException().addMsg("<b>%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<Object> elements) throws MassiveException;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// MAP
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean isCollection()
|
||||
{
|
||||
Type<V> 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<V> type = this.getValueType();
|
||||
Type<Object> innerType = type.getInnerType();
|
||||
|
||||
if (type.isContainerCollection())
|
||||
{
|
||||
this.addParameter(innerType, innerType.getTypeName(), true);
|
||||
}
|
||||
else if (type.isContainerMap())
|
||||
{
|
||||
Type<Object> keyType = innerType.getInnerType(0);
|
||||
Type<Object> 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<Object, Object>(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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<O, V extends Collection<?>> extends CommandEditCollectionAbstract<O, V>
|
||||
public class CommandEditContainerAdd<O, V> extends CommandEditContainerAbstract<O, V>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CommandEditCollectionAdd(EditSettings<O> settings, Property<O, V> property)
|
||||
public CommandEditContainerAdd(EditSettings<O> settings, Property<O, V> property)
|
||||
{
|
||||
// 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<O, V extends Collection<?>> extends Comman
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void alter(List<Object> list) throws MassiveException
|
||||
public void alter(List<Object> elements) throws MassiveException
|
||||
{
|
||||
// Args
|
||||
Object element = this.readArg();
|
||||
Object element = this.readElement();
|
||||
|
||||
// Alter
|
||||
list.add(element);
|
||||
elements.add(element);
|
||||
}
|
||||
|
||||
}
|
@ -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<O, V extends Collection<?>> extends CommandEditCollectionAbstract<O, V>
|
||||
public class CommandEditContainerClear<O, V> extends CommandEditContainerAbstract<O, V>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CommandEditCollectionClear(EditSettings<O> settings, Property<O, V> property)
|
||||
public CommandEditContainerClear(EditSettings<O> settings, Property<O, V> property)
|
||||
{
|
||||
// Super
|
||||
super(settings, property);
|
||||
|
||||
// Aliases
|
||||
this.setAliases("clear");
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
@ -22,10 +24,10 @@ public class CommandEditCollectionClear<O, V extends Collection<?>> extends Comm
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void alter(List<Object> list) throws MassiveException
|
||||
public void alter(List<Object> elements) throws MassiveException
|
||||
{
|
||||
// Apply
|
||||
list.clear();
|
||||
elements.clear();
|
||||
}
|
||||
|
||||
}
|
@ -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<O, V extends Collection<?>> extends CommandEditCollectionAbstract<O, V>
|
||||
public class CommandEditContainerInsert<O, V> extends CommandEditContainerAbstract<O, V>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CommandEditCollectionSet(EditSettings<O> settings, Property<O, V> property)
|
||||
public CommandEditContainerInsert(EditSettings<O> settings, Property<O, V> 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<O, V extends Collection<?>> extends Comman
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void alter(List<Object> list) throws MassiveException
|
||||
public void alter(List<Object> 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);
|
||||
}
|
||||
|
||||
}
|
@ -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<O, V extends Collection<?>> extends CommandEditCollectionAbstract<O, V>
|
||||
public class CommandEditContainerMove<O, V> extends CommandEditContainerAbstract<O, V>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CommandEditCollectionMove(EditSettings<O> settings, Property<O, V> property)
|
||||
public CommandEditContainerMove(EditSettings<O> settings, Property<O, V> 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<O, V extends Collection<?>> extends Comma
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void alter(List<Object> list) throws MassiveException
|
||||
public void alter(List<Object> 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);
|
||||
}
|
||||
|
||||
}
|
@ -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<O, V> extends CommandEditContainerAbstract<O, V>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CommandEditContainerRemove(EditSettings<O> settings, Property<O, V> property)
|
||||
{
|
||||
// Super
|
||||
super(settings, property);
|
||||
|
||||
// Aliases
|
||||
this.setAliases("remove");
|
||||
|
||||
// Parameters
|
||||
this.addParametersElement(false);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void alter(List<Object> elements) throws MassiveException
|
||||
{
|
||||
if (this.isCollection())
|
||||
{
|
||||
this.alterCollection(elements);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.alterMap(elements);
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE > COLLECTION
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void alterCollection(List<Object> elements) throws MassiveException
|
||||
{
|
||||
// Args
|
||||
Object element = this.readElement();
|
||||
|
||||
// Alter
|
||||
Iterator<Object> 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<Object> elements) throws MassiveException
|
||||
{
|
||||
// Args
|
||||
Object key = this.readArg();
|
||||
Object value = this.readArg();
|
||||
|
||||
// Validate
|
||||
if (key == null && value == null) throw new MassiveException().addMsg("<b>Please supply key and/or value.");
|
||||
|
||||
// Alter
|
||||
Iterator<Object> iterator = elements.iterator();
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
Entry<Object, Object> other = (Entry<Object, Object>) iterator.next();
|
||||
|
||||
if (key != null && ! MUtil.equals(key, other.getKey())) continue;
|
||||
if (value != null && ! MUtil.equals(value, other.getValue())) continue;
|
||||
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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<O, V extends Collection<?>> extends CommandEditCollectionAbstract<O, V>
|
||||
public class CommandEditContainerRemoveIndex<O, V> extends CommandEditContainerAbstract<O, V>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CommandEditCollectionRemove(EditSettings<O> settings, Property<O, V> property)
|
||||
public CommandEditContainerRemoveIndex(EditSettings<O> settings, Property<O, V> property)
|
||||
{
|
||||
// Super
|
||||
super(settings, property);
|
||||
|
||||
// Aliases
|
||||
this.setAliases("removeIndex");
|
||||
|
||||
// Parameters
|
||||
this.addParameter(TypeInteger.get(), "index");
|
||||
}
|
||||
@ -26,13 +28,13 @@ public class CommandEditCollectionRemove<O, V extends Collection<?>> extends Com
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void alter(List<Object> list) throws MassiveException
|
||||
public void alter(List<Object> elements) throws MassiveException
|
||||
{
|
||||
// Args
|
||||
int index = this.readArg();
|
||||
|
||||
// Alter
|
||||
list.remove(index);
|
||||
elements.remove(index);
|
||||
}
|
||||
|
||||
}
|
@ -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<O, V extends Collection<?>> extends CommandEditCollectionAbstract<O, V>
|
||||
public class CommandEditContainerSet<O, V> extends CommandEditContainerAbstract<O, V>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CommandEditCollectionInsert(EditSettings<O> settings, Property<O, V> property)
|
||||
public CommandEditContainerSet(EditSettings<O> settings, Property<O, V> 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<O, V extends Collection<?>> extends Com
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void alter(List<Object> list) throws MassiveException
|
||||
public void alter(List<Object> 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);
|
||||
}
|
||||
|
||||
}
|
@ -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<O, V extends Collection<?>> extends CommandEditCollectionAbstract<O, V>
|
||||
public class CommandEditContainerSwap<O, V> extends CommandEditContainerAbstract<O, V>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CommandEditCollectionSwap(EditSettings<O> settings, Property<O, V> property)
|
||||
public CommandEditContainerSwap(EditSettings<O> settings, Property<O, V> 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<O, V extends Collection<?>> extends Comma
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void alter(List<Object> list) throws MassiveException
|
||||
public void alter(List<Object> 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);
|
||||
}
|
||||
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
package com.massivecraft.massivecore.command.editor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class CommandEditMap<O, V extends Map<?, ?>> extends CommandEditAbstract<O, V>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CommandEditMap(EditSettings<O> settings, Property<O, V> property)
|
||||
{
|
||||
// Super
|
||||
super(settings, property, null);
|
||||
|
||||
// Children
|
||||
this.addChild(new CommandEditShow<O, V>(settings, property));
|
||||
|
||||
if (property.isNullable())
|
||||
{
|
||||
this.addChild(new CommandEditCreate<O, V>(settings, property));
|
||||
this.addChild(new CommandEditDelete<O, V>(settings, property));
|
||||
}
|
||||
|
||||
this.addChild(new CommandEditMapPut<O, V>(settings, property));
|
||||
this.addChild(new CommandEditMapRemove<O, V>(settings, property));
|
||||
this.addChild(new CommandEditMapClear<O, V>(settings, property));
|
||||
}
|
||||
|
||||
}
|
@ -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<O, V extends Map<?, ?>> extends CommandEditAbstract<O, V>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CommandEditMapAbstract(EditSettings<O> settings, Property<O, V> 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<Object> getMapKeyType()
|
||||
{
|
||||
return this.getProperty().getValueType().getInnerType(0);
|
||||
}
|
||||
|
||||
public Type<Object> getMapValueType()
|
||||
{
|
||||
return this.getProperty().getValueType().getInnerType(1);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void perform() throws MassiveException
|
||||
{
|
||||
// Create
|
||||
Map<Object, Object> after = this.getShallowCopy();
|
||||
|
||||
// Alter
|
||||
try
|
||||
{
|
||||
this.alter(after);
|
||||
}
|
||||
catch (MassiveException e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new MassiveException().addMsg("<b>%s", e.getMessage());
|
||||
}
|
||||
|
||||
// Apply
|
||||
this.attemptSet((V) after);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// ABSTRACT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public abstract void alter(Map<Object, Object> map) throws MassiveException;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// UTIL
|
||||
// -------------------------------------------- //
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<Object, Object> getShallowCopy()
|
||||
{
|
||||
// Create
|
||||
V ret = this.getProperty().getRaw(this.getObject());
|
||||
if (ret == null) return null;
|
||||
|
||||
// Fill
|
||||
Map<Object, Object> copy = (Map<Object, Object>) this.getProperty().getValueType().createNewInstance();
|
||||
for (Map.Entry<Object, Object> entry : ((Map<Object, Object>) ret).entrySet())
|
||||
{
|
||||
copy.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
// Return
|
||||
return copy;
|
||||
}
|
||||
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
package com.massivecraft.massivecore.command.editor;
|
||||
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class CommandEditMapClear<O, V extends Map<?,?>> extends CommandEditMapAbstract<O, V>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CommandEditMapClear(EditSettings<O> settings, Property<O, V> property)
|
||||
{
|
||||
// Super
|
||||
super(settings, property);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void alter(Map<Object, Object> map) throws MassiveException
|
||||
{
|
||||
// Alter
|
||||
map.clear();
|
||||
}
|
||||
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
package com.massivecraft.massivecore.command.editor;
|
||||
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class CommandEditMapPut<O, V extends Map<?,?>> extends CommandEditMapAbstract<O, V>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CommandEditMapPut(EditSettings<O> settings, Property<O, V> 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<Object, Object> map) throws MassiveException
|
||||
{
|
||||
// Args
|
||||
Object key = this.readArg();
|
||||
Object value = this.readArg();
|
||||
|
||||
// Alter
|
||||
map.put(key, value);
|
||||
}
|
||||
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
package com.massivecraft.massivecore.command.editor;
|
||||
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class CommandEditMapRemove<O, V extends Map<?,?>> extends CommandEditMapAbstract<O, V>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CommandEditMapRemove(EditSettings<O> settings, Property<O, V> property)
|
||||
{
|
||||
// Super
|
||||
super(settings, property);
|
||||
|
||||
// Parameters
|
||||
this.addParameter(this.getMapKeyType(), this.getMapKeyType().getTypeName(), true);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void alter(Map<Object, Object> map) throws MassiveException
|
||||
{
|
||||
// Args
|
||||
Object key = this.readArg();
|
||||
|
||||
// Alter
|
||||
map.remove(key);
|
||||
}
|
||||
|
||||
}
|
@ -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
|
||||
{
|
||||
|
@ -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<String> collnames = new TreeSet<String>(NaturalOrderComparator.get());
|
||||
Set<String> collnames = new TreeSet<String>(ComparatorNaturalOrder.get());
|
||||
collnames.addAll(db.getCollnames());
|
||||
|
||||
// Do it!
|
||||
|
@ -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<CommandSender>
|
||||
{
|
||||
|
@ -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<T>
|
||||
// INNER
|
||||
// -------------------------------------------- //
|
||||
|
||||
public <I extends Type<X>, X extends Object> List<I> getInnerTypes();
|
||||
public <I> Type<I> getInnerType(int index);
|
||||
public <I> Type<I> getInnerType();
|
||||
public <I extends Type<? extends Object>> List<I> getInnerTypes();
|
||||
public <I extends Type<? extends Object>> I getInnerType(int index);
|
||||
public <I extends Type<? extends Object>> I getInnerType();
|
||||
|
||||
public void setInnerTypes(Collection<Type<?>> innerTypes);
|
||||
public void setInnerTypes(Type<?>... innerTypes);
|
||||
@ -106,6 +106,42 @@ public interface Type<T>
|
||||
// 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 <E> Comparator<E> getContainerComparator();
|
||||
public void setContainerComparator(Comparator<?> container);
|
||||
|
||||
public <E> List<E> getContainerElementsOrdered(Iterable<E> elements);
|
||||
public <E> List<E> getContainerElementsOrdered(T container);
|
||||
|
||||
public boolean isContainerEmpty(T container);
|
||||
public void clearContainer(T container);
|
||||
|
||||
public <E> Collection<E> getContainerElements(T container);
|
||||
public <E> void setContainerElements(T container, Iterable<E> elements);
|
||||
|
||||
public <E> boolean addContainerElement(T container, E element);
|
||||
public <E> void addContainerElements(T container, Iterable<E> elements);
|
||||
|
||||
// -------------------------------------------- //
|
||||
// EQUALS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean equals(T type1, T type2, boolean strict);
|
||||
public boolean equalsInner(T type1, T type2, boolean strict);
|
||||
|
||||
// -------------------------------------------- //
|
||||
// EDITOR
|
||||
// -------------------------------------------- //
|
||||
|
@ -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<T> implements Type<T>
|
||||
@ -61,10 +69,10 @@ public abstract class TypeAbstract<T> implements Type<T>
|
||||
protected List<Type<Object>> innerTypes = new MassiveList<Type<Object>>();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <I extends Type<X>, X extends Object> List<I> getInnerTypes() { return (List<I>) this.innerTypes; }
|
||||
public <I extends Type<? extends Object>> List<I> getInnerTypes() { return (List<I>) this.innerTypes; }
|
||||
@SuppressWarnings("unchecked")
|
||||
public <I> Type<I> getInnerType(int index) { return (Type<I>) this.getInnerTypes().get(index); }
|
||||
public <I> Type<I> getInnerType() { return this.getInnerType(0); }
|
||||
public <I extends Type<? extends Object>> I getInnerType(int index) { return (I) this.getInnerTypes().get(index); }
|
||||
public <I extends Type<? extends Object>> I getInnerType() { return this.getInnerType(0); }
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public void setInnerTypes(Collection<Type<?>> innerTypes) { this.innerTypes = new MassiveList(innerTypes); }
|
||||
@ -393,6 +401,197 @@ public abstract class TypeAbstract<T> implements Type<T>
|
||||
return new ArrayList<String>(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<Object> elementComparator = null;
|
||||
@SuppressWarnings("unchecked")
|
||||
public <E> Comparator<E> getContainerComparator()
|
||||
{
|
||||
if (this.elementComparator != null) return (Comparator<E>) this.elementComparator;
|
||||
if (this.isContainerIndexed()) return null;
|
||||
return (Comparator<E>) ComparatorHashCode.get().getLenient();
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setContainerComparator(Comparator<?> comparator) { this.elementComparator = (Comparator<Object>) comparator; }
|
||||
|
||||
public <E> List<E> getContainerElementsOrdered(Iterable<E> elements)
|
||||
{
|
||||
if (elements == null) return null;
|
||||
|
||||
List<E> ret;
|
||||
if (elements instanceof Collection<?>)
|
||||
{
|
||||
ret = new MassiveList<E>((Collection<E>)elements);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = new MassiveList<E>();
|
||||
for (E element : elements)
|
||||
{
|
||||
ret.add(element);
|
||||
}
|
||||
}
|
||||
|
||||
Comparator<E> elementComparator = this.getContainerComparator();
|
||||
if (elementComparator != null) ret.sort(elementComparator);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> List<E> getContainerElementsOrdered(T container)
|
||||
{
|
||||
Collection<E> 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 <E> Collection<E> getContainerElements(T container)
|
||||
{
|
||||
if (container instanceof Collection<?>)
|
||||
{
|
||||
Collection<E> collection = (Collection<E>)container;
|
||||
return collection;
|
||||
}
|
||||
|
||||
if (container instanceof Map<?, ?>)
|
||||
{
|
||||
Map<?, ?> map = (Map<?, ?>)container;
|
||||
return (Collection<E>) map.entrySet();
|
||||
}
|
||||
|
||||
throw new UnsupportedOperationException("not implemented");
|
||||
}
|
||||
|
||||
public <E> void setContainerElements(T container, Iterable<E> elements)
|
||||
{
|
||||
this.clearContainer(container);
|
||||
this.addContainerElements(container, elements);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <E> boolean addContainerElement(T container, E element)
|
||||
{
|
||||
if (container instanceof Collection<?>)
|
||||
{
|
||||
Collection<E> collection = (Collection<E>)container;
|
||||
return collection.add(element);
|
||||
}
|
||||
|
||||
if (container instanceof Map<?, ?>)
|
||||
{
|
||||
Map<Object, Object> map = (Map<Object, Object>)container;
|
||||
Entry<Object, Object> entry = (Entry<Object, Object>)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 <E> void addContainerElements(T container, Iterable<E> 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<T> implements Type<T>
|
||||
|
||||
public T createNewInstance()
|
||||
{
|
||||
throw new RuntimeException("Not implemented");
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<T> extends TypeAbstract<T> implements A
|
||||
public Set<String> createTabs(T value)
|
||||
{
|
||||
// Create
|
||||
Set<String> ret = new MassiveTreeSet<String, CaseInsensitiveComparator>(CaseInsensitiveComparator.get());
|
||||
Set<String> ret = new MassiveTreeSet<String, ComparatorCaseInsensitive>(ComparatorCaseInsensitive.get());
|
||||
|
||||
// Fill
|
||||
String string;
|
||||
|
@ -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<T> extends TypeAbstract<T> implements AllAble<T>
|
||||
|
@ -13,10 +13,10 @@ public class TypeWrapper<T> extends TypeAbstract<T>
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public TypeWrapper(Type<T> inner)
|
||||
public TypeWrapper(Type<T> 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<T> extends TypeAbstract<T>
|
||||
@Override
|
||||
public String getVisualInner(T value, CommandSender sender)
|
||||
{
|
||||
return this.getInnerType().getVisualInner(value, sender);
|
||||
Type<T> innerType = this.getInnerType();
|
||||
return innerType.getVisualInner(value, sender);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNameInner(T value)
|
||||
{
|
||||
return this.getInnerType().getNameInner(value);
|
||||
Type<T> innerType = this.getInnerType();
|
||||
return innerType.getNameInner(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdInner(T value)
|
||||
{
|
||||
return this.getInnerType().getIdInner(value);
|
||||
Type<T> innerType = this.getInnerType();
|
||||
return innerType.getIdInner(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -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<K,V> extends TypeMapAbstract<Map<K, V>, K, V>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static <K,V> TypeMap<K,V> get(Type<K> keyType, Type<V> valueType)
|
||||
{
|
||||
return new TypeMap<K,V>(keyType, valueType);
|
||||
}
|
||||
|
||||
public TypeMap(Type<K> keyType, Type<V> valueType)
|
||||
{
|
||||
super(keyType, valueType);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public HashMap<K,V> createNewInstance()
|
||||
{
|
||||
return new MassiveMap<K,V>();
|
||||
}
|
||||
|
||||
}
|
@ -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<C extends Map<K, V>, K, V> extends TypeAbstract<C>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public TypeMapAbstract(Type<K> mapKeyType, Type<V> mapValueType)
|
||||
{
|
||||
this.setInnerTypes(mapKeyType, mapValueType);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// INNER TYPES
|
||||
// -------------------------------------------- //
|
||||
|
||||
public Type<K> getMapKeyType() { return this.getInnerType(0); }
|
||||
public Type<V> 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<String> parts = new MassiveList<String>();
|
||||
|
||||
for (Entry<K,V> 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("<silver># <key>%s<silver>: <value>%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<K,V> 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<K,V> 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<String> args = new MassiveList<>(Txt.PATTERN_WHITESPACE.split(arg));
|
||||
if (args.size() % 2 != 0)
|
||||
{
|
||||
throw new MassiveException().setMsg("<b>There must be an even amount of arguments for a map.");
|
||||
}
|
||||
|
||||
// Fill
|
||||
for (Iterator<String> 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<String> 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<String> 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<String> 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<String> 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 <O> CommandEditAbstract<O, C> createEditCommand(EditSettings<O> settings, Property<O, C> property)
|
||||
{
|
||||
return new CommandEditMap<O, C>(settings, property);
|
||||
}
|
||||
|
||||
}
|
@ -16,25 +16,18 @@ import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
public abstract class TypeCombined<T> extends TypeAbstract<T>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
protected List<Type<?>> types;
|
||||
public List<Type<?>> getTypes() { return this.types; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public TypeCombined(Collection<Type<?>> types)
|
||||
public TypeCombined(Collection<Type<?>> innerTypes)
|
||||
{
|
||||
this.types = new MassiveList<Type<?>>(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<T> extends TypeAbstract<T>
|
||||
|
||||
// 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<Type<?>, Object> entry = new SimpleEntry<Type<?>, Object>(type, part);
|
||||
ret.add(entry);
|
||||
@ -76,7 +69,7 @@ public abstract class TypeCombined<T> extends TypeAbstract<T>
|
||||
List<String> parts = new MassiveList<String>();
|
||||
|
||||
// Fill
|
||||
for (Type<?> type : this.getTypes())
|
||||
for (Type<?> type : this.getInnerTypes())
|
||||
{
|
||||
parts.add(type.getTypeName());
|
||||
}
|
||||
@ -157,7 +150,7 @@ public abstract class TypeCombined<T> extends TypeAbstract<T>
|
||||
// Fill
|
||||
List<String> argParts = Arrays.asList(arg.split("[, ]+"));
|
||||
|
||||
if (argParts.size() > this.getTypes().size())
|
||||
if (argParts.size() > this.getInnerTypes().size())
|
||||
{
|
||||
throw new MassiveException().addMsg("<b>Too many parts!");
|
||||
}
|
||||
@ -165,7 +158,7 @@ public abstract class TypeCombined<T> extends TypeAbstract<T>
|
||||
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);
|
||||
|
||||
|
@ -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<K, V> extends TypeCombined<Entry<K, V>>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static <K, V> TypeEntry<K, V> get(Type<K> keyType, Type<V> valueType) { return new TypeEntry<K, V>(keyType, valueType); }
|
||||
public TypeEntry(Type<K> keyType, Type<V> valueType)
|
||||
{
|
||||
super(keyType, valueType);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// INNER TYPES
|
||||
// -------------------------------------------- //
|
||||
|
||||
public Type<K> getKeyType() { return this.getInnerType(0); }
|
||||
public Type<V> getValueType() { return this.getInnerType(1); }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String getTypeName()
|
||||
{
|
||||
return this.getKeyType().getTypeName() + " and " + this.getValueType().getTypeName();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Entry<K, V> combine(List<Object> 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<K, V>(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Object> split(Entry<K, V> entry)
|
||||
{
|
||||
return new MassiveList<Object>(
|
||||
entry.getKey(),
|
||||
entry.getValue()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equalsInner(Entry<K, V> type1, Entry<K, V> 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;
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.massivecraft.massivecore.command.type.collection;
|
||||
package com.massivecraft.massivecore.command.type.container;
|
||||
|
||||
import java.util.Collection;
|
||||
|
@ -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<C extends Collection<E>, E> extends TypeAbstract<C>
|
||||
public abstract class TypeContainer<C extends Object, E> extends TypeAbstract<C>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public TypeCollection(Type<E> innerType)
|
||||
public TypeContainer(Type<E> innerType)
|
||||
{
|
||||
this.setInnerType(innerType);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// META
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
@ -39,41 +39,56 @@ public abstract class TypeCollection<C extends Collection<E>, 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<String> parts = new MassiveList<String>();
|
||||
|
||||
// Fill
|
||||
List<E> elements = this.getContainerElementsOrdered(container);
|
||||
Type<E> innerType = this.getInnerType();
|
||||
int index = -1;
|
||||
for (E element : value)
|
||||
for (E element : elements)
|
||||
{
|
||||
index++;
|
||||
String part = Txt.parse("<white>%d <yellow>%s", index, this.getInnerType().getVisualInner(element, sender));
|
||||
String part = Txt.parse("<white>%d <yellow>%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<String> parts = new MassiveList<String>();
|
||||
|
||||
// Fill
|
||||
for (E element : value)
|
||||
List<E> elements = this.getContainerElementsOrdered(container);
|
||||
Type<E> 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<C extends Collection<E>, 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<String> parts = new MassiveList<String>();
|
||||
|
||||
// Fill
|
||||
for (E element : value)
|
||||
List<E> elements = this.getContainerElementsOrdered(container);
|
||||
Type<E> 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<C extends Collection<E>, 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<C extends Collection<E>, E> extends TypeAbs
|
||||
AllAble<E> allAble = (AllAble<E>)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<C extends Collection<E>, E> extends TypeAbs
|
||||
{
|
||||
Type<E> innerType = this.getInnerType();
|
||||
E element = innerType.read(elementArg, sender);
|
||||
ret.add(element);
|
||||
this.addContainerElement(ret, element);
|
||||
}
|
||||
|
||||
// Return
|
||||
return ret;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// TAB LIST
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Collection<String> getTabList(CommandSender sender, String arg)
|
||||
{
|
||||
@ -154,14 +183,42 @@ public abstract class TypeCollection<C extends Collection<E>, E> extends TypeAbs
|
||||
return this.getInnerType().allowSpaceAfterTab();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// EQUALS
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public <O> CommandEditAbstract<O, C> createEditCommand(EditSettings<O> settings, Property<O, C> property)
|
||||
public boolean equalsInner(C container1, C container2, boolean strict)
|
||||
{
|
||||
return new CommandEditCollection<O, C>(settings, property);
|
||||
List<E> ordered1 = this.getContainerElementsOrdered(container1);
|
||||
List<E> ordered2 = this.getContainerElementsOrdered(container2);
|
||||
|
||||
if (ordered1.size() != ordered2.size()) return false;
|
||||
|
||||
Type<E> 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 <O> CommandEditAbstract<O, C> createEditCommand(EditSettings<O> settings, Property<O, C> property)
|
||||
{
|
||||
return new CommandEditContainer<O, C>(settings, property);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// ARGS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static List<String> getArgs(String string)
|
@ -1,4 +1,4 @@
|
||||
package com.massivecraft.massivecore.command.type.collection;
|
||||
package com.massivecraft.massivecore.command.type.container;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -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<E> extends TypeCollection<List<E>, E>
|
||||
public class TypeList<E> extends TypeContainer<List<E>, E>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
@ -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<K, V> extends TypeContainer<Map<K, V>, Entry<K, V>>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static <K, V> TypeMap<K, V> get(Type<K> keyType, Type<V> valueType)
|
||||
{
|
||||
return new TypeMap<K, V>(keyType, valueType);
|
||||
}
|
||||
|
||||
public TypeMap(Type<K> keyType, Type<V> valueType)
|
||||
{
|
||||
super(TypeEntry.get(keyType, valueType));
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// INNER TYPES
|
||||
// -------------------------------------------- //
|
||||
|
||||
public TypeEntry<K, V> getEntryType() { return this.getInnerType(); }
|
||||
public Type<K> getKeyType() { return this.getEntryType().getKeyType(); }
|
||||
public Type<V> getValueType() { return this.getEntryType().getValueType(); }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String getCollectionTypeName()
|
||||
{
|
||||
return "Map";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<K, V> createNewInstance()
|
||||
{
|
||||
return new MassiveMap<K, V>();
|
||||
}
|
||||
|
||||
}
|
@ -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<E> extends TypeCollection<Set<E>, E>
|
||||
public class TypeSet<E> extends TypeContainer<Set<E>, E>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
@ -0,0 +1,61 @@
|
||||
package com.massivecraft.massivecore.comparator;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
|
||||
public class ComparatorAbstract<T> implements Comparator<T>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// REVERSED
|
||||
// -------------------------------------------- //
|
||||
|
||||
private ComparatorReversed<T> reversed = null;
|
||||
public ComparatorAbstract<T> getReversed()
|
||||
{
|
||||
if (this.reversed == null) this.reversed = ComparatorReversed.get(this);
|
||||
return this.reversed;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// LENIENT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private ComparatorLenient<T> lenient = null;
|
||||
public ComparatorAbstract<T> 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");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package com.massivecraft.massivecore.comparator;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
public abstract class ComparatorAbstractTransformer<T, X> extends ComparatorAbstractWrapper<T, X>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public ComparatorAbstractTransformer(Comparator<X> 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);
|
||||
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.massivecraft.massivecore.comparator;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
public abstract class ComparatorAbstractWrapper<T, X> extends ComparatorAbstract<T>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
private Comparator<X> comparator;
|
||||
public Comparator<X> getComparator() { return this.comparator; }
|
||||
public void setComparator(Comparator<X> comparator) { this.comparator = comparator; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public ComparatorAbstractWrapper(Comparator<X> comparator)
|
||||
{
|
||||
this.comparator = comparator;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.massivecraft.massivecore.comparator;
|
||||
|
||||
public class ComparatorCaseInsensitive extends ComparatorAbstract<String>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// 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);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package com.massivecraft.massivecore.comparator;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class ComparatorEntryKey<K, V> extends ComparatorAbstractTransformer<Entry<K, V>, K>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static <K, V> ComparatorEntryKey<K, V> get(Comparator<K> comparator) { return new ComparatorEntryKey<K, V>(comparator); }
|
||||
public ComparatorEntryKey(Comparator<K> comparator)
|
||||
{
|
||||
super(comparator);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public K transform(Entry<K, V> type)
|
||||
{
|
||||
return type.getKey();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package com.massivecraft.massivecore.comparator;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class ComparatorEntryValue<K, V> extends ComparatorAbstractTransformer<Entry<K, V>, V>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static <K, V> ComparatorEntryValue<K, V> get(Comparator<V> comparator) { return new ComparatorEntryValue<K, V>(comparator); }
|
||||
public ComparatorEntryValue(Comparator<V> comparator)
|
||||
{
|
||||
super(comparator);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public V transform(Entry<K, V> type)
|
||||
{
|
||||
return type.getValue();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.massivecraft.massivecore.comparator;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class ComparatorHashCode extends ComparatorAbstract<Object>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// 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;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package com.massivecraft.massivecore.comparator;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
public class ComparatorLenient<T> extends ComparatorAbstractWrapper<T, T>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static <T> ComparatorLenient<T> get(Comparator<T> comparator) { return new ComparatorLenient<T>(comparator); }
|
||||
public ComparatorLenient(Comparator<T> 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<T> getLenient()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
@ -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<Object>
|
||||
public class ComparatorNaturalOrder extends ComparatorAbstract<Object>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// 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<Object>
|
||||
return s.charAt(i);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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<Prioritized>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// 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());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package com.massivecraft.massivecore.comparator;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
public class ComparatorReversed<T> extends ComparatorAbstractWrapper<T, T>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static <T> ComparatorReversed<T> get(Comparator<T> comparator) { return new ComparatorReversed<T>(comparator); }
|
||||
public ComparatorReversed(Comparator<T> comparator)
|
||||
{
|
||||
super(comparator);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public int compare(T type1, T type2)
|
||||
{
|
||||
return - this.getComparator().compare(type1, type2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComparatorAbstract<T> getReversed()
|
||||
{
|
||||
Comparator<T> comparator = this.getComparator();
|
||||
if (comparator instanceof ComparatorAbstract<?>) return (ComparatorAbstract<T>) comparator;
|
||||
return super.getReversed();
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.massivecraft.massivecore;
|
||||
package com.massivecraft.massivecore.predicate;
|
||||
|
||||
public interface Predicate<T>
|
||||
{
|
@ -1,4 +1,4 @@
|
||||
package com.massivecraft.massivecore;
|
||||
package com.massivecraft.massivecore.predicate;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
@ -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<String>
|
@ -1,4 +1,6 @@
|
||||
package com.massivecraft.massivecore;
|
||||
package com.massivecraft.massivecore.predicate;
|
||||
|
||||
import com.massivecraft.massivecore.Registerable;
|
||||
|
||||
public class PredicateIsRegistered implements Predicate<Registerable>
|
||||
{
|
@ -1,4 +1,4 @@
|
||||
package com.massivecraft.massivecore;
|
||||
package com.massivecraft.massivecore.predicate;
|
||||
|
||||
import com.massivecraft.massivecore.store.Entity;
|
||||
|
@ -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<String>
|
@ -1,4 +1,4 @@
|
||||
package com.massivecraft.massivecore;
|
||||
package com.massivecraft.massivecore.predicate;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
@ -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<E extends Entity<E>> extends CollAbstract<E>
|
||||
public final static String TOTAL = "*total*";
|
||||
|
||||
// All instances registered here are considered inited.
|
||||
private static Map<String, Coll<?>> name2instance = new ConcurrentSkipListMap<String, Coll<?>>(NaturalOrderComparator.get());
|
||||
private static Map<String, Coll<?>> name2instance = new ConcurrentSkipListMap<String, Coll<?>>(ComparatorNaturalOrder.get());
|
||||
|
||||
private static Map<String, Coll<?>> umap = Collections.unmodifiableMap(name2instance);
|
||||
private static Set<String> unames = Collections.unmodifiableSet(name2instance.keySet());
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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<E extends Entity<E>> extends Named
|
||||
|
@ -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<Entity<?>>
|
||||
{
|
||||
@ -29,7 +29,7 @@ public class ComparatorEntityId implements Comparator<Entity<?>>
|
||||
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.
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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<String> treeset(String... items)
|
||||
{
|
||||
return new MassiveTreeSet<String, CaseInsensitiveComparator>(CaseInsensitiveComparator.get(), Arrays.asList(items));
|
||||
return new MassiveTreeSet<String, ComparatorCaseInsensitive>(ComparatorCaseInsensitive.get(), Arrays.asList(items));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user