-
-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Improves the meta data API for Island * Unified API into MetaDataAble Interface All classes now use the same interface and Optionals. Reduces code duplication and makes the API the same across the board. * Version 1.15.6 Fixed since JavaDocs
- Loading branch information
1 parent
c465fd1
commit 4f0ef8f
Showing
6 changed files
with
65 additions
and
136 deletions.
There are no files selected for viewing
43 changes: 25 additions & 18 deletions
43
src/main/java/world/bentobox/bentobox/api/metadata/MetaDataAble.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,55 @@ | ||
package world.bentobox.bentobox.api.metadata; | ||
|
||
import java.util.Map; | ||
|
||
import org.eclipse.jdt.annotation.NonNull; | ||
import java.util.Optional; | ||
|
||
/** | ||
* This interface is for all BentoBox objects that have meta data | ||
* @author tastybento | ||
* @since 1.15.4 | ||
* @since 1.15.6 | ||
*/ | ||
public interface MetaDataAble { | ||
|
||
/** | ||
* @return the metaData | ||
*/ | ||
public Map<String, MetaDataValue> getMetaData(); | ||
public Optional<Map<String, MetaDataValue>> getMetaData(); | ||
|
||
/** | ||
* Get meta data by key | ||
* @param key - key | ||
* @return the value to which the specified key is mapped, or null if there is no mapping for the key | ||
* @param metaData the metaData to set | ||
* @since 1.15.4 | ||
*/ | ||
public MetaDataValue getMetaData(@NonNull String key); | ||
public void setMetaData(Map<String, MetaDataValue> metaData); | ||
|
||
/** | ||
* @param metaData the metaData to set | ||
* @since 1.15.4 | ||
* Get meta data by key | ||
* @param key - key | ||
* @return the value to which the specified key is mapped, or null if there is no mapping for the key | ||
* @since 1.15.6 | ||
*/ | ||
public void setMetaData(Map<String, MetaDataValue> metaData); | ||
default Optional<MetaDataValue> getMetaData(String key) { | ||
return getMetaData().map(m -> m.get(key)); | ||
} | ||
|
||
/** | ||
* Put a key, value string pair into the object's meta data | ||
* Put a key, value string pair into the meta data | ||
* @param key - key | ||
* @param value - value | ||
* @return the previous value associated with key, or null if there was no mapping for key. | ||
* @since 1.15.4 | ||
* @return the previous value associated with key, or empty if there was no mapping for key. | ||
* @since 1.15.6 | ||
*/ | ||
public MetaDataValue putMetaData(@NonNull String key, @NonNull MetaDataValue value); | ||
default Optional<MetaDataValue> putMetaData(String key, MetaDataValue value) { | ||
return getMetaData().map(m -> m.put(key, value)); | ||
} | ||
|
||
/** | ||
* Remove meta data | ||
* @param key - key to remove | ||
* @return the previous value associated with key, or null if there was no mapping for key. | ||
* @since 1.15.4 | ||
* @return the previous value associated with key, or empty if there was no mapping for key. | ||
* @since 1.15.6 | ||
*/ | ||
public MetaDataValue removeMetaData(@NonNull String key); | ||
default Optional<MetaDataValue> removeMetaData(String key) { | ||
return getMetaData().map(m -> m.remove(key)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1650,4 +1650,5 @@ public CompletableFuture<Boolean> checkTeams(User user, World world) { | |
|
||
return r; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters