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