Search in sources :

Example 81 with DataContainer

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

the class MemoryDataTest method testDeepSerialization.

@Test
public void testDeepSerialization() {
    List<List<?>> values = Lists.newArrayList();
    List<List<?>> sub = Lists.newArrayList();
    values.add(sub);
    SimpleData data1 = new SimpleData(1, 2.0, "3", Arrays.asList("foo", "bar", "baz"));
    SimpleData data2 = new SimpleData(2, 3.0, "4", Arrays.asList("bar", "baz", "foo"));
    SimpleData data3 = new SimpleData(3, 4.0, "5", Arrays.asList("baz", "foo", "bar"));
    sub.add(ImmutableList.of(data1));
    sub.add(ImmutableList.of(data2));
    DataContainer main = DataContainer.createNew();
    main.set(DataQuery.of("ROOT"), data3);
    main.set(DataQuery.of("SINGLE"), ImmutableList.of(data2));
    main.set(DataQuery.of("SUB"), values);
    main.getMap(of()).get();
}
Also used : DataContainer(org.spongepowered.api.data.DataContainer) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Test(org.junit.Test)

Example 82 with DataContainer

use of org.spongepowered.api.data.DataContainer 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)

Example 83 with DataContainer

use of org.spongepowered.api.data.DataContainer 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 84 with DataContainer

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

the class MemoryDataTest method testGetSerializable.

@Test
public void testGetSerializable() throws Exception {
    initBuilder();
    List<String> myList = ImmutableList.of("foo", "bar", "baz");
    SimpleData temp = new SimpleData(1, 2.0, "foo", myList);
    DataContainer container = temp.toContainer();
    Optional<SimpleData> fromContainer = container.getSerializable(of(), SimpleData.class);
    assertTrue(fromContainer.isPresent());
    assertTrue(Objects.equal(fromContainer.get(), temp));
    assertTrue(container.contains(of("myStringList")));
    assertTrue(container.getStringList(of("myStringList")).get().equals(myList));
}
Also used : DataContainer(org.spongepowered.api.data.DataContainer) Test(org.junit.Test)

Example 85 with DataContainer

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

the class MemoryDataTest method testGetName.

@Test
public void testGetName() {
    DataContainer container = DataContainer.createNew();
    assertTrue(container.getName() != null);
}
Also used : DataContainer(org.spongepowered.api.data.DataContainer) Test(org.junit.Test)

Aggregations

DataContainer (org.spongepowered.api.data.DataContainer)110 DataView (org.spongepowered.api.data.DataView)30 DataQuery (org.spongepowered.api.data.DataQuery)28 Test (org.junit.Test)24 List (java.util.List)15 Map (java.util.Map)15 ArrayList (java.util.ArrayList)13 Nullable (javax.annotation.Nullable)11 Collection (java.util.Collection)10 ImmutableList (com.google.common.collect.ImmutableList)9 ImmutableMap (com.google.common.collect.ImmutableMap)9 IOException (java.io.IOException)9 Path (java.nio.file.Path)9 Optional (java.util.Optional)9 CatalogType (org.spongepowered.api.CatalogType)9 Sponge (org.spongepowered.api.Sponge)8 Set (java.util.Set)7 Collectors (java.util.stream.Collectors)7 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)7 DataSerializable (org.spongepowered.api.data.DataSerializable)7