Package net.minestom.server.data
Interface Data
- All Known Subinterfaces:
SerializableData
- All Known Implementing Classes:
DataImpl
,NbtDataImpl
,SerializableDataImpl
public interface Data
Represents an object which contains key/value based data.
See DataImpl
for the default implementation.
-
Field Summary
-
Method Summary
Modifier and Type Method Description Data
copy()
Copies this data.<T> T
get(java.lang.String key)
Retrieves a value based on its key.java.util.Set<java.lang.String>
getKeys()
Gets the list of data keys.<T> T
getOrDefault(java.lang.String key, T defaultValue)
Retrieves a value based on its key, give a default value if not found.boolean
hasKey(java.lang.String key)
Gets if the data has a key.boolean
isEmpty()
Gets if the data is empty or not.default <T> void
set(java.lang.String key, T value)
Assigns a value to a specific key.<T> void
set(java.lang.String key, T value, java.lang.Class<T> type)
Assigns a value to a specific key.
-
Field Details
-
Method Details
-
set
<T> void set(@NotNull java.lang.String key, @Nullable T value, @Nullable java.lang.Class<T> type)Assigns a value to a specific key.- Type Parameters:
T
- the value generic- Parameters:
key
- the keyvalue
- the value object, null to remove the keytype
- the value type,set(String, Object)
can be used instead. null ifvalue
is also null
-
set
default <T> void set(@NotNull java.lang.String key, @Nullable T value)Assigns a value to a specific key.Will by default call
set(String, Object, Class)
with the type sets toObject.getClass()
.- Type Parameters:
T
- the value generic- Parameters:
key
- the keyvalue
- the value object, null to remove the key
-
get
@Nullable <T> T get(@NotNull java.lang.String key)Retrieves a value based on its key.- Type Parameters:
T
- the value type- Parameters:
key
- the key- Returns:
- the data associated with the key or null
-
getOrDefault
@Nullable <T> T getOrDefault(@NotNull java.lang.String key, @Nullable T defaultValue)Retrieves a value based on its key, give a default value if not found.- Type Parameters:
T
- the value type- Parameters:
key
- the keydefaultValue
- the value to return if the key is not found- Returns:
get(String)
if found,defaultValue
otherwise
-
hasKey
boolean hasKey(@NotNull java.lang.String key)Gets if the data has a key.- Parameters:
key
- the key to check- Returns:
- true if the data contains the key
-
getKeys
@NotNull java.util.Set<java.lang.String> getKeys()Gets the list of data keys.- Returns:
- an unmodifiable
Set
containing all the keys
-
isEmpty
boolean isEmpty()Gets if the data is empty or not.- Returns:
- true if the data does not contain anything, false otherwise
-
copy
Copies this data.- Returns:
- a cloned data object
-