Search in sources :

Example 26 with DataQuery

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

the class MemoryDataTest method testGetMaps.

@Test
public void testGetMaps() {
    DataView view = DataContainer.createNew();
    view.set(of("foo", "bar", "foo"), "foo");
    view.set(of("foo", "bar", "bar"), "foobar");
    view.set(of("foo", "bar", "baz"), "foobarbaz");
    view.set(of("bar"), 1);
    Map<DataQuery, Object> shallowMap = Maps.newLinkedHashMap();
    shallowMap.put(of("bar"), 1);
    final Map<DataQuery, Object> internalView = Maps.newLinkedHashMap();
    internalView.put(of("foo"), "foo");
    internalView.put(of("bar"), "foobar");
    internalView.put(of("baz"), "foobarbaz");
    Map<DataQuery, Object> intermediateMap = Maps.newLinkedHashMap();
    intermediateMap.put(of("bar"), internalView);
    shallowMap.put(of("foo"), intermediateMap);
    Map<DataQuery, Object> shallowValues = view.getValues(false);
    assertTrue(shallowValues.entrySet().equals(shallowMap.entrySet()));
    final Map<DataQuery, Object> deepMap = Maps.newLinkedHashMap();
    deepMap.put(of("bar"), 1);
    deepMap.put(of("foo", "bar", "foo"), "foo");
    deepMap.put(of("foo", "bar", "bar"), "foobar");
    deepMap.put(of("foo", "bar", "baz"), "foobarbaz");
    deepMap.put(of("foo"), intermediateMap);
    intermediateMap.put(of("bar", "foo"), "foo");
    intermediateMap.put(of("bar", "bar"), "foobar");
    intermediateMap.put(of("bar", "baz"), "foobarbaz");
    deepMap.put(of("foo", "bar"), internalView);
    Map<DataQuery, Object> deepValues = view.getValues(true);
    assertTrue(deepValues.keySet().equals(deepMap.keySet()));
    assertTrue(deepValues.entrySet().equals(deepMap.entrySet()));
}
Also used : DataView(org.spongepowered.api.data.DataView) DataQuery(org.spongepowered.api.data.DataQuery) Test(org.junit.Test)

Example 27 with DataQuery

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

the class MemoryDataTest method testNumbers.

@Test
public void testNumbers() {
    DataContainer container = DataContainer.createNew();
    DataQuery testQuery = of("foo", "bar");
    container.set(testQuery, 1.0D);
    Optional<Integer> integerOptional = container.getInt(testQuery);
    assertTrue(integerOptional.isPresent());
    assertTrue(integerOptional.get() == 1);
    Optional<Long> longOptional = container.getLong(testQuery);
    assertTrue(longOptional.isPresent());
    assertTrue(longOptional.get() == 1L);
    Optional<Double> doubleOptional = container.getDouble(testQuery);
    assertTrue(doubleOptional.isPresent());
    assertTrue(doubleOptional.get() == 1.0D);
}
Also used : DataContainer(org.spongepowered.api.data.DataContainer) DataQuery(org.spongepowered.api.data.DataQuery) Test(org.junit.Test)

Example 28 with DataQuery

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

the class MemoryDataTest method testContainsEmpty.

@Test
public void testContainsEmpty() {
    DataContainer container = DataContainer.createNew();
    DataQuery query = of("");
    assertTrue(!container.contains(query));
    container.set(query, "foo");
    assertTrue(container.contains(query));
    query = of('.', "foo.bar");
    assertTrue(!container.contains(query));
    container.set(query, "baz");
    assertTrue(container.contains(query));
}
Also used : DataContainer(org.spongepowered.api.data.DataContainer) DataQuery(org.spongepowered.api.data.DataQuery) Test(org.junit.Test)

Example 29 with DataQuery

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

the class MemoryDataTest method testLists.

@Test
public void testLists() {
    DataContainer container = DataContainer.createNew();
    DataQuery query = of("foo");
    List<DataView> list = Lists.newArrayList();
    for (int i = 0; i < 1; i++) {
        DataContainer internal = DataContainer.createNew();
        internal.set(of("foo", "bar"), "foo.bar" + i);
        int[] ints = new int[] { 0, 1, 2, 3, i };
        internal.set(of("ints"), Arrays.asList(ints));
        list.add(internal);
    }
    container.set(query, list);
    assertTrue(container.contains(query));
    List<DataView> queriedList = container.getViewList(query).get();
    assertTrue(queriedList.equals(list));
}
Also used : DataView(org.spongepowered.api.data.DataView) DataContainer(org.spongepowered.api.data.DataContainer) DataQuery(org.spongepowered.api.data.DataQuery) Test(org.junit.Test)

Example 30 with DataQuery

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

the class MemoryDataTest method testAbsents.

@Test
public void testAbsents() {
    DataContainer container = DataContainer.createNew();
    DataQuery testQuery = of("foo", "bar", "baz");
    assertTrue(!container.get(testQuery).isPresent());
    assertTrue(!container.getBoolean(testQuery).isPresent());
    assertTrue(!container.getBooleanList(testQuery).isPresent());
    assertTrue(!container.getByteList(testQuery).isPresent());
    assertTrue(!container.getCharacterList(testQuery).isPresent());
    assertTrue(!container.getDouble(testQuery).isPresent());
    assertTrue(!container.getDoubleList(testQuery).isPresent());
    assertTrue(!container.getFloatList(testQuery).isPresent());
    assertTrue(!container.getInt(testQuery).isPresent());
    assertTrue(!container.getIntegerList(testQuery).isPresent());
    assertTrue(!container.getList(testQuery).isPresent());
    assertTrue(!container.getLong(testQuery).isPresent());
    assertTrue(!container.getLongList(testQuery).isPresent());
    assertTrue(!container.getMapList(testQuery).isPresent());
    assertTrue(!container.getShortList(testQuery).isPresent());
    assertTrue(!container.getString(testQuery).isPresent());
    assertTrue(!container.getStringList(testQuery).isPresent());
    assertTrue(!container.getView(testQuery).isPresent());
}
Also used : DataContainer(org.spongepowered.api.data.DataContainer) DataQuery(org.spongepowered.api.data.DataQuery) Test(org.junit.Test)

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