|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
package speiger.src.coreengine.utils.io.dataTag.special;
|
|
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
|
|
import speiger.src.coreengine.utils.io.dataTag.DataTag;
|
|
|
|
@ -23,97 +24,93 @@ import speiger.src.coreengine.utils.io.dataTag.simple.StringTag;
|
|
|
|
|
|
|
|
|
|
public interface IMapTag extends DataTag
|
|
|
|
|
{
|
|
|
|
|
public void setTag(String id, DataTag tag);
|
|
|
|
|
public default void setList(String id, ListTag tag) { if(!tag.isEmpty()) setTag(id, tag); }
|
|
|
|
|
public default void setMap(String id, MapTag tag) { if(!tag.isEmpty()) setTag(id, tag); }
|
|
|
|
|
public void putTag(String id, DataTag tag);
|
|
|
|
|
public default void putList(String id, ListTag tag) { if(!tag.isEmpty()) putTag(id, tag); }
|
|
|
|
|
public default void putMap(String id, MapTag tag) { if(!tag.isEmpty()) putTag(id, tag); }
|
|
|
|
|
|
|
|
|
|
public default void setBoolean(String id, boolean value) {setByte(id, (byte)(value ? 1 : 0), (byte)0);}
|
|
|
|
|
public default void setByte(String id, byte value) {setByte(id, value, (byte)0);}
|
|
|
|
|
public default void setByte(String id, byte value, byte defaultValue)
|
|
|
|
|
{
|
|
|
|
|
if(value != defaultValue)
|
|
|
|
|
{
|
|
|
|
|
setTag(id, new ByteTag(value));
|
|
|
|
|
}
|
|
|
|
|
public default void putBoolean(String id, boolean value) {putByte(id, (byte)(value ? 1 : 0), (byte)0);}
|
|
|
|
|
public default void putBoolean(String id, boolean value, boolean defaultValue) {putByte(id, (byte)(value ? 1 : 0), (byte)(defaultValue ? 1 : 0));}
|
|
|
|
|
public default void putByte(String id, byte value) {putByte(id, value, (byte)0);}
|
|
|
|
|
public default void putByte(String id, byte value, byte defaultValue) {
|
|
|
|
|
if(value != defaultValue) putTag(id, new ByteTag(value));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public default void setShort(String id, short value) {setShort(id, value, (short)0);}
|
|
|
|
|
public default void setShort(String id, short value, short defaultValue)
|
|
|
|
|
{
|
|
|
|
|
if(value != defaultValue)
|
|
|
|
|
{
|
|
|
|
|
setTag(id, new ShortTag(value));
|
|
|
|
|
}
|
|
|
|
|
public default void putShort(String id, short value) {putShort(id, value, (short)0);}
|
|
|
|
|
public default void putShort(String id, short value, short defaultValue) {
|
|
|
|
|
if(value != defaultValue) putTag(id, new ShortTag(value));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public default void setMedium(String id, int value) {setMedium(id, value, 0);}
|
|
|
|
|
public default void setMedium(String id, int value, int defaultValue)
|
|
|
|
|
{
|
|
|
|
|
if(value != defaultValue)
|
|
|
|
|
{
|
|
|
|
|
setTag(id, new MediumTag(value));
|
|
|
|
|
}
|
|
|
|
|
public default void putMedium(String id, int value) {putMedium(id, value, 0);}
|
|
|
|
|
public default void putMedium(String id, int value, int defaultValue) {
|
|
|
|
|
if(value != defaultValue) putTag(id, new MediumTag(value));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public default void setInt(String id, int value) {setInt(id, value, 0);}
|
|
|
|
|
public default void setInt(String id, int value, int defaultValue)
|
|
|
|
|
{
|
|
|
|
|
if(value != defaultValue)
|
|
|
|
|
{
|
|
|
|
|
setTag(id, new IntTag(value));
|
|
|
|
|
}
|
|
|
|
|
public default void putInt(String id, int value) {putInt(id, value, 0);}
|
|
|
|
|
public default void putInt(String id, int value, int defaultValue) {
|
|
|
|
|
if(value != defaultValue) putTag(id, new IntTag(value));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public default void setLong(String id, long value) {setLong(id, value, 0L);}
|
|
|
|
|
public default void setLong(String id, long value, long defaultValue)
|
|
|
|
|
{
|
|
|
|
|
if(value != defaultValue)
|
|
|
|
|
{
|
|
|
|
|
setTag(id, new LongTag(value));
|
|
|
|
|
}
|
|
|
|
|
public default void putLong(String id, long value) {putLong(id, value, 0L);}
|
|
|
|
|
public default void putLong(String id, long value, long defaultValue) {
|
|
|
|
|
if(value != defaultValue) putTag(id, new LongTag(value));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public default void setFloat(String id, float value) {setFloat(id, value, 0F);}
|
|
|
|
|
public default void setFloat(String id, float value, float defaultValue)
|
|
|
|
|
{
|
|
|
|
|
if(value != defaultValue)
|
|
|
|
|
{
|
|
|
|
|
setTag(id, new FloatTag(value));
|
|
|
|
|
}
|
|
|
|
|
public default void putFloat(String id, float value) {putFloat(id, value, 0F);}
|
|
|
|
|
public default void putFloat(String id, float value, float defaultValue) {
|
|
|
|
|
if(Float.floatToIntBits(value) == Float.floatToIntBits(defaultValue)) putTag(id, new FloatTag(value));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public default void setDouble(String id, double value) {setDouble(id, value, 0D);}
|
|
|
|
|
public default void setDouble(String id, double value, double defaultValue)
|
|
|
|
|
{
|
|
|
|
|
if(value != defaultValue)
|
|
|
|
|
{
|
|
|
|
|
setTag(id, new DoubleTag(value));
|
|
|
|
|
}
|
|
|
|
|
public default void putDouble(String id, double value) {putDouble(id, value, 0D);}
|
|
|
|
|
public default void putDouble(String id, double value, double defaultValue) {
|
|
|
|
|
if(Double.doubleToLongBits(value) == Double.doubleToLongBits(defaultValue)) putTag(id, new DoubleTag(value));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public default void setString(String id, String value) {setString(id, value, "");}
|
|
|
|
|
public default void setString(String id, String value, String defaultValue)
|
|
|
|
|
{
|
|
|
|
|
if(!value.equals(defaultValue))
|
|
|
|
|
{
|
|
|
|
|
setTag(id, new StringTag(value));
|
|
|
|
|
}
|
|
|
|
|
public default void putString(String id, String value) {putString(id, value, "");}
|
|
|
|
|
public default void putString(String id, String value, String defaultValue) {
|
|
|
|
|
if(!value.equals(defaultValue)) putTag(id, new StringTag(value));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public default void setByteArray(String id, byte[] data) {if(data.length > 0){setTag(id, new ByteArrayTag(data));}}
|
|
|
|
|
public default void setShortArray(String id, short[] data) {if(data.length > 0){setTag(id, new ShortArrayTag(data));}}
|
|
|
|
|
public default void setMediumArray(String id, int[] data) {if(data.length > 0){setTag(id, new MediumArrayTag(data));}}
|
|
|
|
|
public default void setIntArray(String id, int[] data) {if(data.length > 0){setTag(id, new IntArrayTag(data));}}
|
|
|
|
|
public default void setLongArray(String id, long[] data) {if(data.length > 0){setTag(id, new LongArrayTag(data));}}
|
|
|
|
|
public default void setFloatArray(String id, float[] data) {if(data.length > 0){setTag(id, new FloatArrayTag(data));}}
|
|
|
|
|
public default void setDoubleArray(String id, double[] data) {if(data.length > 0){setTag(id, new DoubleArrayTag(data));}}
|
|
|
|
|
public default void setStringArray(String id, String[] data) {if(data.length > 0){setTag(id, new StringArrayTag(data));}}
|
|
|
|
|
public default void putByteArray(String id, byte[] data) {if(data.length > 0){putTag(id, new ByteArrayTag(data));}}
|
|
|
|
|
public default void putByteArray(String id, byte[] data, byte[] defaultValue) {if(!Arrays.equals(data, defaultValue)){putTag(id, new ByteArrayTag(data));}}
|
|
|
|
|
public default void putShortArray(String id, short[] data) {if(data.length > 0){putTag(id, new ShortArrayTag(data));}}
|
|
|
|
|
public default void putShortArray(String id, short[] data, short[] defaultValue) {if(!Arrays.equals(data, defaultValue)){putTag(id, new ShortArrayTag(data));}}
|
|
|
|
|
public default void putMediumArray(String id, int[] data) {if(data.length > 0){putTag(id, new MediumArrayTag(data));}}
|
|
|
|
|
public default void putMediumArray(String id, int[] data, int[] defaultValue) {if(!Arrays.equals(data, defaultValue)){putTag(id, new MediumArrayTag(data));}}
|
|
|
|
|
public default void putIntArray(String id, int[] data) {if(data.length > 0){putTag(id, new IntArrayTag(data));}}
|
|
|
|
|
public default void putIntArray(String id, int[] data, int[] defaultValue) {if(!Arrays.equals(data, defaultValue)){putTag(id, new IntArrayTag(data));}}
|
|
|
|
|
public default void putLongArray(String id, long[] data) {if(data.length > 0){putTag(id, new LongArrayTag(data));}}
|
|
|
|
|
public default void putLongArray(String id, long[] data, long[] defaultValue) {if(!Arrays.equals(data, defaultValue)){putTag(id, new LongArrayTag(data));}}
|
|
|
|
|
public default void putFloatArray(String id, float[] data) {if(data.length > 0){putTag(id, new FloatArrayTag(data));}}
|
|
|
|
|
public default void putFloatArray(String id, float[] data, float[] defaultValue) {if(!Arrays.equals(data, defaultValue)){putTag(id, new FloatArrayTag(data));}}
|
|
|
|
|
public default void putDoubleArray(String id, double[] data) {if(data.length > 0){putTag(id, new DoubleArrayTag(data));}}
|
|
|
|
|
public default void putDoubleArray(String id, double[] data, double[] defaultValue) {if(!Arrays.equals(data, defaultValue)){putTag(id, new DoubleArrayTag(data));}}
|
|
|
|
|
public default void putStringArray(String id, String[] data) {if(data.length > 0){putTag(id, new StringArrayTag(data));}}
|
|
|
|
|
public default void putStringArray(String id, String[] data, String[] defaultValue) {if(!Arrays.equals(data, defaultValue)){putTag(id, new StringArrayTag(data));}}
|
|
|
|
|
|
|
|
|
|
public default void setUUID(String id, UUID data) { if(data != null) setLongArray(id, new long[]{data.getMostSignificantBits(), data.getLeastSignificantBits()});}
|
|
|
|
|
public default void putUUID(String id, UUID data) { if(data != null) putLongArray(id, new long[]{data.getMostSignificantBits(), data.getLeastSignificantBits()});}
|
|
|
|
|
|
|
|
|
|
public default <T extends Enum<T>> void putEnum(String id, T value)
|
|
|
|
|
{
|
|
|
|
|
int index = value == null ? 0 : value.ordinal()+1;
|
|
|
|
|
if(index == 0) return;
|
|
|
|
|
if(index < Byte.MAX_VALUE) putByte(id, (byte)index);
|
|
|
|
|
else if(index < Short.MAX_VALUE) putShort(id, (short)index);
|
|
|
|
|
else putInt(id, index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public default <T extends Enum<T>> void putEnum(String id, T value, T defaultValue)
|
|
|
|
|
{
|
|
|
|
|
if(value == defaultValue || value == null) return;
|
|
|
|
|
int index = value.ordinal()+1;
|
|
|
|
|
if(index < Byte.MAX_VALUE) putByte(id, (byte)index);
|
|
|
|
|
else if(index < Short.MAX_VALUE) putShort(id, (short)index);
|
|
|
|
|
else putInt(id, index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DataTag get(String id);
|
|
|
|
|
|
|
|
|
|
public default boolean getBoolean(String id) { return getByte(id, (byte)0) != 0;}
|
|
|
|
|
public default boolean getBoolean(String id, boolean defaultValue) { return getByte(id, (byte)(defaultValue ? 1 : 0)) != 0;}
|
|
|
|
|
public default byte getByte(String id) {return getByte(id, (byte)0);}
|
|
|
|
|
public default byte getByte(String id, byte defaultValue)
|
|
|
|
|
{
|
|
|
|
@ -160,7 +157,7 @@ public interface IMapTag extends DataTag
|
|
|
|
|
public default double getDouble(String id, double defaultValue)
|
|
|
|
|
{
|
|
|
|
|
DataTag tag = get(id);
|
|
|
|
|
return isPrimitve(tag) ? ((PrimitiveTag)tag).asByte() : defaultValue;
|
|
|
|
|
return isPrimitve(tag) ? ((PrimitiveTag)tag).asDouble() : defaultValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public default String getString(String id) {return getString(id, "");}
|
|
|
|
@ -170,52 +167,60 @@ public interface IMapTag extends DataTag
|
|
|
|
|
return isType(tag, 8) ? ((StringTag)tag).get() : defaultValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public default byte[] getByteArray(String id)
|
|
|
|
|
public default byte[] getByteArray(String id) { return getByteArray(id, Defaults.EMPTY_BYTE); }
|
|
|
|
|
public default byte[] getByteArray(String id, byte[] defaultValue)
|
|
|
|
|
{
|
|
|
|
|
DataTag tag = get(id);
|
|
|
|
|
return isType(tag, 9) ? ((ByteArrayTag)tag).get() : new byte[0];
|
|
|
|
|
return isType(tag, 9) ? ((ByteArrayTag)tag).get() : defaultValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public default short[] getShortArray(String id)
|
|
|
|
|
public default short[] getShortArray(String id) { return getShortArray(id, Defaults.EMPTY_SHORT); }
|
|
|
|
|
public default short[] getShortArray(String id, short[] defaultValue)
|
|
|
|
|
{
|
|
|
|
|
DataTag tag = get(id);
|
|
|
|
|
return isType(tag, 10) ? ((ShortArrayTag)tag).get() : new short[0];
|
|
|
|
|
return isType(tag, 10) ? ((ShortArrayTag)tag).get() : defaultValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public default int[] getMediumArray(String id)
|
|
|
|
|
public default int[] getMediumArray(String id) { return getMediumArray(id, Defaults.EMPTY_INT); }
|
|
|
|
|
public default int[] getMediumArray(String id, int[] defaultValue)
|
|
|
|
|
{
|
|
|
|
|
DataTag tag = get(id);
|
|
|
|
|
return isType(tag, 11) ? ((MediumArrayTag)tag).get() : new int[0];
|
|
|
|
|
return isType(tag, 11) ? ((MediumArrayTag)tag).get() : defaultValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public default int[] getIntArray(String id)
|
|
|
|
|
public default int[] getIntArray(String id) { return getIntArray(id, Defaults.EMPTY_INT); }
|
|
|
|
|
public default int[] getIntArray(String id, int[] defaultValue)
|
|
|
|
|
{
|
|
|
|
|
DataTag tag = get(id);
|
|
|
|
|
return isType(tag, 12) ? ((IntArrayTag)tag).get() : new int[0];
|
|
|
|
|
return isType(tag, 12) ? ((IntArrayTag)tag).get() : defaultValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public default long[] getLongArray(String id)
|
|
|
|
|
public default long[] getLongArray(String id) { return getLongArray(id, Defaults.EMPTY_LONG); }
|
|
|
|
|
public default long[] getLongArray(String id, long[] defaultValue)
|
|
|
|
|
{
|
|
|
|
|
DataTag tag = get(id);
|
|
|
|
|
return isType(tag, 13) ? ((LongArrayTag)tag).get() : new long[0];
|
|
|
|
|
return isType(tag, 13) ? ((LongArrayTag)tag).get() : defaultValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public default float[] getFloatArray(String id)
|
|
|
|
|
public default float[] getFloatArray(String id) { return getFloatArray(id, Defaults.EMPTY_FLOAT); }
|
|
|
|
|
public default float[] getFloatArray(String id, float[] defaultValue)
|
|
|
|
|
{
|
|
|
|
|
DataTag tag = get(id);
|
|
|
|
|
return isType(tag, 14) ? ((FloatArrayTag)tag).get() : new float[0];
|
|
|
|
|
return isType(tag, 14) ? ((FloatArrayTag)tag).get() : defaultValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public default double[] getDoubleArray(String id)
|
|
|
|
|
public default double[] getDoubleArray(String id) { return getDoubleArray(id, Defaults.EMPTY_DOUBLE); }
|
|
|
|
|
public default double[] getDoubleArray(String id, double[] defaultValue)
|
|
|
|
|
{
|
|
|
|
|
DataTag tag = get(id);
|
|
|
|
|
return isType(tag, 15) ? ((DoubleArrayTag)tag).get() : new double[0];
|
|
|
|
|
return isType(tag, 15) ? ((DoubleArrayTag)tag).get() : defaultValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public default String[] getStringArray(String id)
|
|
|
|
|
public default String[] getStringArray(String id) { return getStringArray(id, Defaults.EMPTY_STRING); }
|
|
|
|
|
public default String[] getStringArray(String id, String[] defaultValue)
|
|
|
|
|
{
|
|
|
|
|
DataTag tag = get(id);
|
|
|
|
|
return isType(tag, 16) ? ((StringArrayTag)tag).get() : new String[0];
|
|
|
|
|
return isType(tag, 16) ? ((StringArrayTag)tag).get() : defaultValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public default UUID getUUID(String id)
|
|
|
|
@ -224,6 +229,18 @@ public interface IMapTag extends DataTag
|
|
|
|
|
return data == null || data.length != 2 ? null : new UUID(data[0], data[1]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public default <T extends Enum<T>> T getEnum(String id, Class<T> clz)
|
|
|
|
|
{
|
|
|
|
|
int value = getInt(id);
|
|
|
|
|
return value == 0 ? null : clz.getEnumConstants()[value-1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public default <T extends Enum<T>> T getEnum(String id, Class<T> clz, T defaultValue)
|
|
|
|
|
{
|
|
|
|
|
int value = getInt(id);
|
|
|
|
|
return value == 0 ? defaultValue : clz.getEnumConstants()[value-1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public default MapTag getMap(String id)
|
|
|
|
|
{
|
|
|
|
|
DataTag tag = get(id);
|
|
|
|
@ -246,4 +263,15 @@ public interface IMapTag extends DataTag
|
|
|
|
|
{
|
|
|
|
|
return (tag == null ? 0 : tag.getId()) == type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static class Defaults
|
|
|
|
|
{
|
|
|
|
|
private static final byte[] EMPTY_BYTE = new byte[0];
|
|
|
|
|
private static final short[] EMPTY_SHORT = new short[0];
|
|
|
|
|
private static final int[] EMPTY_INT = new int[0];
|
|
|
|
|
private static final long[] EMPTY_LONG = new long[0];
|
|
|
|
|
private static final float[] EMPTY_FLOAT = new float[0];
|
|
|
|
|
private static final double[] EMPTY_DOUBLE = new double[0];
|
|
|
|
|
private static final String[] EMPTY_STRING = new String[0];
|
|
|
|
|
}
|
|
|
|
|
}
|