Skip to content

Commit 12e88cc

Browse files
committed
Add String based createView and getView to DataView
1 parent 6c0209e commit 12e88cc

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

  • src/main/java/org/spongepowered/api/data/persistence

src/main/java/org/spongepowered/api/data/persistence/DataView.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,18 @@ default DataView set(String key, double value) {
393393
*/
394394
DataView createView(DataQuery path);
395395

396+
/**
397+
* Creates a new {@link DataView} at the desired key.
398+
* <p>If any data existed at the given path, that data will be
399+
* overwritten with the newly constructed {@link DataView}.</p>
400+
*
401+
* @param key The key of the new view
402+
* @return The newly created view
403+
*/
404+
default DataView createView(String key) {
405+
return this.createView(DataQuery.of(key));
406+
}
407+
396408
/**
397409
* Creates a new {@link DataView} with the given data at the desired
398410
* path.
@@ -418,6 +430,20 @@ default DataView set(String key, double value) {
418430
*/
419431
Optional<DataView> getView(DataQuery path);
420432

433+
/**
434+
* Gets the {@link DataView} by key, if available.
435+
*
436+
* <p>If a {@link DataView} does not exist, or the data residing at
437+
* the path is not an instance of a {@link DataView}, an absent is
438+
* returned.</p>
439+
*
440+
* @param key The key of the value to get
441+
* @return The data view, if available
442+
*/
443+
default Optional<DataView> getView(String key) {
444+
return this.getView(DataQuery.of(key));
445+
}
446+
421447
/**
422448
* Gets the underlying {@link Map} by path, if available.
423449
*

0 commit comments

Comments
 (0)