Do some cleanup for the container editor
This commit is contained in:
parent
89500be756
commit
251ff4da75
@ -545,12 +545,27 @@ public class MassiveCommand
|
|||||||
|
|
||||||
// WITHOUT 4
|
// WITHOUT 4
|
||||||
|
|
||||||
// Without defaultValue, reqFromConsole, defaultDesc & concat .
|
// Without defaultValue, reqFromConsole, defaultDesc & concat.
|
||||||
public <T> Parameter<T> addParameter(Type<T> type, String name)
|
public <T> Parameter<T> addParameter(Type<T> type, String name)
|
||||||
{
|
{
|
||||||
return this.addParameter(new Parameter<T>(type, name));
|
return this.addParameter(new Parameter<T>(type, name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Without defaultValue, name, reqFromConsole & defaultDesc.
|
||||||
|
public <T> Parameter<T> addParameter(Type<T> type, boolean concatFromHere)
|
||||||
|
{
|
||||||
|
return this.addParameter(new Parameter<T>(type), concatFromHere);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Without 5
|
||||||
|
|
||||||
|
// Without defaultValue, name, reqFromConsole, defaultDesc & concat.
|
||||||
|
public <T> Parameter<T> addParameter(Type<T> type)
|
||||||
|
{
|
||||||
|
return this.addParameter(new Parameter<T>(type));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// PREPROCESS
|
// PREPROCESS
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
@ -145,6 +145,12 @@ public class Parameter<T>
|
|||||||
this(type, REQUIRED_FROM_CONSOLE_DEFAULT, name, DEFAULT_DESC_DEFAULT);
|
this(type, REQUIRED_FROM_CONSOLE_DEFAULT, name, DEFAULT_DESC_DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Without defaultValue, name, reqFromConsole and defaultDesc.
|
||||||
|
public Parameter(Type<T> type)
|
||||||
|
{
|
||||||
|
this(type, REQUIRED_FROM_CONSOLE_DEFAULT, type.getTypeName(), DEFAULT_DESC_DEFAULT);
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// CONVENIENCE
|
// CONVENIENCE
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
package com.massivecraft.massivecore.command.editor;
|
package com.massivecraft.massivecore.command.editor;
|
||||||
|
|
||||||
|
import java.util.AbstractMap.SimpleImmutableEntry;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.AbstractMap.SimpleEntry;
|
|
||||||
|
|
||||||
import com.massivecraft.massivecore.MassiveException;
|
import com.massivecraft.massivecore.MassiveException;
|
||||||
import com.massivecraft.massivecore.command.requirement.RequirementEditorPropertyCreated;
|
import com.massivecraft.massivecore.command.requirement.RequirementEditorPropertyCreated;
|
||||||
import com.massivecraft.massivecore.command.type.Type;
|
import com.massivecraft.massivecore.command.type.Type;
|
||||||
import com.massivecraft.massivecore.command.type.TypeNullable;
|
import com.massivecraft.massivecore.command.type.TypeNullable;
|
||||||
import com.massivecraft.massivecore.util.ContainerUtil;
|
import com.massivecraft.massivecore.util.ContainerUtil;
|
||||||
|
import com.massivecraft.massivecore.util.Txt;
|
||||||
|
|
||||||
public abstract class CommandEditContainerAbstract<O, V> extends CommandEditAbstract<O, V>
|
public abstract class CommandEditContainerAbstract<O, V> extends CommandEditAbstract<O, V>
|
||||||
{
|
{
|
||||||
@ -38,8 +39,6 @@ public abstract class CommandEditContainerAbstract<O, V> extends CommandEditAbst
|
|||||||
@Override
|
@Override
|
||||||
public void perform() throws MassiveException
|
public void perform() throws MassiveException
|
||||||
{
|
{
|
||||||
// Type
|
|
||||||
|
|
||||||
// Create
|
// Create
|
||||||
V container = this.getProperty().getRaw(this.getObject());
|
V container = this.getProperty().getRaw(this.getObject());
|
||||||
List<Object> elements = this.getValueType().getContainerElementsOrdered(container);
|
List<Object> elements = this.getValueType().getContainerElementsOrdered(container);
|
||||||
@ -59,17 +58,26 @@ public abstract class CommandEditContainerAbstract<O, V> extends CommandEditAbst
|
|||||||
}
|
}
|
||||||
|
|
||||||
// After
|
// After
|
||||||
|
elements = this.getValueType().getContainerElementsOrdered(elements);
|
||||||
V after = this.getValueType().createNewInstance();
|
V after = this.getValueType().createNewInstance();
|
||||||
ContainerUtil.addElements(after, elements);
|
ContainerUtil.addElements(after, elements);
|
||||||
|
|
||||||
// Order
|
|
||||||
elements = this.getValueType().getContainerElementsOrdered(after);
|
|
||||||
ContainerUtil.setElements(after, elements);
|
|
||||||
|
|
||||||
// Apply
|
// Apply
|
||||||
this.attemptSet(after);
|
this.attemptSet(after);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String createCommandAlias()
|
||||||
|
{
|
||||||
|
// Split at uppercase letters
|
||||||
|
String name = this.getClass().getSimpleName();
|
||||||
|
name = name.substring("CommandEditContainer".length());
|
||||||
|
final String[] words = name.split("(?=[A-Z])");
|
||||||
|
String alias = Txt.implode(words, "");
|
||||||
|
alias = Txt.lowerCaseFirst(alias);
|
||||||
|
return alias;
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// ABSTRACT
|
// ABSTRACT
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -77,43 +85,33 @@ public abstract class CommandEditContainerAbstract<O, V> extends CommandEditAbst
|
|||||||
public abstract void alter(List<Object> elements) throws MassiveException;
|
public abstract void alter(List<Object> elements) throws MassiveException;
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// MAP
|
// PARAMETER
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public boolean isCollection()
|
public boolean isCollection()
|
||||||
{
|
{
|
||||||
Type<V> type = this.getValueType();
|
Type<V> type = this.getValueType();
|
||||||
if (type.isContainerCollection())
|
if (type.isContainerCollection()) return true;
|
||||||
{
|
if (type.isContainerMap()) return false;
|
||||||
return true;
|
throw new RuntimeException("Neither Collection nor Map.");
|
||||||
}
|
|
||||||
else if (type.isContainerMap())
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new RuntimeException("Neither Collection nor Map.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addParametersElement(boolean strict)
|
public void addParametersElement(boolean strict)
|
||||||
{
|
{
|
||||||
Type<V> type = this.getValueType();
|
Type<Object> innerType = this.getValueInnerType();
|
||||||
Type<Object> innerType = type.getInnerType();
|
|
||||||
|
|
||||||
if (type.isContainerCollection())
|
if (this.isCollection())
|
||||||
{
|
{
|
||||||
this.addParameter(innerType, innerType.getTypeName(), true);
|
this.addParameter(innerType, true);
|
||||||
}
|
}
|
||||||
else if (type.isContainerMap())
|
else
|
||||||
{
|
{
|
||||||
Type<Object> keyType = innerType.getInnerType(0);
|
Type<Object> keyType = innerType.getInnerType(0);
|
||||||
Type<Object> valueType = innerType.getInnerType(1);
|
Type<Object> valueType = innerType.getInnerType(1);
|
||||||
if (strict)
|
if (strict)
|
||||||
{
|
{
|
||||||
this.addParameter(keyType, keyType.getTypeName());
|
this.addParameter(keyType);
|
||||||
this.addParameter(valueType, valueType.getTypeName());
|
this.addParameter(valueType);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -121,10 +119,6 @@ public abstract class CommandEditContainerAbstract<O, V> extends CommandEditAbst
|
|||||||
this.addParameter(null, TypeNullable.get(valueType, "any", "all"), valueType.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
|
public Object readElement() throws MassiveException
|
||||||
@ -137,7 +131,7 @@ public abstract class CommandEditContainerAbstract<O, V> extends CommandEditAbst
|
|||||||
{
|
{
|
||||||
Object key = this.readArg();
|
Object key = this.readArg();
|
||||||
Object value = this.readArg();
|
Object value = this.readArg();
|
||||||
return new SimpleEntry<Object, Object>(key, value);
|
return new SimpleImmutableEntry<Object, Object>(key, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ public class CommandEditContainerAdd<O, V> extends CommandEditContainerAbstract<
|
|||||||
super(settings, property);
|
super(settings, property);
|
||||||
|
|
||||||
// Aliases
|
// Aliases
|
||||||
this.setAliases("add", "put");
|
this.addAliases("put");
|
||||||
|
|
||||||
// Parameters
|
// Parameters
|
||||||
this.addParametersElement(true);
|
this.addParametersElement(true);
|
||||||
|
@ -14,9 +14,6 @@ public class CommandEditContainerClear<O, V> extends CommandEditContainerAbstrac
|
|||||||
{
|
{
|
||||||
// Super
|
// Super
|
||||||
super(settings, property);
|
super(settings, property);
|
||||||
|
|
||||||
// Aliases
|
|
||||||
this.setAliases("clear");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
@ -16,9 +16,6 @@ public class CommandEditContainerInsert<O, V> extends CommandEditContainerAbstra
|
|||||||
// Super
|
// Super
|
||||||
super(settings, property);
|
super(settings, property);
|
||||||
|
|
||||||
// Aliases
|
|
||||||
this.setAliases("insert");
|
|
||||||
|
|
||||||
// Parameters
|
// Parameters
|
||||||
this.addParameter(TypeInteger.get(), "index");
|
this.addParameter(TypeInteger.get(), "index");
|
||||||
this.addParametersElement(true);
|
this.addParametersElement(true);
|
||||||
|
@ -16,9 +16,6 @@ public class CommandEditContainerMove<O, V> extends CommandEditContainerAbstract
|
|||||||
// Super
|
// Super
|
||||||
super(settings, property);
|
super(settings, property);
|
||||||
|
|
||||||
// Aliases
|
|
||||||
this.setAliases("move");
|
|
||||||
|
|
||||||
// Parameters
|
// Parameters
|
||||||
this.addParameter(TypeInteger.get(), "indexFrom");
|
this.addParameter(TypeInteger.get(), "indexFrom");
|
||||||
this.addParameter(TypeInteger.get(), "indexTo");
|
this.addParameter(TypeInteger.get(), "indexTo");
|
||||||
|
@ -18,9 +18,6 @@ public class CommandEditContainerRemove<O, V> extends CommandEditContainerAbstra
|
|||||||
// Super
|
// Super
|
||||||
super(settings, property);
|
super(settings, property);
|
||||||
|
|
||||||
// Aliases
|
|
||||||
this.setAliases("remove");
|
|
||||||
|
|
||||||
// Parameters
|
// Parameters
|
||||||
this.addParametersElement(false);
|
this.addParametersElement(false);
|
||||||
}
|
}
|
||||||
@ -52,12 +49,11 @@ public class CommandEditContainerRemove<O, V> extends CommandEditContainerAbstra
|
|||||||
Object element = this.readElement();
|
Object element = this.readElement();
|
||||||
|
|
||||||
// Alter
|
// Alter
|
||||||
Iterator<Object> iterator = elements.iterator();
|
for (Iterator<?> it = elements.iterator(); it.hasNext();)
|
||||||
while (iterator.hasNext())
|
|
||||||
{
|
{
|
||||||
Object other = iterator.hasNext();
|
Object other = it.next();
|
||||||
if ( ! this.getValueInnerType().equals(other, element)) continue;
|
if ( ! this.getValueInnerType().equals(other, element)) continue;
|
||||||
iterator.remove();
|
it.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,15 +72,14 @@ public class CommandEditContainerRemove<O, V> extends CommandEditContainerAbstra
|
|||||||
if (key == null && value == null) throw new MassiveException().addMsg("<b>Please supply key and/or value.");
|
if (key == null && value == null) throw new MassiveException().addMsg("<b>Please supply key and/or value.");
|
||||||
|
|
||||||
// Alter
|
// Alter
|
||||||
Iterator<Object> iterator = elements.iterator();
|
for (Iterator<?> it = elements.iterator(); it.hasNext();)
|
||||||
while (iterator.hasNext())
|
|
||||||
{
|
{
|
||||||
Entry<Object, Object> other = (Entry<Object, Object>) iterator.next();
|
Entry<Object, Object> other = (Entry<Object, Object>) it.next();
|
||||||
|
|
||||||
if (key != null && ! MUtil.equals(key, other.getKey())) continue;
|
if (key != null && ! MUtil.equals(key, other.getKey())) continue;
|
||||||
if (value != null && ! MUtil.equals(value, other.getValue())) continue;
|
if (value != null && ! MUtil.equals(value, other.getValue())) continue;
|
||||||
|
|
||||||
iterator.remove();
|
it.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,9 +16,6 @@ public class CommandEditContainerRemoveIndex<O, V> extends CommandEditContainerA
|
|||||||
// Super
|
// Super
|
||||||
super(settings, property);
|
super(settings, property);
|
||||||
|
|
||||||
// Aliases
|
|
||||||
this.setAliases("removeIndex");
|
|
||||||
|
|
||||||
// Parameters
|
// Parameters
|
||||||
this.addParameter(TypeInteger.get(), "index");
|
this.addParameter(TypeInteger.get(), "index");
|
||||||
}
|
}
|
||||||
|
@ -16,9 +16,6 @@ public class CommandEditContainerSet<O, V> extends CommandEditContainerAbstract<
|
|||||||
// Super
|
// Super
|
||||||
super(settings, property);
|
super(settings, property);
|
||||||
|
|
||||||
// Aliases
|
|
||||||
this.setAliases("set");
|
|
||||||
|
|
||||||
// Parameters
|
// Parameters
|
||||||
this.addParameter(TypeInteger.get(), "index");
|
this.addParameter(TypeInteger.get(), "index");
|
||||||
this.addParametersElement(true);
|
this.addParametersElement(true);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.massivecraft.massivecore.command.editor;
|
package com.massivecraft.massivecore.command.editor;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.massivecraft.massivecore.MassiveException;
|
import com.massivecraft.massivecore.MassiveException;
|
||||||
@ -16,9 +17,6 @@ public class CommandEditContainerSwap<O, V> extends CommandEditContainerAbstract
|
|||||||
// Super
|
// Super
|
||||||
super(settings, property);
|
super(settings, property);
|
||||||
|
|
||||||
// Aliases
|
|
||||||
this.setAliases("swap");
|
|
||||||
|
|
||||||
// Parameters
|
// Parameters
|
||||||
this.addParameter(TypeInteger.get(), "indexOne");
|
this.addParameter(TypeInteger.get(), "indexOne");
|
||||||
this.addParameter(TypeInteger.get(), "indexTwo");
|
this.addParameter(TypeInteger.get(), "indexTwo");
|
||||||
@ -36,10 +34,7 @@ public class CommandEditContainerSwap<O, V> extends CommandEditContainerAbstract
|
|||||||
int indexTwo = this.readArg();
|
int indexTwo = this.readArg();
|
||||||
|
|
||||||
// Alter
|
// Alter
|
||||||
Object elementOne = elements.get(indexOne);
|
Collections.swap(elements, indexOne, indexTwo);
|
||||||
Object elementTwo = elements.get(indexTwo);
|
|
||||||
elements.set(indexOne, elementTwo);
|
|
||||||
elements.set(indexTwo, elementOne);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,9 +25,9 @@ public interface Type<T>
|
|||||||
// INNER
|
// INNER
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public <I extends Type<? extends Object>> List<I> getInnerTypes();
|
public <I extends Type<?>> List<I> getInnerTypes();
|
||||||
public <I extends Type<? extends Object>> I getInnerType(int index);
|
public <I extends Type<?>> I getInnerType(int index);
|
||||||
public <I extends Type<? extends Object>> I getInnerType();
|
public <I extends Type<?>> I getInnerType();
|
||||||
|
|
||||||
public void setInnerTypes(Collection<Type<?>> innerTypes);
|
public void setInnerTypes(Collection<Type<?>> innerTypes);
|
||||||
public void setInnerTypes(Type<?>... innerTypes);
|
public void setInnerTypes(Type<?>... innerTypes);
|
||||||
|
@ -60,13 +60,13 @@ public abstract class TypeAbstract<T> implements Type<T>
|
|||||||
// INNER
|
// INNER
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
protected List<Type<Object>> innerTypes = new MassiveList<Type<Object>>();
|
protected List<Type<?>> innerTypes = new MassiveList<>();
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <I extends Type<? extends Object>> List<I> getInnerTypes() { return (List<I>) this.innerTypes; }
|
public <I extends Type<?>> List<I> getInnerTypes() { return (List<I>) this.innerTypes; }
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <I extends Type<? extends Object>> I getInnerType(int index) { return (I) this.getInnerTypes().get(index); }
|
public <I extends Type<?>> I getInnerType(int index) { return (I) this.getInnerTypes().get(index); }
|
||||||
public <I extends Type<? extends Object>> I getInnerType() { return this.getInnerType(0); }
|
public <I extends Type<?>> I getInnerType() { return this.getInnerType(0); }
|
||||||
|
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
public void setInnerTypes(Collection<Type<?>> innerTypes) { this.innerTypes = new MassiveList(innerTypes); }
|
public void setInnerTypes(Collection<Type<?>> innerTypes) { this.innerTypes = new MassiveList(innerTypes); }
|
||||||
|
@ -1,15 +1,21 @@
|
|||||||
package com.massivecraft.massivecore.command.type.combined;
|
package com.massivecraft.massivecore.command.type.combined;
|
||||||
|
|
||||||
|
import java.util.AbstractMap.SimpleImmutableEntry;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import java.util.AbstractMap.SimpleEntry;
|
|
||||||
|
|
||||||
import com.massivecraft.massivecore.collections.MassiveList;
|
|
||||||
import com.massivecraft.massivecore.command.type.Type;
|
import com.massivecraft.massivecore.command.type.Type;
|
||||||
|
|
||||||
public class TypeEntry<K, V> extends TypeCombined<Entry<K, V>>
|
public class TypeEntry<K, V> extends TypeCombined<Entry<K, V>>
|
||||||
{
|
{
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// CONSTANTS
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
private static final Entry<?, ?> ENTRY_EMPTY = new SimpleImmutableEntry<>(null, null);
|
||||||
|
@SuppressWarnings("unchecked") public static <K, V> Entry<K, V> getEntryEmpty() { return (Entry<K, V>) ENTRY_EMPTY; }
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// INSTANCE & CONSTRUCT
|
// INSTANCE & CONSTRUCT
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -41,36 +47,17 @@ public class TypeEntry<K, V> extends TypeCombined<Entry<K, V>>
|
|||||||
@Override
|
@Override
|
||||||
public Entry<K, V> combine(List<Object> parts)
|
public Entry<K, V> combine(List<Object> parts)
|
||||||
{
|
{
|
||||||
// Create
|
if (parts.isEmpty()) return getEntryEmpty();
|
||||||
K key = null;
|
if (parts.size() == 1) return new SimpleImmutableEntry<>((K)parts.get(0), null);
|
||||||
V value = null;
|
if (parts.size() == 2) return new SimpleImmutableEntry<>((K)parts.get(0), (V) parts.get(1));
|
||||||
|
|
||||||
// Fill
|
throw new RuntimeException(parts.size() + " parts");
|
||||||
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
|
@Override
|
||||||
public List<Object> split(Entry<K, V> entry)
|
public List<Object> split(Entry<K, V> entry)
|
||||||
{
|
{
|
||||||
return new MassiveList<Object>(
|
return Arrays.asList(entry.getKey(), entry.getValue());
|
||||||
entry.getKey(),
|
|
||||||
entry.getValue()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -40,7 +40,7 @@ public abstract class TypeContainer<C extends Object, E> extends TypeAbstract<C>
|
|||||||
|
|
||||||
public String getCollectionTypeName()
|
public String getCollectionTypeName()
|
||||||
{
|
{
|
||||||
return "Container";
|
return super.getTypeName();
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -111,8 +111,8 @@ public abstract class TypeContainer<C extends Object, E> extends TypeAbstract<C>
|
|||||||
List<String> parts = new MassiveList<String>();
|
List<String> parts = new MassiveList<String>();
|
||||||
|
|
||||||
// Fill
|
// Fill
|
||||||
List<E> elements = this.getContainerElementsOrdered(container);
|
|
||||||
Type<E> innerType = this.getInnerType();
|
Type<E> innerType = this.getInnerType();
|
||||||
|
List<E> elements = this.getContainerElementsOrdered(container);
|
||||||
for (E element : elements)
|
for (E element : elements)
|
||||||
{
|
{
|
||||||
String part = innerType.getIdInner(element);
|
String part = innerType.getIdInner(element);
|
||||||
@ -146,10 +146,9 @@ public abstract class TypeContainer<C extends Object, E> extends TypeAbstract<C>
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fill
|
// Fill
|
||||||
String[] elementArgs = Txt.PATTERN_WHITESPACE.split(arg);
|
Type<E> innerType = this.getInnerType();
|
||||||
for (String elementArg : elementArgs)
|
for (String elementArg : Txt.PATTERN_WHITESPACE.split(arg))
|
||||||
{
|
{
|
||||||
Type<E> innerType = this.getInnerType();
|
|
||||||
E element = innerType.read(elementArg, sender);
|
E element = innerType.read(elementArg, sender);
|
||||||
ContainerUtil.addElement(ret, element);
|
ContainerUtil.addElement(ret, element);
|
||||||
}
|
}
|
||||||
|
@ -25,12 +25,6 @@ public class TypeList<E> extends TypeContainer<List<E>, E>
|
|||||||
// OVERRIDE
|
// OVERRIDE
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getCollectionTypeName()
|
|
||||||
{
|
|
||||||
return "List";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<E> createNewInstance()
|
public List<E> createNewInstance()
|
||||||
{
|
{
|
||||||
|
@ -35,12 +35,6 @@ public class TypeMap<K, V> extends TypeContainer<Map<K, V>, Entry<K, V>>
|
|||||||
// OVERRIDE
|
// OVERRIDE
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getCollectionTypeName()
|
|
||||||
{
|
|
||||||
return "Map";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<K, V> createNewInstance()
|
public Map<K, V> createNewInstance()
|
||||||
{
|
{
|
||||||
|
@ -25,12 +25,6 @@ public class TypeSet<E> extends TypeContainer<Set<E>, E>
|
|||||||
// OVERRIDE
|
// OVERRIDE
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getCollectionTypeName()
|
|
||||||
{
|
|
||||||
return "Set";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<E> createNewInstance()
|
public Set<E> createNewInstance()
|
||||||
{
|
{
|
||||||
|
@ -2,11 +2,12 @@ package com.massivecraft.massivecore.util;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
import java.util.SortedMap;
|
import java.util.SortedMap;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
import java.util.Map.Entry;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The ContainerUtil provides an imaginary super class to Collection and Map.
|
* The ContainerUtil provides an imaginary super class to Collection and Map.
|
||||||
@ -51,12 +52,12 @@ public class ContainerUtil
|
|||||||
|
|
||||||
public static boolean isOrdered(Object container)
|
public static boolean isOrdered(Object container)
|
||||||
{
|
{
|
||||||
return container instanceof List<?> || container instanceof LinkedHashMap<?, ?>;
|
return container instanceof List || container instanceof LinkedHashMap || container instanceof LinkedHashSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isSorted(Object container)
|
public static boolean isSorted(Object container)
|
||||||
{
|
{
|
||||||
return container instanceof SortedSet<?> || container instanceof SortedMap<?, ?>;
|
return container instanceof SortedSet || container instanceof SortedMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -64,14 +65,14 @@ public class ContainerUtil
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <C extends Collection<? extends Object>> C asCollection(Object container)
|
public static <C extends Collection<?>> C asCollection(Object container)
|
||||||
{
|
{
|
||||||
if ( ! isCollection(container)) return null;
|
if ( ! isCollection(container)) return null;
|
||||||
return (C)container;
|
return (C)container;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <M extends Map<? extends Object, ? extends Object>> M asMap(Object container)
|
public static <M extends Map<?, ?>> M asMap(Object container)
|
||||||
{
|
{
|
||||||
if ( ! isMap(container)) return null;
|
if ( ! isMap(container)) return null;
|
||||||
return (M)container;
|
return (M)container;
|
||||||
@ -83,6 +84,8 @@ public class ContainerUtil
|
|||||||
|
|
||||||
public static boolean isEmpty(Object container)
|
public static boolean isEmpty(Object container)
|
||||||
{
|
{
|
||||||
|
if (container == null) throw new NullPointerException("container");
|
||||||
|
|
||||||
Collection<Object> collection = asCollection(container);
|
Collection<Object> collection = asCollection(container);
|
||||||
if (collection != null)
|
if (collection != null)
|
||||||
{
|
{
|
||||||
@ -95,11 +98,13 @@ public class ContainerUtil
|
|||||||
return map.isEmpty();
|
return map.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException(container.getClass().getName() + " is not a container.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int size(Object container)
|
public static int size(Object container)
|
||||||
{
|
{
|
||||||
|
if (container == null) throw new NullPointerException("container");
|
||||||
|
|
||||||
Collection<Object> collection = asCollection(container);
|
Collection<Object> collection = asCollection(container);
|
||||||
if (collection != null)
|
if (collection != null)
|
||||||
{
|
{
|
||||||
@ -112,7 +117,7 @@ public class ContainerUtil
|
|||||||
return map.size();
|
return map.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException(container.getClass().getName() + " is not a container.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -122,6 +127,8 @@ public class ContainerUtil
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <E> Collection<E> getElements(Object container)
|
public static <E> Collection<E> getElements(Object container)
|
||||||
{
|
{
|
||||||
|
if (container == null) throw new NullPointerException("container");
|
||||||
|
|
||||||
Collection<E> collection = asCollection(container);
|
Collection<E> collection = asCollection(container);
|
||||||
if (collection != null)
|
if (collection != null)
|
||||||
{
|
{
|
||||||
@ -134,7 +141,7 @@ public class ContainerUtil
|
|||||||
return (Collection<E>) map.entrySet();
|
return (Collection<E>) map.entrySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException(container.getClass().getName() + " is not a container.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -143,6 +150,8 @@ public class ContainerUtil
|
|||||||
|
|
||||||
public static void clear(Object container)
|
public static void clear(Object container)
|
||||||
{
|
{
|
||||||
|
if (container == null) throw new NullPointerException("container");
|
||||||
|
|
||||||
Collection<Object> collection = asCollection(container);
|
Collection<Object> collection = asCollection(container);
|
||||||
if (collection != null)
|
if (collection != null)
|
||||||
{
|
{
|
||||||
@ -157,7 +166,7 @@ public class ContainerUtil
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException(container.getClass().getName() + " is not a container.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setElements(Object container, Iterable<? extends Object> elements)
|
public static void setElements(Object container, Iterable<? extends Object> elements)
|
||||||
@ -169,6 +178,8 @@ public class ContainerUtil
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static boolean addElement(Object container, Object element)
|
public static boolean addElement(Object container, Object element)
|
||||||
{
|
{
|
||||||
|
if (container == null) throw new NullPointerException("container");
|
||||||
|
|
||||||
Collection<Object> collection = asCollection(container);
|
Collection<Object> collection = asCollection(container);
|
||||||
if (collection != null)
|
if (collection != null)
|
||||||
{
|
{
|
||||||
@ -185,11 +196,14 @@ public class ContainerUtil
|
|||||||
return ! MUtil.equals(after, before);
|
return ! MUtil.equals(after, before);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException(container.getClass().getName() + " is not a container.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addElements(Object container, Iterable<? extends Object> elements)
|
public static void addElements(Object container, Iterable<? extends Object> elements)
|
||||||
{
|
{
|
||||||
|
if (container == null) throw new NullPointerException("container");
|
||||||
|
if (elements == null) throw new NullPointerException("elements");
|
||||||
|
|
||||||
for (Object element : elements)
|
for (Object element : elements)
|
||||||
{
|
{
|
||||||
addElement(container, element);
|
addElement(container, element);
|
||||||
|
@ -235,6 +235,12 @@ public class Txt
|
|||||||
if (string.length() == 0) return string;
|
if (string.length() == 0) return string;
|
||||||
return string.substring(0, 1).toUpperCase() + string.substring(1);
|
return string.substring(0, 1).toUpperCase() + string.substring(1);
|
||||||
}
|
}
|
||||||
|
public static String lowerCaseFirst(String string)
|
||||||
|
{
|
||||||
|
if (string == null) return null;
|
||||||
|
if (string.length() == 0) return string;
|
||||||
|
return string.substring(0, 1).toLowerCase() + string.substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
public static String repeat(String string, int times)
|
public static String repeat(String string, int times)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user