Improve Map and Collection editor. Add SenderEntity id transformer.

This commit is contained in:
Olof Larsson 2016-01-14 14:12:53 +01:00
parent f2d922e049
commit 8034bf44c6
17 changed files with 76 additions and 89 deletions

View File

@ -43,7 +43,7 @@ public abstract class CommandEditCollectionAbstract<O, V extends Collection<?>>
// Alter
try
{
after = this.alter(after);
this.alter(after);
}
catch (MassiveException e)
{
@ -69,7 +69,7 @@ public abstract class CommandEditCollectionAbstract<O, V extends Collection<?>>
// ABSTRACT
// -------------------------------------------- //
public abstract List<Object> alter(List<Object> list) throws MassiveException;
public abstract void alter(List<Object> list) throws MassiveException;
// -------------------------------------------- //
// UTIL

View File

@ -25,16 +25,13 @@ public class CommandEditCollectionAdd<O, V extends Collection<?>> extends Comman
// -------------------------------------------- //
@Override
public List<Object> alter(List<Object> list) throws MassiveException
public void alter(List<Object> list) throws MassiveException
{
// Args
Object element = this.readArg();
// Alter
list.add(element);
// Return
return list;
}
}

View File

@ -22,13 +22,10 @@ public class CommandEditCollectionClear<O, V extends Collection<?>> extends Comm
// -------------------------------------------- //
@Override
public List<Object> alter(List<Object> list) throws MassiveException
public void alter(List<Object> list) throws MassiveException
{
// Apply
list.clear();
// Return
return list;
}
}

View File

@ -27,7 +27,7 @@ public class CommandEditCollectionInsert<O, V extends Collection<?>> extends Com
// -------------------------------------------- //
@Override
public List<Object> alter(List<Object> list) throws MassiveException
public void alter(List<Object> list) throws MassiveException
{
// Args
int index = this.readArg();
@ -35,9 +35,6 @@ public class CommandEditCollectionInsert<O, V extends Collection<?>> extends Com
// Alter
list.add(index, element);
// Return
return list;
}
}

View File

@ -27,7 +27,7 @@ public class CommandEditCollectionMove<O, V extends Collection<?>> extends Comma
// -------------------------------------------- //
@Override
public List<Object> alter(List<Object> list) throws MassiveException
public void alter(List<Object> list) throws MassiveException
{
// Args
int indexFrom = this.readArg();
@ -36,9 +36,6 @@ public class CommandEditCollectionMove<O, V extends Collection<?>> extends Comma
// Alter
Object element = list.remove(indexFrom);
list.add(indexTo, element);
// Return
return list;
}
}

View File

@ -26,16 +26,13 @@ public class CommandEditCollectionRemove<O, V extends Collection<?>> extends Com
// -------------------------------------------- //
@Override
public List<Object> alter(List<Object> list) throws MassiveException
public void alter(List<Object> list) throws MassiveException
{
// Args
int index = this.readArg();
// Alter
list.remove(index);
// Return
return list;
}
}

View File

@ -27,7 +27,7 @@ public class CommandEditCollectionSet<O, V extends Collection<?>> extends Comman
// -------------------------------------------- //
@Override
public List<Object> alter(List<Object> list) throws MassiveException
public void alter(List<Object> list) throws MassiveException
{
// Args
int index = this.readArg();
@ -35,9 +35,6 @@ public class CommandEditCollectionSet<O, V extends Collection<?>> extends Comman
// Alter
list.set(index, element);
// Return
return list;
}
}

View File

@ -27,7 +27,7 @@ public class CommandEditCollectionSwap<O, V extends Collection<?>> extends Comma
// -------------------------------------------- //
@Override
public List<Object> alter(List<Object> list) throws MassiveException
public void alter(List<Object> list) throws MassiveException
{
// Args
int indexOne = this.readArg();
@ -38,9 +38,6 @@ public class CommandEditCollectionSwap<O, V extends Collection<?>> extends Comma
Object two = list.get(indexTwo);
list.set(indexOne, two);
list.set(indexTwo, one);
// Return
return list;
}
}

View File

@ -1,7 +1,5 @@
package com.massivecraft.massivecore.command.editor;
import com.massivecraft.massivecore.command.type.Type;
import java.util.Map;
public class CommandEditMap<O, V extends Map<?, ?>> extends CommandEditAbstract<O, V>
@ -10,7 +8,7 @@ public class CommandEditMap<O, V extends Map<?, ?>> extends CommandEditAbstract<
// CONSTRUCT
// -------------------------------------------- //
public CommandEditMap(EditSettings<O> settings, Property<O, V> property, Type<?> mapValueType)
public CommandEditMap(EditSettings<O> settings, Property<O, V> property)
{
// Super
super(settings, property, null);
@ -20,9 +18,9 @@ public class CommandEditMap<O, V extends Map<?, ?>> extends CommandEditAbstract<
this.addChild(new CommandEditCreate<O, V>(settings, property));
this.addChild(new CommandEditDelete<O, V>(settings, property));
this.addChild(new CommandEditMapPut<O, V>(settings, property, mapValueType));
this.addChild(new CommandEditMapRemove<O, V>(settings, property, mapValueType));
this.addChild(new CommandEditMapClear<O, V>(settings, property, mapValueType));
this.addChild(new CommandEditMapPut<O, V>(settings, property));
this.addChild(new CommandEditMapRemove<O, V>(settings, property));
this.addChild(new CommandEditMapClear<O, V>(settings, property));
}
}

View File

@ -12,11 +12,10 @@ public abstract class CommandEditMapAbstract<O, V extends Map<?, ?>> extends Com
// CONSTRUCT
// -------------------------------------------- //
public CommandEditMapAbstract(EditSettings<O> settings, Property<O, V> property, Type<?> mapValueType)
public CommandEditMapAbstract(EditSettings<O> settings, Property<O, V> property)
{
// Super
super(settings, property, true);
this.setMapValueType(mapValueType);
// Aliases
String alias = this.createCommandAlias();
@ -29,13 +28,6 @@ public abstract class CommandEditMapAbstract<O, V extends Map<?, ?>> extends Com
this.addRequirements(RequirementEditorPropertyCreated.get(true));
}
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
Type<?> mapValueType = null;
public void setMapValueType(Type<?> mapValueType) { this.mapValueType = mapValueType; }
// -------------------------------------------- //
// SHORTCUTS > PROPERTY > TYPE
// -------------------------------------------- //
@ -43,13 +35,12 @@ public abstract class CommandEditMapAbstract<O, V extends Map<?, ?>> extends Com
// Only to be used with map type properties.
public Type<Object> getMapKeyType()
{
return this.getProperty().getValueType().getInnerType();
return this.getProperty().getValueType().getInnerType(0);
}
@SuppressWarnings("unchecked")
public Type<Object> getMapValueType()
{
return (Type<Object>) mapValueType;
return this.getProperty().getValueType().getInnerType(1);
}
// -------------------------------------------- //
@ -66,7 +57,7 @@ public abstract class CommandEditMapAbstract<O, V extends Map<?, ?>> extends Com
// Alter
try
{
after = this.alter(after);
this.alter(after);
}
catch (MassiveException e)
{
@ -85,7 +76,7 @@ public abstract class CommandEditMapAbstract<O, V extends Map<?, ?>> extends Com
// ABSTRACT
// -------------------------------------------- //
public abstract Map<Object, Object> alter(Map<Object, Object> map) throws MassiveException;
public abstract void alter(Map<Object, Object> map) throws MassiveException;
// -------------------------------------------- //
// UTIL

View File

@ -1,7 +1,6 @@
package com.massivecraft.massivecore.command.editor;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.command.type.Type;
import java.util.Map;
@ -11,10 +10,10 @@ public class CommandEditMapClear<O, V extends Map<?,?>> extends CommandEditMapAb
// CONSTRUCT
// -------------------------------------------- //
public CommandEditMapClear(EditSettings<O> settings, Property<O, V> property, Type<?> mapValueType)
public CommandEditMapClear(EditSettings<O> settings, Property<O, V> property)
{
// Super
super(settings, property, mapValueType);
super(settings, property);
}
// -------------------------------------------- //
@ -22,13 +21,10 @@ public class CommandEditMapClear<O, V extends Map<?,?>> extends CommandEditMapAb
// -------------------------------------------- //
@Override
public Map<Object, Object> alter(Map<Object, Object> map) throws MassiveException
public void alter(Map<Object, Object> map) throws MassiveException
{
// Alter
map.clear();
// Return
return map;
}
}

View File

@ -1,7 +1,6 @@
package com.massivecraft.massivecore.command.editor;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.command.type.Type;
import java.util.Map;
@ -11,10 +10,10 @@ public class CommandEditMapPut<O, V extends Map<?,?>> extends CommandEditMapAbst
// CONSTRUCT
// -------------------------------------------- //
public CommandEditMapPut(EditSettings<O> settings, Property<O, V> property, Type<?> mapValueType)
public CommandEditMapPut(EditSettings<O> settings, Property<O, V> property)
{
// Super
super(settings, property, mapValueType);
super(settings, property);
// Parameters
this.addParameter(this.getMapKeyType(), this.getMapKeyType().getTypeName());
@ -26,7 +25,7 @@ public class CommandEditMapPut<O, V extends Map<?,?>> extends CommandEditMapAbst
// -------------------------------------------- //
@Override
public Map<Object, Object> alter(Map<Object, Object> map) throws MassiveException
public void alter(Map<Object, Object> map) throws MassiveException
{
// Args
Object key = this.readArg();
@ -34,9 +33,6 @@ public class CommandEditMapPut<O, V extends Map<?,?>> extends CommandEditMapAbst
// Alter
map.put(key, value);
// Return
return map;
}
}

View File

@ -1,7 +1,6 @@
package com.massivecraft.massivecore.command.editor;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.command.type.Type;
import java.util.Map;
@ -11,10 +10,10 @@ public class CommandEditMapRemove<O, V extends Map<?,?>> extends CommandEditMapA
// CONSTRUCT
// -------------------------------------------- //
public CommandEditMapRemove(EditSettings<O> settings, Property<O, V> property, Type<?> mapValueType)
public CommandEditMapRemove(EditSettings<O> settings, Property<O, V> property)
{
// Super
super(settings, property, mapValueType);
super(settings, property);
// Parameters
this.addParameter(this.getMapKeyType(), this.getMapKeyType().getTypeName(), true);
@ -25,16 +24,13 @@ public class CommandEditMapRemove<O, V extends Map<?,?>> extends CommandEditMapA
// -------------------------------------------- //
@Override
public Map<Object, Object> alter(Map<Object, Object> map) throws MassiveException
public void alter(Map<Object, Object> map) throws MassiveException
{
// Args
Object key = this.readArg();
// Alter
map.remove(key);
// Return
return map;
}
}

View File

@ -1,7 +1,5 @@
package com.massivecraft.massivecore.command.editor;
import java.util.Collection;
import com.massivecraft.massivecore.MassiveException;
public class CommandEditShow<O, V> extends CommandEditAbstract<O, V>

View File

@ -19,27 +19,22 @@ import java.util.Map.Entry;
public abstract class TypeMapAbstract<C extends Map<K, V>, K, V> extends TypeAbstract<C>
{
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
private Type<V> mapValueType = null;
public void setMapValueType(Type<V> mapValueType) { this.mapValueType = mapValueType; }
public Type<V> getMapValueType() { return mapValueType; }
public void setMapKeyType(Type<K> mapKeyType) { this.setInnerType(mapKeyType); }
public Type<K> getMapKeyType() { return this.getInnerType(); }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public TypeMapAbstract(Type<K> mapKeyType, Type<V> mapValueType)
{
this.setMapKeyType(mapKeyType);
this.setMapValueType(mapValueType);
this.setInnerTypes(mapKeyType, mapValueType);
}
// -------------------------------------------- //
// INNER TYPES
// -------------------------------------------- //
public Type<K> getMapKeyType() { return this.getInnerType(0); }
public Type<V> getMapValueType() { return this.getInnerType(1); }
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@ -209,7 +204,7 @@ public abstract class TypeMapAbstract<C extends Map<K, V>, K, V> extends TypeAbs
@Override
public <O> CommandEditAbstract<O, C> createEditCommand(EditSettings<O> settings, Property<O, C> property)
{
return new CommandEditMap<O, C>(settings, property, this.getMapValueType());
return new CommandEditMap<O, C>(settings, property);
}
}

View File

@ -12,6 +12,7 @@ public class TypeSenderEntity<T extends SenderEntity<T>> extends TypeSenderIdAbs
// -------------------------------------------- //
protected final SenderColl<T> coll;
public SenderColl<T> getColl() { return this.coll; }
// -------------------------------------------- //
// CONSTRUCT

View File

@ -0,0 +1,37 @@
package com.massivecraft.massivecore.command.type.sender;
import com.massivecraft.massivecore.command.type.TypeTransformer;
import com.massivecraft.massivecore.command.type.primitive.TypeStringId;
import com.massivecraft.massivecore.store.SenderEntity;
public class TypeSenderEntityId<I extends SenderEntity<I>> extends TypeTransformer<I, String>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
public TypeSenderEntityId(TypeSenderEntity<I> typeInner)
{
super(typeInner, TypeStringId.get());
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public String innerToOuter(I inner)
{
if (inner == null) return null;
return inner.getId();
}
@Override
public I outerToInner(String outer)
{
if (outer == null) return null;
TypeSenderEntity<I> typeSenderEntity = (TypeSenderEntity<I>)INNER;
return typeSenderEntity.getColl().get(outer, false);
}
}