use of org.spongepowered.api.data.DataQuery 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.DataQuery 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());
}
use of org.spongepowered.api.data.DataQuery in project modules-extra by CubeEngine.
the class DuctData method from.
@Override
public Optional<DuctData> from(DataContainer container) {
Optional<DataView> filters = container.getView(FILTERS.getQuery());
if (filters.isPresent()) {
Map<Direction, List<ItemStack>> map = new HashMap<>();
for (DataQuery key : filters.get().getKeys(false)) {
Direction dir = Direction.valueOf(key.toString());
List<ItemStack> list = filters.get().getSerializableList(key, ItemStack.class).orElse(new ArrayList<>());
map.put(dir, list);
}
this.setFilters((map));
return Optional.of(this);
}
Optional<Integer> uses = container.getInt(USES.getQuery());
if (uses.isPresent()) {
this.setUses(uses.get());
return Optional.of(this);
}
return Optional.empty();
}
use of org.spongepowered.api.data.DataQuery in project core by CubeEngine.
the class DataContainerConverter method fromNode.
@Override
public DataContainer fromNode(Node node, Class<? extends DataContainer> type, ConverterManager manager) throws ConversionException {
DataContainer data = DataContainer.createNew();
for (Entry<String, Node> entry : ((MapNode) node).getValue().entrySet()) {
DataQuery key = DataQuery.of('_', ((MapNode) node).getOriginalKey(entry.getKey()));
data.set(key, toObject(entry.getValue(), manager));
}
return data;
}
use of org.spongepowered.api.data.DataQuery in project LanternServer by LanternPowered.
the class MemoryDataView method contains.
@Override
public boolean contains(DataQuery path, DataQuery... paths) {
checkNotNull(path, "DataQuery cannot be null!");
checkNotNull(paths, "DataQuery varargs cannot be null!");
if (paths.length == 0) {
return contains(path);
}
final List<DataQuery> queries = new ArrayList<>();
queries.add(path);
for (DataQuery query : paths) {
queries.add(checkNotNull(query, "No null queries!"));
}
for (DataQuery query : queries) {
if (!contains(query)) {
return false;
}
}
return true;
}
Aggregations