T
- the primary object type that is stored in the given tagZ
- the retrieved object type when applying this tag typepublic interface PersistentDataType<T,Z>
This interface can be used to create your own custom
PersistentDataType
with different complex types. This may be useful
for the likes of a UUIDTagType:
public class UUIDTagType implements PersistentDataType<byte[], UUID> {
{@literal @Override}
public Class<byte[]> getPrimitiveType() {
return byte[].class;
}
{@literal @Override}
public Class<UUID> getComplexType() {
return UUID.class;
}
{@literal @Override}
public byte[] toPrimitive(UUID complex, PersistentDataAdapterContext context) {
ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
bb.putLong(complex.getMostSignificantBits());
bb.putLong(complex.getLeastSignificantBits());
return bb.array();
}
{@literal @Override}
public UUID fromPrimitive(byte[] primitive, PersistentDataAdapterContext context) {
ByteBuffer bb = ByteBuffer.wrap(primitive);
long firstLong = bb.getLong();
long secondLong = bb.getLong();
return new UUID(firstLong, secondLong);
}
}
Modifier and Type | Interface and Description |
---|---|
static class |
PersistentDataType.PrimitivePersistentDataType<T>
A default implementation that simply exists to pass on the retrieved or
inserted value to the next layer.
|
Modifier and Type | Field and Description |
---|---|
static PersistentDataType<Byte,Byte> |
BYTE |
static PersistentDataType<byte[],byte[]> |
BYTE_ARRAY |
static PersistentDataType<Double,Double> |
DOUBLE |
static PersistentDataType<Float,Float> |
FLOAT |
static PersistentDataType<Integer,Integer> |
INTEGER |
static PersistentDataType<int[],int[]> |
INTEGER_ARRAY |
static PersistentDataType<Long,Long> |
LONG |
static PersistentDataType<long[],long[]> |
LONG_ARRAY |
static PersistentDataType<Short,Short> |
SHORT |
static PersistentDataType<String,String> |
STRING |
static PersistentDataType<PersistentDataContainer,PersistentDataContainer> |
TAG_CONTAINER |
static PersistentDataType<PersistentDataContainer[],PersistentDataContainer[]> |
TAG_CONTAINER_ARRAY |
Modifier and Type | Method and Description |
---|---|
Z |
fromPrimitive(T primitive,
@NotNull PersistentDataAdapterContext context)
Creates a complex object based of the passed primitive value
|
@NotNull Class<Z> |
getComplexType()
Returns the complex object type the primitive value resembles.
|
@NotNull Class<T> |
getPrimitiveType()
Returns the primitive data type of this tag.
|
T |
toPrimitive(Z complex,
@NotNull PersistentDataAdapterContext context)
Returns the primitive data that resembles the complex object passed to
this method.
|
static final PersistentDataType<Byte,Byte> BYTE
static final PersistentDataType<Short,Short> SHORT
static final PersistentDataType<Integer,Integer> INTEGER
static final PersistentDataType<Long,Long> LONG
static final PersistentDataType<Float,Float> FLOAT
static final PersistentDataType<Double,Double> DOUBLE
static final PersistentDataType<String,String> STRING
static final PersistentDataType<byte[],byte[]> BYTE_ARRAY
static final PersistentDataType<int[],int[]> INTEGER_ARRAY
static final PersistentDataType<long[],long[]> LONG_ARRAY
static final PersistentDataType<PersistentDataContainer[],PersistentDataContainer[]> TAG_CONTAINER_ARRAY
static final PersistentDataType<PersistentDataContainer,PersistentDataContainer> TAG_CONTAINER
@NotNull @NotNull Class<T> getPrimitiveType()
@NotNull @NotNull Class<Z> getComplexType()
@NotNull T toPrimitive(@NotNull Z complex, @NotNull @NotNull PersistentDataAdapterContext context)
complex
- the complex object instancecontext
- the context this operation is running in@NotNull Z fromPrimitive(@NotNull T primitive, @NotNull @NotNull PersistentDataAdapterContext context)
primitive
- the primitive valuecontext
- the context this operation is running inCopyright © 2021. All rights reserved.