Class MemoryEntry<T>

java.lang.Object
me.a8kj.config.template.memory.MemoryEntry<T>
Type Parameters:
T - the expected type of the value held by this entry.

public class MemoryEntry<T> extends Object
Represents a predefined entry in the configuration memory. This class encapsulates both the access key and the expected data type, providing a type-safe way to fetch values without manual casting or repeated key strings.
Since:
0.1
Author:
a8kj7sea
  • Method Details

    • of

      public static <T> MemoryEntry<T> of(String key, MemoryDataType type)
      Creates a new MemoryEntry instance.
      Type Parameters:
      T - the expected return type.
      Parameters:
      key - the configuration path/key.
      type - the MemoryDataType representing the data's nature.
      Returns:
      a new MemoryEntry instance.
      Since:
      0.1
    • fetch

      public T fetch(DataMemory<String> memory)
      Fetches the value associated with this entry from the provided memory source.
      Parameters:
      memory - the DataMemory instance to pull data from.
      Returns:
      the value of type T stored at the designated key.
      Since:
      0.1
    • fetchOrDefault

      public T fetchOrDefault(DataMemory<String> memory, T defaultValue)
      Fetches the value associated with this entry from the provided memory source. If the value is null, the provided default value will be returned instead.
      Parameters:
      memory - the DataMemory instance to pull data from.
      defaultValue - the fallback value to return if no value is found.
      Returns:
      the stored value or the default value if absent.
      Since:
      0.3
    • key

      public String key()
      Returns the configuration key associated with this entry.
      Returns:
      the configuration path/key.
      Since:
      0.3
    • type

      public MemoryDataType type()
      Returns the MemoryDataType of this entry.
      Returns:
      the memory data type strategy.
      Since:
      0.3