接口 PersistentDataType<P,C>
- 类型参数:
P- 存储在给定标签中的主要对象类型C- 应用此标签类型时检索到的对象类型
- 所有已知子接口:
ListPersistentDataType<P,C>
- 所有已知实现类:
PersistentDataType.BooleanPersistentDataType,PersistentDataType.PrimitivePersistentDataType
public interface PersistentDataType<P,C>
此类表示一个具有泛型内容类型的枚举。它定义了自定义标签可以具有的类型。
此接口可用于创建您自己的具有不同复杂类型的自定义 PersistentDataType。这对于 UUIDTagType 等可能很有用:
public class UUIDTagType implements PersistentDataType<byte[], UUID> {
@Override
public Class<byte[]> getPrimitiveType() {
return byte[].class;
}
@Override
public Class<UUID> getComplexType() {
return UUID.class;
}
@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();
}
@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);
}
}
任何插件拥有的此接口的实现都需要定义此接口中找到的现有原始类型之一。特别是 BOOLEAN 不是原始类型,而是便捷类型。-
嵌套类概要
嵌套类修饰符和类型接口说明static class一个便捷实现,用于在 Byte 和 Boolean 之间转换,因为布尔值没有原生实现。static class一个默认实现,仅用于将检索或插入的值传递到下一层。 -
字段概要
字段修饰符和类型字段说明static final PersistentDataType<Byte,Boolean> 一个便捷实现,用于在 Byte 和 Boolean 之间转换,因为布尔值没有原生实现。static final PersistentDataType<Byte,Byte> static final PersistentDataType<byte[],byte[]> static final PersistentDataType<Double,Double> static final PersistentDataType<Float,Float> static final PersistentDataType<Integer,Integer> static final PersistentDataType<int[],int[]> static final ListPersistentDataTypeProvider一个数据类型提供者类型,其本身不能用作PersistentDataType。static final PersistentDataType<Long,Long> static final PersistentDataType<long[],long[]> static final PersistentDataType<Short,Short> static final PersistentDataType<String,String> static final PersistentDataType<PersistentDataContainer,PersistentDataContainer> static final PersistentDataType<PersistentDataContainer[],PersistentDataContainer[]> 已过时。 -
方法概要
修饰符和类型方法说明fromPrimitive(P primitive, @NotNull PersistentDataAdapterContext context) 基于传递的原始值创建复杂对象。返回原始值所代表的复杂对象类型。返回此标签的原始数据类型。toPrimitive(C complex, @NotNull PersistentDataAdapterContext context) 返回与此方法传递的复杂对象相似的原始数据。
-
字段详细资料
-
BYTE
-
SHORT
-
INTEGER
-
LONG
-
FLOAT
-
DOUBLE
-
BOOLEAN
一个便捷实现,用于在 Byte 和 Boolean 之间转换,因为布尔值没有原生实现。
任何不等于 0 的字节值都被视为 true。 -
STRING
-
BYTE_ARRAY
-
INTEGER_ARRAY
-
LONG_ARRAY
-
TAG_CONTAINER_ARRAY
@Deprecated(since="1.20.4") static final PersistentDataType<PersistentDataContainer[],PersistentDataContainer[]> TAG_CONTAINER_ARRAY已过时。使用LIST的ListPersistentDataTypeProvider.dataContainers()代替,因为ListPersistentDataType提供对原始类型的完整支持,例如PersistentDataContainer。 -
TAG_CONTAINER
-
LIST
一个数据类型提供者类型,其本身不能用作PersistentDataType。ListPersistentDataTypeProvider暴露了共享的持久数据类型,用于存储其他数据类型的列表。它在
PersistentDataType接口中的存在不允许List作为原始类型与普通的PersistentDataType结合使用。List只有在通过ListPersistentDataType使用时才是有效的原始类型。
-
-
方法详细资料
-
getPrimitiveType
返回此标签的原始数据类型。原文: Returns the primitive data type of this tag.
- 返回:
- 类
-
getComplexType
返回原始值所代表的复杂对象类型。原文: Returns the complex object type the primitive value resembles.
- 返回:
- 类类型
-
toPrimitive
返回与此方法传递的复杂对象相似的原始数据。原文: Returns the primitive data that resembles the complex object passed to this method.
- 参数:
complex- 复杂对象实例context- 此操作运行的上下文- 返回:
- 原始值
-
fromPrimitive
@NotNull C fromPrimitive(@NotNull P primitive, @NotNull @NotNull PersistentDataAdapterContext context) 基于传递的原始值创建复杂对象。原文: Creates a complex object based of the passed primitive value
- 参数:
primitive- 原始值context- 此操作运行的上下文- 返回:
- 复杂对象实例
-
LIST的ListPersistentDataTypeProvider.dataContainers()代替,因为ListPersistentDataType提供对原始类型的完整支持,例如PersistentDataContainer。