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;
}
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));
}
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);
}
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));
}
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));
}
Aggregations