use of org.spongepowered.api.data.DataQuery in project SpongeCommon by SpongePowered.
the class HomeDataImpl method from.
// Only required on mutable implementations
@Override
public Optional<HomeData> from(DataContainer container) {
if (!container.contains(MyHomes.DEFAULT_HOME, MyHomes.HOMES)) {
return Optional.empty();
}
// Loads the structure defined in toContainer
this.defaultHome = container.getSerializable(MyHomes.DEFAULT_HOME.getQuery(), Home.class).get();
// Loads the map of homes
this.homes = Maps.newHashMap();
DataView homes = container.getView(MyHomes.HOMES.getQuery()).get();
for (DataQuery homeQuery : homes.getKeys(false)) {
homes.getSerializable(homeQuery, Home.class).ifPresent(home -> this.homes.put(homeQuery.toString(), home));
}
return Optional.of(this);
}
use of org.spongepowered.api.data.DataQuery in project SpongeCommon by SpongePowered.
the class MemoryDataView method createView.
@Override
public DataView createView(DataQuery path) {
checkNotNull(path, "path");
List<String> queryParts = path.getParts();
int sz = queryParts.size();
checkArgument(sz != 0, "The size of the query must be at least 1");
String key = queryParts.get(0);
DataQuery keyQuery = of(key);
if (sz == 1) {
DataView result = new MemoryDataView(this, keyQuery, this.safety);
this.map.put(key, result);
return result;
}
DataQuery subQuery = path.popFirst();
DataView subView = (DataView) this.map.get(key);
if (subView == null) {
subView = new MemoryDataView(this.parent, keyQuery, this.safety);
this.map.put(key, subView);
}
return subView.createView(subQuery);
}
use of org.spongepowered.api.data.DataQuery in project SpongeCommon by SpongePowered.
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);
}
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;
}
use of org.spongepowered.api.data.DataQuery in project core by CubeEngine.
the class DataContainerConverter method toMap.
private Map toMap(MapNode node, ConverterManager manager) throws ConversionException {
Map<DataQuery, Object> map = new HashMap<>();
for (Entry<String, Node> entry : node.getMappedNodes().entrySet()) {
DataQuery key = DataQuery.of('_', node.getOriginalKey(entry.getKey()));
map.put(key, toObject(entry.getValue(), manager));
}
return map;
}
use of org.spongepowered.api.data.DataQuery in project LanternServer by LanternPowered.
the class MemoryDataView method createView.
@Override
public DataView createView(DataQuery path) {
checkNotNull(path, "path");
final List<String> queryParts = path.getParts();
final int sz = queryParts.size();
checkArgument(sz != 0, "The size of the query must be at least 1");
final String key = queryParts.get(0);
final DataQuery keyQuery = of(key);
if (sz == 1) {
final DataView result = new MemoryDataView(this, keyQuery, this.safety);
this.map.put(key, result);
return result;
}
final DataQuery subQuery = path.popFirst();
final DataView subView = (DataView) this.map.computeIfAbsent(key, key1 -> new MemoryDataView(this.parent, keyQuery, this.safety));
return subView.createView(subQuery);
}
Aggregations