Add double short and byte support to UserData (#946)
This commit is contained in:
parent
835fbd7957
commit
626af3123a
@ -70,6 +70,9 @@ public final class UserData implements Savable {
|
|||||||
private static final int TYPE_LIST = 6;
|
private static final int TYPE_LIST = 6;
|
||||||
private static final int TYPE_MAP = 7;
|
private static final int TYPE_MAP = 7;
|
||||||
private static final int TYPE_ARRAY = 8;
|
private static final int TYPE_ARRAY = 8;
|
||||||
|
private static final int TYPE_DOUBLE = 9;
|
||||||
|
private static final int TYPE_SHORT = 10;
|
||||||
|
private static final int TYPE_BYTE = 11;
|
||||||
|
|
||||||
protected byte type;
|
protected byte type;
|
||||||
protected Object value;
|
protected Object value;
|
||||||
@ -87,7 +90,7 @@ public final class UserData implements Savable {
|
|||||||
* Value of the data
|
* Value of the data
|
||||||
*/
|
*/
|
||||||
public UserData(byte type, Object value) {
|
public UserData(byte type, Object value) {
|
||||||
assert type >= 0 && type <= 8;
|
assert type >= 0 && type <= 11;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
@ -120,6 +123,12 @@ public final class UserData implements Savable {
|
|||||||
return TYPE_MAP;
|
return TYPE_MAP;
|
||||||
} else if (type instanceof Object[]) {
|
} else if (type instanceof Object[]) {
|
||||||
return TYPE_ARRAY;
|
return TYPE_ARRAY;
|
||||||
|
} else if (type instanceof Double) {
|
||||||
|
return TYPE_DOUBLE;
|
||||||
|
} else if (type instanceof Short) {
|
||||||
|
return TYPE_SHORT;
|
||||||
|
} else if (type instanceof Byte) {
|
||||||
|
return TYPE_BYTE;
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Unsupported type: " + type.getClass().getName());
|
throw new IllegalArgumentException("Unsupported type: " + type.getClass().getName());
|
||||||
}
|
}
|
||||||
@ -165,6 +174,18 @@ public final class UserData implements Savable {
|
|||||||
case TYPE_ARRAY:
|
case TYPE_ARRAY:
|
||||||
this.writeList(oc, Arrays.asList((Object[]) value), "0");
|
this.writeList(oc, Arrays.asList((Object[]) value), "0");
|
||||||
break;
|
break;
|
||||||
|
case TYPE_DOUBLE:
|
||||||
|
Double d = (Double) value;
|
||||||
|
oc.write(d, "doubleVal", 0.);
|
||||||
|
break;
|
||||||
|
case TYPE_SHORT:
|
||||||
|
Short sh = (Short) value;
|
||||||
|
oc.write(sh, "shortVal", (short)0);
|
||||||
|
break;
|
||||||
|
case TYPE_BYTE:
|
||||||
|
Byte bh = (Byte) value;
|
||||||
|
oc.write(bh, "byteVal", (byte)0);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new UnsupportedOperationException("Unsupported value type: " + value.getClass());
|
throw new UnsupportedOperationException("Unsupported value type: " + value.getClass());
|
||||||
}
|
}
|
||||||
@ -207,6 +228,15 @@ public final class UserData implements Savable {
|
|||||||
case TYPE_ARRAY:
|
case TYPE_ARRAY:
|
||||||
value = this.readList(ic, "0").toArray();
|
value = this.readList(ic, "0").toArray();
|
||||||
break;
|
break;
|
||||||
|
case TYPE_DOUBLE:
|
||||||
|
value = ic.readDouble("doubleVal", 0.);
|
||||||
|
break;
|
||||||
|
case TYPE_SHORT:
|
||||||
|
value = ic.readShort("shortVal", (short)0);
|
||||||
|
break;
|
||||||
|
case TYPE_BYTE:
|
||||||
|
value = ic.readByte("byteVal", (byte)0);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new UnsupportedOperationException("Unknown type of stored data: " + type);
|
throw new UnsupportedOperationException("Unknown type of stored data: " + type);
|
||||||
}
|
}
|
||||||
@ -255,6 +285,15 @@ public final class UserData implements Savable {
|
|||||||
Map<?, ?> map = (Map<?, ?>) o;
|
Map<?, ?> map = (Map<?, ?>) o;
|
||||||
this.writeList(oc, map.keySet(), listName + "v(keys)" + counter);
|
this.writeList(oc, map.keySet(), listName + "v(keys)" + counter);
|
||||||
this.writeList(oc, map.values(), listName + "v(vals)" + counter);
|
this.writeList(oc, map.values(), listName + "v(vals)" + counter);
|
||||||
|
} else if (o instanceof Double) {
|
||||||
|
oc.write(TYPE_DOUBLE, listName + "t" + counter, 0);
|
||||||
|
oc.write((Double) o, listName + "v" + counter, 0.);
|
||||||
|
} else if (o instanceof Short) {
|
||||||
|
oc.write(TYPE_SHORT, listName + "t" + counter, 0);
|
||||||
|
oc.write((Short) o, listName + "v" + counter, (short)0);
|
||||||
|
} else if (o instanceof Byte) {
|
||||||
|
oc.write(TYPE_BYTE, listName + "t" + counter, 0);
|
||||||
|
oc.write((Byte) o, listName + "v" + counter, (byte)0);
|
||||||
} else {
|
} else {
|
||||||
throw new UnsupportedOperationException("Unsupported type stored in the list: " + o.getClass());
|
throw new UnsupportedOperationException("Unsupported type stored in the list: " + o.getClass());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user