当前位置: 首页>>代码示例>>Java>>正文


Java DataManipulator类代码示例

本文整理汇总了Java中org.spongepowered.api.data.manipulator.DataManipulator的典型用法代码示例。如果您正苦于以下问题:Java DataManipulator类的具体用法?Java DataManipulator怎么用?Java DataManipulator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DataManipulator类属于org.spongepowered.api.data.manipulator包,在下文中一共展示了DataManipulator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getData

import org.spongepowered.api.data.manipulator.DataManipulator; //导入依赖的package包/类
@JsonDetails
public Map<String, Object> getData() {
    HashMap<String, Object> data = new HashMap<>();
    Map<String, Class<? extends DataManipulator<?, ?>>> supData = WebAPI.getSerializeService().getSupportedData();
    for (Map.Entry<String, Class<? extends DataManipulator<?, ?>>> entry : supData.entrySet()) {
        try {
            if (!value.supports(entry.getValue()))
                continue;

            Optional<?> m = value.get(entry.getValue());

            if (!m.isPresent())
                continue;

            data.put(entry.getKey(), ((DataManipulator) m.get()).copy());
        } catch (IllegalArgumentException | IllegalStateException ignored) {
        }
    }
    return data;
}
 
开发者ID:Valandur,项目名称:Web-API,代码行数:21,代码来源:FluidStackView.java

示例2: removeFast

import org.spongepowered.api.data.manipulator.DataManipulator; //导入依赖的package包/类
@Override
default boolean removeFast(Class<? extends DataManipulator<?,?>> containerClass) {
    checkNotNull(containerClass, "containerClass");
    // You cannot remove default data manipulators?
    final Optional optRegistration = DataManipulatorRegistry.get().getBy(containerClass);
    if (optRegistration.isPresent()) {
        return false;
    }

    if (this instanceof AdditionalContainerHolder) {
        final AdditionalContainerCollection<DataManipulator<?,?>> containers =
                ((AdditionalContainerHolder<DataManipulator<?,?>>) this).getAdditionalContainers();
        final Optional<DataManipulator<?,?>> old = containers.remove(containerClass);
        if (old.isPresent()) {
            return true;
        }
    }

    return false;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:21,代码来源:IDataHolder.java

示例3: remove

import org.spongepowered.api.data.manipulator.DataManipulator; //导入依赖的package包/类
@Override
default DataTransactionResult remove(Class<? extends DataManipulator<?,?>> containerClass) {
    checkNotNull(containerClass, "containerClass");
    // You cannot remove default data manipulators?
    final Optional optRegistration = DataManipulatorRegistry.get().getBy(containerClass);
    if (optRegistration.isPresent()) {
        return DataTransactionResult.failNoData();
    }

    if (this instanceof AdditionalContainerHolder) {
        final AdditionalContainerCollection<DataManipulator<?,?>> containers =
                ((AdditionalContainerHolder<DataManipulator<?,?>>) this).getAdditionalContainers();
        final Optional<DataManipulator<?,?>> old = containers.remove(containerClass);
        if (old.isPresent()) {
            return DataTransactionResult.successRemove(old.get().getValues());
        }
    }

    return DataTransactionResult.failNoData();
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:21,代码来源:IDataHolder.java

示例4: supports

import org.spongepowered.api.data.manipulator.DataManipulator; //导入依赖的package包/类
@Override
default boolean supports(Class<? extends DataManipulator<?,?>> containerClass) {
    checkNotNull(containerClass, "containerClass");

    // Offer all the default key values as long if they are supported
    final Optional<DataManipulatorRegistration> optRegistration = DataManipulatorRegistry.get().getBy(containerClass);
    if (optRegistration.isPresent()) {
        final DataManipulatorRegistration registration = optRegistration.get();
        for (Key key : (Set<Key>) registration.getRequiredKeys()) {
            if (!supports(key)) {
                return false;
            }
        }
        return true;
    }

    // Support all the additional manipulators
    return this instanceof AdditionalContainerHolder;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:20,代码来源:IDataHolder.java

示例5: get

import org.spongepowered.api.data.manipulator.DataManipulator; //导入依赖的package包/类
@Override
default <T extends DataManipulator<?,?>> Optional<T> get(Class<T> containerClass) {
    checkNotNull(containerClass, "containerClass");

    // Check default registrations
    final Optional<DataManipulatorRegistration> optRegistration = DataManipulatorRegistry.get().getBy(containerClass);
    if (optRegistration.isPresent()) {
        final DataManipulator manipulator = DataHelper.create(this, optRegistration.get());
        return manipulator == null ? Optional.empty() : Optional.of(
                (T) (ImmutableDataManipulator.class.isAssignableFrom(containerClass) ? manipulator.asImmutable() : manipulator));
    }

    // Try the additional containers if they are supported
    if (this instanceof AdditionalContainerHolder) {
        final AdditionalContainerCollection<DataManipulator<?,?>> containers =
                ((AdditionalContainerHolder<DataManipulator<?,?>>) this).getAdditionalContainers();
        return containers.get(containerClass);
    }

    return Optional.empty();
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:22,代码来源:IDataHolder.java

示例6: getContainers

import org.spongepowered.api.data.manipulator.DataManipulator; //导入依赖的package包/类
@Override
default Collection<DataManipulator<?, ?>> getContainers() {
    final ImmutableList.Builder<DataManipulator<?, ?>> builder = ImmutableList.builder();
    for (DataManipulatorRegistration registration : DataManipulatorRegistry.get().getAll()) {
        final DataManipulator manipulator = DataHelper.create(this, registration);
        if (manipulator != null) {
            builder.add(manipulator);
        }
    }

    // Try the additional manipulators if they are supported
    if (this instanceof AdditionalContainerHolder) {
        final AdditionalContainerCollection<DataManipulator<?,?>> containers =
                ((AdditionalContainerHolder<DataManipulator<?,?>>) this).getAdditionalContainers();
        containers.getAll().forEach(manipulator -> builder.add(manipulator.copy()));
    }

    return builder.build();
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:20,代码来源:IDataHolder.java

示例7: getDataValue

import org.spongepowered.api.data.manipulator.DataManipulator; //导入依赖的package包/类
@SuppressWarnings({"rawtypes", "unchecked"})
public byte getDataValue(Collection<DataManipulator<?, ?>> manipulators, BlockType target) {
    final DataTypeConverter converter = getConverter(target);
    Collection<DataManipulator<?, ?>> data = Collections2.filter(manipulators, input -> {
        if (input == null) {
            return false;
        }
        try {
            Class<? extends DataManipulator<?, ?>> clazz = (Class<? extends DataManipulator<?, ?>>)
                    Class.forName(input.getClass().getName().split("\\$")[0]);
            return converter.getApplicableDataTypes().contains(clazz);
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
            return false;
        }
    });
    return converter.of(data);
}
 
开发者ID:LapisBlue,项目名称:Pore,代码行数:19,代码来源:BlockDataConverter.java

示例8: of

import org.spongepowered.api.data.manipulator.DataManipulator; //导入依赖的package包/类
@SuppressWarnings({"rawtypes", "unchecked"})
public byte of(Collection<DataManipulator<?, ?>> data) {
    HashMap<String, DataManipulator> dataMap = Maps.newHashMap();
    for (DataManipulator datum : data) {
        dataMap.put(datum.getClass().getName().split("\\$")[0], datum);
    }
    BiMap<AbstractDataValue, Byte>[] biMapList = new BiMap[converters.size()];
    converters.keySet().toArray(biMapList);
    Byte[] bitSetSizes = new Byte[converters.size()];
    converters.values().toArray(bitSetSizes);
    byte finalValue = 0;
    byte bitOffset = 0;
    for (int i = 0; i < applicableTypes.size(); i++) {
        byte bitsToConsider = bitSetSizes[i];
        assert bitOffset + bitsToConsider <= 8;
        if (dataMap.containsKey(applicableTypes.get(i).getName())) {
            DataManipulator datum = dataMap.get(applicableTypes.get(i).getName());
            BiMap<AbstractDataValue, Byte> bm = biMapList[i];
            AbstractDataValue adv = AbstractDataValue.of(datum);
            finalValue |= bm.containsKey(adv) ? bm.get(adv) << bitOffset : 0; // mask the value onto the data byte
        }
        bitOffset += bitsToConsider;
    }
    return finalValue;
}
 
开发者ID:LapisBlue,项目名称:Pore,代码行数:26,代码来源:DataTypeConverter.java

示例9: testAbstraction

import org.spongepowered.api.data.manipulator.DataManipulator; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static void testAbstraction(BlockType blockType, byte rawData,
        Collection<? extends AbstractDataValue<? extends DataManipulator, ?>>
                abstractedData,
        boolean invert) throws Exception {
    Method getConverter = BlockDataConverter.class.getDeclaredMethod("getConverter", BlockType.class);
    getConverter.setAccessible(true);
    DataTypeConverter converter = (DataTypeConverter) getConverter.invoke(BlockDataConverter.INSTANCE, blockType);
    Collection<AbstractDataValue> derived = converter.of(rawData);
    if (invert) {
        assertFalse(derived.containsAll(abstractedData) && abstractedData.containsAll(derived));
    } else {
        assertTrue("Missing expected data values", derived.containsAll(abstractedData));
        assertTrue("Found unexpected data values", abstractedData.containsAll(derived));
    }
}
 
开发者ID:LapisBlue,项目名称:Pore,代码行数:17,代码来源:BTDCTestUtil.java

示例10: getData

import org.spongepowered.api.data.manipulator.DataManipulator; //导入依赖的package包/类
@JsonDetails
public Map<String, Object> getData() {
    HashMap<String, Object> data = new HashMap<>();
    // Add properties
    for (Property<?, ?> property : value.getApplicableProperties()) {
        String key = property.getKey().toString();
        key = key.replace("Property", "");
        key = Character.toLowerCase(key.charAt(0)) + key.substring(1);
        data.put(key, property.getValue());
    }
    // Add data
    Map<String, Class<? extends DataManipulator<?, ?>>> supData = WebAPI.getSerializeService().getSupportedData();
    for (Map.Entry<String, Class<? extends DataManipulator<?, ?>>> entry : supData.entrySet()) {
        try {
            if (!value.supports(entry.getValue()))
                continue;

            Optional<?> m = value.get(entry.getValue());

            if (!m.isPresent())
                continue;

            data.put(entry.getKey(), ((DataManipulator) m.get()).copy());
        } catch (IllegalArgumentException | IllegalStateException ignored) {
        }
    }
    return data;
}
 
开发者ID:Valandur,项目名称:Web-API,代码行数:29,代码来源:ItemStackView.java

示例11: deserialize

import org.spongepowered.api.data.manipulator.DataManipulator; //导入依赖的package包/类
@Override
public ItemStack deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
    JsonNode root = p.readValueAsTree();
    if (root.path("type").path("id").isMissingNode())
        throw new IOException("Missing item type");

    String id = root.path("type").path("id").asText();
    Optional<ItemType> optType = Sponge.getRegistry().getType(ItemType.class, id);
    if (!optType.isPresent())
        throw new IOException("Invalid item type " + id);

    Integer amount = root.path("quantity").isMissingNode() ? 1 : root.path("quantity").asInt();

    ItemType type = optType.get();

    ItemStack.Builder builder = ItemStack.builder().itemType(type).quantity(amount);
    ItemStack item = builder.build();

    if (!root.path("data").isMissingNode()) {
        Iterator<Map.Entry<String, JsonNode>> it = root.path("data").fields();
        while (it.hasNext()) {
            Map.Entry<String, JsonNode> entry = it.next();
            Class<? extends DataManipulator> c = WebAPI.getSerializeService().getSupportedData().get(entry.getKey());
            if (c == null) continue;
            Optional<? extends DataManipulator> optData = item.getOrCreate(c);
            if (!optData.isPresent())
                throw new IOException("Invalid item data: " + entry.getKey());
            DataManipulator data = optData.get();
            item.offer(data);
        }
    }

    return item;
}
 
开发者ID:Valandur,项目名称:Web-API,代码行数:35,代码来源:ItemStackDeserializer.java

示例12: deserialize

import org.spongepowered.api.data.manipulator.DataManipulator; //导入依赖的package包/类
@Override
public ItemStackSnapshot deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
    JsonNode root = p.readValueAsTree();
    if (root.path("type").path("id").isMissingNode())
        throw new IOException("Missing item type");

    String id = root.path("type").path("id").asText();
    Optional<ItemType> optType = Sponge.getRegistry().getType(ItemType.class, id);
    if (!optType.isPresent())
        throw new IOException("Invalid item type " + id);

    Integer amount = root.path("quantity").isMissingNode() ? 1 : root.path("quantity").asInt();

    ItemType type = optType.get();

    ItemStack.Builder builder = ItemStack.builder().itemType(type).quantity(amount);
    ItemStack item = builder.build();

    if (!root.path("data").isMissingNode()) {
        Iterator<Map.Entry<String, JsonNode>> it = root.path("data").fields();
        while (it.hasNext()) {
            Map.Entry<String, JsonNode> entry = it.next();
            Class<? extends DataManipulator> c = WebAPI.getSerializeService().getSupportedData().get(entry.getKey());
            if (c == null) continue;
            Optional<? extends DataManipulator> optData = item.getOrCreate(c);
            if (!optData.isPresent())
                throw new IOException("Invalid item data: " + entry.getKey());
            DataManipulator data = optData.get();
            item.offer(data);
        }
    }

    return item.createSnapshot();
}
 
开发者ID:Valandur,项目名称:Web-API,代码行数:35,代码来源:ItemStackSnapshotDeserializer.java

示例13: CachedObject

import org.spongepowered.api.data.manipulator.DataManipulator; //导入依赖的package包/类
public CachedObject(T value, boolean serializeDataHolder) {
    this.cachedAt = System.nanoTime();
    this.cacheService = WebAPIAPI.getCacheService().orElse(null);
    this.serializeService = WebAPIAPI.getJsonService().orElse(null);

    this.cacheDuration = cacheService.getCacheDurationFor(this.getClass());

    if (value != null) this.clazz = value.getClass();

    if (serializeDataHolder && value instanceof DataHolder) {
        DataHolder holder = (DataHolder)value;

        Map<String, Class<? extends DataManipulator<?, ?>>> supData = serializeService.getSupportedData();
        for (Map.Entry<String, Class<? extends DataManipulator<?, ?>>> entry : supData.entrySet()) {
            try {
                if (!holder.supports(entry.getValue()))
                    continue;

                Optional<?> m = holder.get(entry.getValue());

                if (!m.isPresent())
                    continue;

                data.put(entry.getKey(), ((DataManipulator) m.get()).copy());
            } catch (IllegalArgumentException | IllegalStateException ignored) {
            }
        }
    }
}
 
开发者ID:Valandur,项目名称:Web-API,代码行数:30,代码来源:CachedObject.java

示例14: LanternFluidStack

import org.spongepowered.api.data.manipulator.DataManipulator; //导入依赖的package包/类
private LanternFluidStack(FluidType fluidType, int volume,
        ValueCollection valueCollection, AdditionalContainerCollection<DataManipulator<?, ?>> additionalContainers) {
    this.valueCollection = valueCollection;
    this.additionalContainers = additionalContainers;
    this.fluidType = fluidType;
    this.volume = volume;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:8,代码来源:LanternFluidStack.java

示例15: serializeRawContainerData

import org.spongepowered.api.data.manipulator.DataManipulator; //导入依赖的package包/类
public static void serializeRawContainerData(DataView dataView, IValueContainer valueContainer, DataQuery query) {
    if (!(valueContainer instanceof AdditionalContainerHolder)) {
        return;
    }
    final ValueCollection valueCollection = valueContainer.getValueCollection();
    final AdditionalContainerCollection<ValueContainer<?>> containers =
            ((AdditionalContainerHolder) valueContainer).getAdditionalContainers();
    final ImmutableList.Builder<DataView> builder = ImmutableList.builder();
    final LanternDataManager dataManager = Lantern.getGame().getDataManager();
    for (ValueContainer<?> manipulator : containers.getAll()) {
        if (!(manipulator instanceof DataManipulator)) {
            continue;
        }
        final Class<?> manipulatorType;
        if (manipulator instanceof IDataManipulator) {
            manipulatorType = ((IDataManipulator) manipulator).getMutableType();
        } else {
            manipulatorType = manipulator.getClass();
        }
        final Optional<DataRegistration> optRegistration = dataManager.get(manipulatorType);
        if (!optRegistration.isPresent()) {
            getLogger().error("Could not serialize {}. No registration could be found.", manipulatorType.getName());
        } else {
            builder.add(DataContainer.createNew()
                    .set(DataQueries.MANIPULATOR_ID, optRegistration.get().getId())
                    .set(DataQueries.MANIPULATOR_DATA, ((DataManipulator) manipulator).toContainer()));
        }
    }
    Element<List<DataView>> holder = valueCollection.getElement(LanternKeys.FAILED_DATA_MANIPULATORS).orElse(null);
    if (holder != null) {
        builder.addAll(holder.get());
    }
    dataView.set(query, builder.build());
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:35,代码来源:DataHelper.java


注:本文中的org.spongepowered.api.data.manipulator.DataManipulator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。