Package xyz.srnyx.annoyingapi.data
Class Data<T>
- java.lang.Object
-
- xyz.srnyx.javautilities.parents.Stringable
-
- xyz.srnyx.annoyingapi.data.Data<T>
-
- Type Parameters:
T- the type of target to manage data for
- All Implemented Interfaces:
Annoyable
- Direct Known Subclasses:
ItemData,StringData
public abstract class Data<T> extends xyz.srnyx.javautilities.parents.Stringable implements Annoyable
Represents a class that can be used to manage data
-
-
Field Summary
Fields Modifier and Type Field Description protected @NotNull AnnoyingPluginpluginTheplugininstanceTtargetThe target to manage data for
-
Constructor Summary
Constructors Modifier Constructor Description protectedData(@NotNull AnnoyingPlugin plugin, T target)Construct a newDatafor the given target
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract @Nullable java.lang.Stringget(@NotNull java.lang.String key)Get the data value for the given key@NotNull java.lang.Stringget(@NotNull java.lang.String key, @NotNull java.lang.String def)Get the data value for the given key, or the default value if not found@NotNull AnnoyingPlugingetAnnoyingPlugin()TheAnnoyingPlugininstance@NotNull java.util.Optional<java.lang.String>getOptional(@NotNull java.lang.String key)Get the data value for the given key as anOptionalbooleanhas(@NotNull java.lang.String key)Check if the data value exists for the given keyabstract booleanremove(@NotNull java.lang.String key)Remove the data value with the given key@NotNull Data<T>removeChain(@NotNull java.lang.String key)Remove the data value with the given keyprotected voidsendError(@NotNull java.lang.String action, @Nullable java.lang.Throwable t)Send an error message to the consoleprotected abstract booleanset(@NotNull java.lang.String key, @NotNull java.lang.String value)Set the data value for the given key.booleanset(@NotNull java.lang.String key, @Nullable java.lang.Object value)Set the data value for the given key.@NotNull Data<T>setChain(@NotNull java.lang.String key, @Nullable java.lang.Object value)Set the data value for the given key.
-
-
-
Field Detail
-
plugin
@NotNull protected final @NotNull AnnoyingPlugin plugin
Theplugininstance
-
target
@NotNull public final T target
The target to manage data for
-
-
Constructor Detail
-
Data
protected Data(@NotNull @NotNull AnnoyingPlugin plugin, @NotNull T target)Construct a newDatafor the given target
-
-
Method Detail
-
getAnnoyingPlugin
@NotNull public @NotNull AnnoyingPlugin getAnnoyingPlugin()
Description copied from interface:AnnoyableTheAnnoyingPlugininstance- Specified by:
getAnnoyingPluginin interfaceAnnoyable- Returns:
- the plugin instance
-
has
public boolean has(@NotNull @NotNull java.lang.String key)Check if the data value exists for the given key- Parameters:
key- the key to check for- Returns:
trueif the data value exists,falseotherwise
-
get
@Nullable public abstract @Nullable java.lang.String get(@NotNull @NotNull java.lang.String key)Get the data value for the given key- Parameters:
key- the key to get the data value for- Returns:
- the data value, or null if not found
-
get
@NotNull public @NotNull java.lang.String get(@NotNull @NotNull java.lang.String key, @NotNull @NotNull java.lang.String def)Get the data value for the given key, or the default value if not found- Parameters:
key- the key to get the data value fordef- the default value to return if the data value is not found- Returns:
- the data value, or the default value if not found
-
getOptional
@NotNull public @NotNull java.util.Optional<java.lang.String> getOptional(@NotNull @NotNull java.lang.String key)Get the data value for the given key as anOptional- Parameters:
key- the key to get the data value for- Returns:
- the data value as an
Optional
-
set
protected abstract boolean set(@NotNull @NotNull java.lang.String key, @NotNull @NotNull java.lang.String value)Set the data value for the given key. If the key already exists, it will be overwritten- Parameters:
key- the key to set the data value forvalue- the data value to set- Returns:
trueif the data value was set successfully,falseotherwise
-
set
public boolean set(@NotNull @NotNull java.lang.String key, @Nullable @Nullable java.lang.Object value)Set the data value for the given key. If the key already exists, it will be overwritten- Parameters:
key- the key to set the data value forvalue- the data value to set, or null to remove the data value- Returns:
trueif the data value was set successfully,falseotherwise
-
setChain
@NotNull public @NotNull Data<T> setChain(@NotNull @NotNull java.lang.String key, @Nullable @Nullable java.lang.Object value)
Set the data value for the given key. If the key already exists, it will be overwritten- Parameters:
key- the key to set the data value forvalue- the data value to set, or null to remove the data value- Returns:
- this
Datainstance for chaining
-
remove
public abstract boolean remove(@NotNull @NotNull java.lang.String key)Remove the data value with the given key- Parameters:
key- the key to remove the data value for- Returns:
trueif the data value was removed successfully,falseotherwise
-
removeChain
@NotNull public @NotNull Data<T> removeChain(@NotNull @NotNull java.lang.String key)
Remove the data value with the given key- Parameters:
key- the key to remove the data value for- Returns:
- this
Datainstance for chaining
-
sendError
protected void sendError(@NotNull @NotNull java.lang.String action, @Nullable @Nullable java.lang.Throwable t)Send an error message to the console- Parameters:
action- the action that failedt- theThrowablethat caused the error
-
-