本文整理汇总了Java中org.spongepowered.api.data.key.Key.getElementToken方法的典型用法代码示例。如果您正苦于以下问题:Java Key.getElementToken方法的具体用法?Java Key.getElementToken怎么用?Java Key.getElementToken使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spongepowered.api.data.key.Key
的用法示例。
在下文中一共展示了Key.getElementToken方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deserializeForKeys
import org.spongepowered.api.data.key.Key; //导入方法依赖的package包/类
private <T, U extends BaseValue<T>> void deserializeForKeys(
ConfigurationNode node, DataQuery dataQuery, BiConsumer<Key<U>, T> consumer) throws InvalidDataException
{
if (KEYS.containsKey(dataQuery))
{
try
{
@SuppressWarnings("unchecked")
Key<U> key = (Key<U>) KEYS.get(dataQuery);
@SuppressWarnings("unchecked")
TypeToken<T> elementToken = (TypeToken<T>) key.getElementToken();
consumer.accept(key, Optional.ofNullable(node.getValue(elementToken))
.orElseThrow(() -> new InvalidDataException("No value present")));
}
catch (ObjectMappingException e)
{
throw new InvalidDataException(e);
}
}
else if (!EXCEPTIONS.contains(dataQuery))
{
throw new InvalidDataException("No matched query present");
}
}
示例2: toContainer
import org.spongepowered.api.data.key.Key; //导入方法依赖的package包/类
public static DataContainer toContainer(IValueContainer valueContainer) {
final DataContainer dataContainer = DataContainer.createNew();
final ValueCollection valueCollection = valueContainer.getValueCollection();
final LanternDataManager dataManager = Lantern.getGame().getDataManager();
for (KeyRegistration<?,?> registration : valueCollection.getAll()) {
if (!(registration instanceof Element)) {
continue;
}
final Key<?> key = registration.getKey();
final DataQuery dataQuery = key.getQuery();
final TypeToken<?> typeToken = key.getElementToken();
final DataTypeSerializer typeSerializer = dataManager.getTypeSerializer(typeToken)
.orElseThrow(() -> new IllegalStateException("Wasn't able to find a type serializer for the element type: " + typeToken.toString()));
final DataTypeSerializerContext context = dataManager.getTypeSerializerContext();
// The value's shouldn't be null inside a data manipulator,
// since it doesn't support removal of values
dataContainer.set(dataQuery, typeSerializer.serialize(typeToken, context,
checkNotNull(((Element) registration).get(), "element")));
}
return dataContainer;
}
示例3: serializeRawRegisteredKeyData
import org.spongepowered.api.data.key.Key; //导入方法依赖的package包/类
public static void serializeRawRegisteredKeyData(DataView dataView, IValueContainer valueContainer,
Set<Key> ignoredKeys) {
DataView view = null;
final ValueCollection valueCollection = valueContainer.getValueCollection();
final LanternDataManager dataManager = Lantern.getGame().getDataManager();
final DataTypeSerializerContext context = dataManager.getTypeSerializerContext();
for (KeyRegistration<?,?> registration : valueCollection.getAll()) {
final Key<?> key = registration.getKey();
if (!(registration instanceof Element)
|| ignoredKeys.contains(key)
|| key == LanternKeys.FAILED_DATA_MANIPULATORS
|| key == LanternKeys.FAILED_DATA_VALUES) {
continue;
}
final Element element = (Element) registration;
final TypeToken<?> typeToken = key.getElementToken();
final DataTypeSerializer typeSerializer = dataManager.getTypeSerializer(typeToken)
.orElseThrow(() -> new IllegalStateException(
"Wasn't able to find a type serializer for the element type: " + typeToken.toString()));
final Object object = element.get();
if (object == null) {
continue;
}
final Object value = typeSerializer.serialize(typeToken, context, object);
if (view == null) {
view = dataView.createView(DataQueries.DATA_VALUES);
}
view.set(key.getQuery(), value);
}
Element<DataView> holder = valueCollection.getElement(LanternKeys.FAILED_DATA_VALUES).orElse(null);
if (holder != null) {
if (view == null) {
view = dataView.createView(DataQueries.DATA_VALUES);
}
for (Map.Entry<DataQuery, Object> entry : holder.get().getValues(false).entrySet()) {
if (!view.contains(entry.getKey())) {
view.set(entry.getKey(), entry.getValue());
}
}
}
}