Search in sources :

Example 31 with DataQuery

use of org.spongepowered.api.data.DataQuery in project SpongeCommon by SpongePowered.

the class MemoryDataTest method testGetKeys.

@Test
public void testGetKeys() {
    Set<DataQuery> queries = Sets.newHashSet();
    queries.add(of("foo"));
    queries.add(of("foo", "bar"));
    queries.add(of("foo", "bar", "baz"));
    queries.add(of("bar"));
    DataView view = DataContainer.createNew();
    view.set(of("foo"), "foo");
    view.set(of("foo", "bar"), "foobar");
    view.set(of("foo", "bar", "baz"), "foobarbaz");
    view.set(of("bar"), 1);
    Set<DataQuery> testQueries = Sets.newHashSet();
    testQueries.add(of("foo"));
    testQueries.add(of("bar"));
    Set<DataQuery> shallowKeys = view.getKeys(false);
    assertTrue(shallowKeys.equals(testQueries));
    Set<DataQuery> deepKeys = view.getKeys(true);
    assertTrue(deepKeys.containsAll(queries));
}
Also used : DataView(org.spongepowered.api.data.DataView) DataQuery(org.spongepowered.api.data.DataQuery) Test(org.junit.Test)

Example 32 with DataQuery

use of org.spongepowered.api.data.DataQuery in project SpongeCommon by SpongePowered.

the class MemoryDataTest method testCreateView.

@Test
public void testCreateView() {
    DataContainer container = DataContainer.createNew();
    DataQuery tempQuery = of("foo", "bar", "baz");
    container.createView(tempQuery);
    assertTrue(container.getView(tempQuery).isPresent());
}
Also used : DataContainer(org.spongepowered.api.data.DataContainer) DataQuery(org.spongepowered.api.data.DataQuery) Test(org.junit.Test)

Example 33 with DataQuery

use of org.spongepowered.api.data.DataQuery in project modules-extra by CubeEngine.

the class DuctData method from.

@Override
public Optional<DuctData> from(DataContainer container) {
    Optional<DataView> filters = container.getView(FILTERS.getQuery());
    if (filters.isPresent()) {
        Map<Direction, List<ItemStack>> map = new HashMap<>();
        for (DataQuery key : filters.get().getKeys(false)) {
            Direction dir = Direction.valueOf(key.toString());
            List<ItemStack> list = filters.get().getSerializableList(key, ItemStack.class).orElse(new ArrayList<>());
            map.put(dir, list);
        }
        this.setFilters((map));
        return Optional.of(this);
    }
    Optional<Integer> uses = container.getInt(USES.getQuery());
    if (uses.isPresent()) {
        this.setUses(uses.get());
        return Optional.of(this);
    }
    return Optional.empty();
}
Also used : DataView(org.spongepowered.api.data.DataView) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) DataQuery(org.spongepowered.api.data.DataQuery) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Direction(org.spongepowered.api.util.Direction)

Example 34 with DataQuery

use of org.spongepowered.api.data.DataQuery in project core by CubeEngine.

the class DataContainerConverter method fromNode.

@Override
public DataContainer fromNode(Node node, Class<? extends DataContainer> type, ConverterManager manager) throws ConversionException {
    DataContainer data = DataContainer.createNew();
    for (Entry<String, Node> entry : ((MapNode) node).getValue().entrySet()) {
        DataQuery key = DataQuery.of('_', ((MapNode) node).getOriginalKey(entry.getKey()));
        data.set(key, toObject(entry.getValue(), manager));
    }
    return data;
}
Also used : DataContainer(org.spongepowered.api.data.DataContainer) MapNode(org.cubeengine.converter.node.MapNode) ListNode(org.cubeengine.converter.node.ListNode) Node(org.cubeengine.converter.node.Node) DataQuery(org.spongepowered.api.data.DataQuery)

Example 35 with DataQuery

use of org.spongepowered.api.data.DataQuery in project LanternServer by LanternPowered.

the class MemoryDataView method contains.

@Override
public boolean contains(DataQuery path, DataQuery... paths) {
    checkNotNull(path, "DataQuery cannot be null!");
    checkNotNull(paths, "DataQuery varargs cannot be null!");
    if (paths.length == 0) {
        return contains(path);
    }
    final List<DataQuery> queries = new ArrayList<>();
    queries.add(path);
    for (DataQuery query : paths) {
        queries.add(checkNotNull(query, "No null queries!"));
    }
    for (DataQuery query : queries) {
        if (!contains(query)) {
            return false;
        }
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) DataQuery(org.spongepowered.api.data.DataQuery)

Aggregations

DataQuery (org.spongepowered.api.data.DataQuery)41 DataContainer (org.spongepowered.api.data.DataContainer)23 DataView (org.spongepowered.api.data.DataView)20 Test (org.junit.Test)14 Map (java.util.Map)12 ArrayList (java.util.ArrayList)7 List (java.util.List)7 DataTypeSerializer (org.lanternpowered.server.data.persistence.DataTypeSerializer)7 ImmutableMap (com.google.common.collect.ImmutableMap)4 TypeToken (com.google.common.reflect.TypeToken)4 Collection (java.util.Collection)4 HashMap (java.util.HashMap)4 Set (java.util.Set)4 Collectors (java.util.stream.Collectors)4 Nullable (javax.annotation.Nullable)4 CatalogType (org.spongepowered.api.CatalogType)4 DataSerializable (org.spongepowered.api.data.DataSerializable)4 Vector3i (com.flowpowered.math.vector.Vector3i)3 Lists (com.google.common.collect.Lists)3 LinkedHashMap (java.util.LinkedHashMap)3