本文整理汇总了Java中org.spongepowered.api.data.manipulator.DataManipulator.set方法的典型用法代码示例。如果您正苦于以下问题:Java DataManipulator.set方法的具体用法?Java DataManipulator.set怎么用?Java DataManipulator.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spongepowered.api.data.manipulator.DataManipulator
的用法示例。
在下文中一共展示了DataManipulator.set方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import org.spongepowered.api.data.manipulator.DataManipulator; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Nullable
static DataManipulator create(ValueContainer<?> valueContainer, DataManipulatorRegistration registration) {
DataManipulator manipulator = (DataManipulator<?, ?>) registration.createMutable();
for (Key key : (Set<Key>) registration.getRequiredKeys()) {
final Optional value = valueContainer.get(key);
if (value.isPresent()) {
manipulator.set(key, value.get());
} else if (!valueContainer.supports(key)) {
manipulator = null;
break;
}
}
return manipulator;
}
示例2: get
import org.spongepowered.api.data.manipulator.DataManipulator; //导入方法依赖的package包/类
@SuppressWarnings({"unchecked", "ConstantConditions"})
static <I extends ImmutableDataManipulator<I, M>, M extends DataManipulator<M, I>> Optional<I> get(
IImmutableDataHolderBase<?> dataHolder, DataManipulatorRegistration<M, I> registration, Class<?> containerClass) {
final DataManipulator manipulator = registration.createMutable();
final ImmutableContainerCache cache = dataHolder.getContainerCache();
if (cache != null && cache.manipulators == null) {
cache.manipulators = new HashMap<>();
}
for (Key key : registration.getRequiredKeys()) {
final Optional value = dataHolder.getValue(key);
if (!value.isPresent()) {
if (cache != null) {
cache.manipulators.put(containerClass, ImmutableContainerCache.NONE);
}
return Optional.empty();
}
manipulator.set(key, value.get());
}
final I immutable = (I) manipulator.asImmutable();
if (cache != null) {
cache.manipulators.put(containerClass, immutable);
// In case they are different, unlikely
if (registration.getImmutableManipulatorClass() != containerClass) {
cache.manipulators.put(registration.getImmutableManipulatorClass(), immutable);
}
}
return Optional.of(immutable);
}