Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ static DataContainer createNew(SafetyMode safety) {
@Override
DataContainer set(DataQuery path, Object value);

@Override
default DataContainer set(String key, Object value) {
return this.set(DataQuery.of(key), value);
}

@Override
DataContainer remove(DataQuery path);
}
30 changes: 30 additions & 0 deletions src/main/java/org/spongepowered/api/data/persistence/DataView.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Stream;

/**
* Represents an object of data represented by a map.
Expand Down Expand Up @@ -106,6 +107,15 @@ public interface DataView {
*/
Set<DataQuery> keys(boolean deep);

/**
* Gets a Stream containing all root keys for this {@link DataView}.
*
* @return Stream of root keys of this container
*/
default Stream<String> streamRootKeys() {
return this.keys(false).stream().map(k -> k.parts().getFirst());
}

/**
* Gets a Map containing all keys and their values for this {@link DataView}.
*
Expand All @@ -121,6 +131,15 @@ public interface DataView {
*/
Map<DataQuery, Object> values(boolean deep);

/**
* Gets a Stream containing all root keys and their values for this {@link DataView}.
*
* @return Stream of root keys and values of this container
*/
default Stream<Map.Entry<String, Object>> streamRootValues() {
return this.values(false).entrySet().stream().map(entry -> Map.entry(entry.getKey().parts().getFirst(), entry.getValue()));
}

/**
* Returns whether this {@link DataView} contains the given path.
*
Expand Down Expand Up @@ -158,6 +177,17 @@ public interface DataView {
*/
DataView set(DataQuery path, Object value);

/**
* Sets the given Object value to this {@link DataView}'s key.
*
* @param key The key of the object to set
* @param value The value of the data
* @return This view, for chaining
*/
default DataView set(String key, Object value) {
return this.set(DataQuery.of(key), value);
}

/**
* Removes the data associated to the given path relative to this
* {@link DataView}'s path.
Expand Down
Loading