Browse Source

Added interface for serializing (WIP; maybe removed later)

zockerFirstDesign
Felix Stupp 3 years ago
parent
commit
86bed613fa
  1. 7
      src/de/banananetwork/serialize/Serializable.java
  2. 59
      src/de/banananetwork/serialize/SerializedData.java

7
src/de/banananetwork/serialize/Serializable.java

@ -0,0 +1,7 @@
package de.banananetwork.serialize;
public interface Serializable {
SerializedData serialize();
}

59
src/de/banananetwork/serialize/SerializedData.java

@ -0,0 +1,59 @@
package de.banananetwork.serialize;
public interface SerializedData implements Serializable {
@Override
default SerializedData serialize() {
return this;
}
void put(String key, int value);
void put(String key, String value);
default void put(String key, Serializable value) {
put(key, value.serialize());
}
void put(String key, SerializedData value);
void put(String key, int[] values);
void put(String key, String[] values);
default put(String key, Serializable[] values) {
put(key, Arrays.stream(values).map(Serializable::serialize).toArray(SerializedData[]::new));
}
void put(String key, SerializedData[] values);
boolean exists(String key);
Type getType(String key);
boolean isType(String key, Type type);
String[] getKeys();
int getInt(String key);
String getString(String key);
SerializedData getData(String key);
int[] getIntArray(String key);
String[] getStringArray(String key);
SerializedData[] getDataArray(String key);
public enum Type {
INT,
INT_ARRAY,
STRING,
STRING_ARRAY,
SERIALIZED_DATA,
SERIALIZED_DATA_ARRAY;
}
}
Loading…
Cancel
Save