Search in sources :

Example 76 with DataContainer

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

the class ConfigurateTranslator method translateFromNode.

private static DataContainer translateFromNode(ConfigurationNode node) {
    checkNotNull(node, "node");
    DataContainer dataContainer = DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED);
    ConfigurateTranslator.instance().addTo(node, dataContainer);
    return dataContainer;
}
Also used : DataContainer(org.spongepowered.api.data.DataContainer)

Example 77 with DataContainer

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

the class MemoryDataTest method testCopy.

@Test
public void testCopy() {
    final DataContainer container = DataContainer.createNew();
    container.set(of("Foo"), "foo");
    final DataContainer newContainer = container.copy();
    assertTrue(container.equals(newContainer));
    container.set(of("Foo", "bar"), "foo.bar");
    final DataView internal = container.getView(of("Foo")).get().copy();
    final DataContainer internalCopy = DataContainer.createNew().set(of("bar"), "foo.bar");
    assertTrue(internal.equals(internalCopy));
}
Also used : DataView(org.spongepowered.api.data.DataView) DataContainer(org.spongepowered.api.data.DataContainer) Test(org.junit.Test)

Example 78 with DataContainer

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

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

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

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