use of org.spongepowered.api.data.DataView 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.DataView in project SpongeCommon by SpongePowered.
the class MemoryDataTest method testMaps.
@Test
public void testMaps() {
Map<String, Object> myMap = Maps.newHashMap();
myMap.put("foo", "bar");
myMap.put("myNumber", 1);
List<String> stringList = Lists.newArrayList();
for (int i = 0; i < 100; i++) {
stringList.add("Foo" + i);
}
myMap.put("myList", stringList);
DataView view = DataContainer.createNew();
view.set(of("Foo"), myMap);
Map<?, ?> retrievedMap = view.getMap(of("Foo")).get();
assertTrue(myMap.keySet().equals(retrievedMap.keySet()));
assertTrue(myMap.entrySet().equals(retrievedMap.entrySet()));
}
use of org.spongepowered.api.data.DataView in project SpongeCommon by SpongePowered.
the class MemoryDataTest method testGetKeys.
@Test
public void testGetKeys() {
Set<DataQuery> queries = Sets.newHashSet();
queries.add(of("foo"));
queries.add(of("foo", "bar"));
queries.add(of("foo", "bar", "baz"));
queries.add(of("bar"));
DataView view = DataContainer.createNew();
view.set(of("foo"), "foo");
view.set(of("foo", "bar"), "foobar");
view.set(of("foo", "bar", "baz"), "foobarbaz");
view.set(of("bar"), 1);
Set<DataQuery> testQueries = Sets.newHashSet();
testQueries.add(of("foo"));
testQueries.add(of("bar"));
Set<DataQuery> shallowKeys = view.getKeys(false);
assertTrue(shallowKeys.equals(testQueries));
Set<DataQuery> deepKeys = view.getKeys(true);
assertTrue(deepKeys.containsAll(queries));
}
use of org.spongepowered.api.data.DataView in project SpongeCommon by SpongePowered.
the class ConfigurateDataViewTest method testNodeToData.
@Test
public void testNodeToData() {
ConfigurationNode node = SimpleConfigurationNode.root();
node.getNode("foo", "int").setValue(1);
node.getNode("foo", "double").setValue(10.0D);
node.getNode("foo", "long").setValue(Long.MAX_VALUE);
List<String> stringList = Lists.newArrayList();
for (int i = 0; i < 100; i++) {
stringList.add("String" + i);
}
node.getNode("foo", "stringList").setValue(stringList);
List<SimpleData> dataList = Lists.newArrayList();
for (int i = 0; i < 100; i++) {
dataList.add(new SimpleData(i, 10.0 + i, "String" + i, Collections.<String>emptyList()));
}
node.getNode("foo", "nested", "Data").setValue(dataList);
DataContainer manual = DataContainer.createNew();
manual.set(DataQuery.of("foo", "int"), 1).set(DataQuery.of("foo", "double"), 10.0D).set(DataQuery.of("foo", "long"), Long.MAX_VALUE).set(DataQuery.of("foo", "stringList"), stringList).set(DataQuery.of("foo", "nested", "Data"), dataList);
DataView container = ConfigurateTranslator.instance().translate(node);
assertTrue(manual.equals(container));
ConfigurationNode translated = ConfigurateTranslator.instance().translate(container);
// assertTrue(node.equals(translated)); // TODO Pending Configurate equals implementation
}
use of org.spongepowered.api.data.DataView in project modules-extra by CubeEngine.
the class ReportUtil method name.
public static Text name(BlockSnapshot snapshot, Receiver receiver) {
BlockType type = snapshot.getState().getType();
Translation trans = type.getTranslation();
if (snapshot.getState().getType().getItem().isPresent()) {
trans = ItemStack.builder().fromBlockSnapshot(snapshot).build().getTranslation();
}
Builder builder = Text.builder();
builder.append(Text.of(GOLD, trans).toBuilder().onHover(showText(Text.of(type.getName()))).build());
Optional<List<DataView>> items = snapshot.toContainer().getViewList(BlockReport.BLOCK_ITEMS);
if (items.isPresent() && !items.get().isEmpty()) {
// TODO lookup config : detailed inventory? click on ∋ to activate/deactivate or using cmd
builder.append(Text.of(" ∋ ["));
if (receiver.getLookup().getSettings().showDetailedInventory()) {
builder.append(Text.of(" "));
for (DataView dataView : items.get()) {
DataContainer itemData = DataContainer.createNew();
itemData.set(DataQuery.of("Count"), dataView.get(DataQuery.of("Count")).get());
itemData.set(DataQuery.of("ItemType"), dataView.get(DataQuery.of("id")).get());
Optional<DataView> tag = dataView.getView(DataQuery.of("tag"));
if (tag.isPresent()) {
itemData.set(DataQuery.of("UnsafeData"), tag.get().getValues(false));
}
itemData.set(DataQuery.of("UnsafeDamage"), dataView.get(DataQuery.of("Damage")).get());
ItemStack item = ItemStack.builder().fromContainer(itemData).build();
builder.append(Text.of(dataView.getInt(DataQuery.of("Slot")).get()).toBuilder().onHover(showItem(item.createSnapshot())).build());
builder.append(Text.of(" "));
}
} else {
builder.append(Text.of("..."));
}
builder.append(Text.of("]"));
}
Optional<List<Text>> sign = snapshot.get(Keys.SIGN_LINES);
if (sign.isPresent()) {
builder.append(Text.of(" "), Text.of("[I]").toBuilder().onHover(showText(Text.joinWith(Text.NEW_LINE, sign.get()))).build());
}
return builder.build();
}
Aggregations