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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,7 +1,5 @@
package com.massivecraft.massivecore.command.editor; package com.massivecraft.massivecore.command.editor;
import com.massivecraft.massivecore.command.type.Type;
import java.util.Map; import java.util.Map;
public class CommandEditMap<O, V extends Map<?, ?>> extends CommandEditAbstract<O, V> 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 // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public CommandEditMap(EditSettings<O> settings, Property<O, V> property, Type<?> mapValueType) public CommandEditMap(EditSettings<O> settings, Property<O, V> property)
{ {
// Super // Super
super(settings, property, null); 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 CommandEditCreate<O, V>(settings, property));
this.addChild(new CommandEditDelete<O, V>(settings, property)); this.addChild(new CommandEditDelete<O, V>(settings, property));
this.addChild(new CommandEditMapPut<O, V>(settings, property, mapValueType)); this.addChild(new CommandEditMapPut<O, V>(settings, property));
this.addChild(new CommandEditMapRemove<O, V>(settings, property, mapValueType)); this.addChild(new CommandEditMapRemove<O, V>(settings, property));
this.addChild(new CommandEditMapClear<O, V>(settings, property, mapValueType)); 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 // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public CommandEditMapAbstract(EditSettings<O> settings, Property<O, V> property, Type<?> mapValueType) public CommandEditMapAbstract(EditSettings<O> settings, Property<O, V> property)
{ {
// Super // Super
super(settings, property, true); super(settings, property, true);
this.setMapValueType(mapValueType);
// Aliases // Aliases
String alias = this.createCommandAlias(); String alias = this.createCommandAlias();
@ -29,13 +28,6 @@ public abstract class CommandEditMapAbstract<O, V extends Map<?, ?>> extends Com
this.addRequirements(RequirementEditorPropertyCreated.get(true)); this.addRequirements(RequirementEditorPropertyCreated.get(true));
} }
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
Type<?> mapValueType = null;
public void setMapValueType(Type<?> mapValueType) { this.mapValueType = mapValueType; }
// -------------------------------------------- // // -------------------------------------------- //
// SHORTCUTS > PROPERTY > TYPE // 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. // Only to be used with map type properties.
public Type<Object> getMapKeyType() public Type<Object> getMapKeyType()
{ {
return this.getProperty().getValueType().getInnerType(); return this.getProperty().getValueType().getInnerType(0);
} }
@SuppressWarnings("unchecked")
public Type<Object> getMapValueType() 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 // Alter
try try
{ {
after = this.alter(after); this.alter(after);
} }
catch (MassiveException e) catch (MassiveException e)
{ {
@ -85,7 +76,7 @@ public abstract class CommandEditMapAbstract<O, V extends Map<?, ?>> extends Com
// ABSTRACT // ABSTRACT
// -------------------------------------------- // // -------------------------------------------- //
public abstract Map<Object, Object> alter(Map<Object, Object> map) throws MassiveException; public abstract void alter(Map<Object, Object> map) throws MassiveException;
// -------------------------------------------- // // -------------------------------------------- //
// UTIL // UTIL

View File

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

View File

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

View File

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

View File

@ -1,7 +1,5 @@
package com.massivecraft.massivecore.command.editor; package com.massivecraft.massivecore.command.editor;
import java.util.Collection;
import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.MassiveException;
public class CommandEditShow<O, V> extends CommandEditAbstract<O, V> 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> 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 // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public TypeMapAbstract(Type<K> mapKeyType, Type<V> mapValueType) public TypeMapAbstract(Type<K> mapKeyType, Type<V> mapValueType)
{ {
this.setMapKeyType(mapKeyType); this.setInnerTypes(mapKeyType, mapValueType);
this.setMapValueType(mapValueType);
} }
// -------------------------------------------- //
// INNER TYPES
// -------------------------------------------- //
public Type<K> getMapKeyType() { return this.getInnerType(0); }
public Type<V> getMapValueType() { return this.getInnerType(1); }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@ -209,7 +204,7 @@ public abstract class TypeMapAbstract<C extends Map<K, V>, K, V> extends TypeAbs
@Override @Override
public <O> CommandEditAbstract<O, C> createEditCommand(EditSettings<O> settings, Property<O, C> property) 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; protected final SenderColl<T> coll;
public SenderColl<T> getColl() { return this.coll; }
// -------------------------------------------- // // -------------------------------------------- //
// CONSTRUCT // 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);
}
}