Class 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
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected Data​(@NotNull AnnoyingPlugin plugin, T target)
      Construct a new Data for the given target
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      abstract @Nullable java.lang.String get​(@NotNull java.lang.String key)
      Get the data value for the given key
      @NotNull java.lang.String get​(@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 AnnoyingPlugin getAnnoyingPlugin()
      The AnnoyingPlugin instance
      @NotNull java.util.Optional<java.lang.String> getOptional​(@NotNull java.lang.String key)
      Get the data value for the given key as an Optional
      boolean has​(@NotNull java.lang.String key)
      Check if the data value exists for the given key
      abstract boolean remove​(@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 key
      protected void sendError​(@NotNull java.lang.String action, @Nullable java.lang.Throwable t)
      Send an error message to the console
      protected abstract boolean set​(@NotNull java.lang.String key, @NotNull java.lang.String value)
      Set the data value for the given key.
      boolean set​(@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.
      • Methods inherited from class xyz.srnyx.javautilities.parents.Stringable

        toString, toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • 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 new Data for the given target
        Parameters:
        plugin - plugin
        target - target
    • Method Detail

      • 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:
        true if the data value exists, false otherwise
      • 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 for
        def - 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 an Optional
        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 for
        value - the data value to set
        Returns:
        true if the data value was set successfully, false otherwise
      • 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 for
        value - the data value to set, or null to remove the data value
        Returns:
        true if the data value was set successfully, false otherwise
      • 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 for
        value - the data value to set, or null to remove the data value
        Returns:
        this Data instance 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:
        true if the data value was removed successfully, false otherwise
      • 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 Data instance 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 failed
        t - the Throwable that caused the error