Search in sources :

Example 6 with DataQuery

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

the class MemoryDataTest method testNumberedLists.

@Test
public void testNumberedLists() {
    DataContainer container = DataContainer.createNew();
    DataQuery testQuery = of("foo", "bar", "baz");
    List<Integer> intList = ImmutableList.of(1, 2, 3, 4);
    container.set(testQuery, intList);
    assertTrue(container.getIntegerList(testQuery).isPresent());
    assertTrue(container.getIntegerList(testQuery).get().equals(intList));
    List<Double> doubleList = ImmutableList.of(1.0D, 2.0D, 3.0D, 4.0D);
    container.set(testQuery, doubleList);
    assertTrue(container.getDoubleList(testQuery).isPresent());
    assertTrue(container.getDoubleList(testQuery).get().equals(doubleList));
    List<Short> shortList = ImmutableList.of((short) 1, (short) 2, (short) 3, (short) 4);
    container.set(testQuery, shortList);
    assertTrue(container.getShortList(testQuery).isPresent());
    assertTrue(container.getShortList(testQuery).get().equals(shortList));
    List<Byte> byteList = ImmutableList.of((byte) 1, (byte) 2, (byte) 3, (byte) 4);
    container.set(testQuery, byteList);
    assertTrue(container.getByteList(testQuery).isPresent());
    assertTrue(container.getByteList(testQuery).get().equals(byteList));
}
Also used : DataContainer(org.spongepowered.api.data.DataContainer) DataQuery(org.spongepowered.api.data.DataQuery) Test(org.junit.Test)

Example 7 with DataQuery

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

the class MemoryDataTest method testEmptyQuery.

@Test
public void testEmptyQuery() {
    DataContainer container = DataContainer.createNew();
    DataQuery query = of("");
    container.set(query, "foo");
    assertTrue(container.get(query).isPresent());
    assertTrue(container.get(query).get().equals("foo"));
}
Also used : DataContainer(org.spongepowered.api.data.DataContainer) DataQuery(org.spongepowered.api.data.DataQuery) Test(org.junit.Test)

Example 8 with DataQuery

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

the class MemoryDataTest method testBoolean.

@Test
public void testBoolean() {
    DataContainer container = DataContainer.createNew();
    DataQuery testQuery = of("foo", "bar");
    container.set(testQuery, false);
    Optional<Boolean> booleanOptional = container.getBoolean(testQuery);
    assertTrue(booleanOptional.isPresent());
    assertTrue(!booleanOptional.get());
}
Also used : DataContainer(org.spongepowered.api.data.DataContainer) DataQuery(org.spongepowered.api.data.DataQuery) Test(org.junit.Test)

Example 9 with DataQuery

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

the class MemoryDataTest method testIncorrectType.

@Test
public void testIncorrectType() {
    DataContainer container = DataContainer.createNew();
    DataQuery testQuery = of("foo", "bar");
    container.set(testQuery, "foo");
    Optional<Integer> optional = container.getInt(testQuery);
    assertTrue(!optional.isPresent());
}
Also used : DataContainer(org.spongepowered.api.data.DataContainer) DataQuery(org.spongepowered.api.data.DataQuery) Test(org.junit.Test)

Example 10 with DataQuery

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

the class MemoryDataTest method testSetData.

@Test
public void testSetData() {
    DataContainer container = DataContainer.createNew();
    DataQuery testQuery = of('.', "foo.bar");
    container.set(testQuery, 1);
    Optional<Integer> optional = container.getInt(testQuery);
    assertTrue(optional.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