Interface DataMemory<K>

Type Parameters:
K - the type of data keys used (e.g., String for YAML/JSON paths).
All Known Subinterfaces:
EntityAwareMemory, PairedDataMemory<K>
All Known Implementing Classes:
EntityDataMemory, EnumDataMemory, GenericMapDataMemory, MapDataMemory, MapPairedDataMemory, StringMapPairedDataMemory, VelocityDataMemory

public interface DataMemory<K>
Represents the in-memory storage and retrieval system for configuration data.

This interface provides a type-safe way to access configuration values and supports dynamic text transformation through replacements via a dedicated processor.

Since:
0.1
Author:
a8kj7sea
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clears all data currently held in memory.
    boolean
    contains(K key)
    Checks if the memory contains a specific key.
    get(K key)
    Retrieves a raw object from memory by its key.
    default Object
    get(K key, Object defaultValue)
    Retrieves an object from memory, returning a default value if the key is missing.
    boolean
    getBoolean(K key, boolean defaultValue)
    Retrieves a value as a boolean.
    double
    getDouble(K key, double defaultValue)
    Retrieves a value as a double.
    int
    getInt(K key, int defaultValue)
    Retrieves a value as an integer.
    getKeys(K path, boolean deep)
    Retrieves a set of keys under a specific path.
    default Optional<Object>
    Wraps the retrieval of a key in an Optional.
    Provides the ReplacementProcessor associated with this memory instance.
    getString(K key)
    Retrieves a value as a String.
    default String
    getString(K key, String defaultValue, Replacement... replacements)
    Retrieves a string and applies dynamic replacements to it.
    Retrieves a list of strings from the specified key.
    default List<String>
    getStringList(K key, Replacement... replacements)
    Retrieves a string list and applies dynamic replacements to each entry.
    void
    set(K key, Object value)
    Sets a value in the memory buffer for the specified key.
    default String
    transform(String text, Replacement... replacements)
    Transforms a given text by applying the provided replacements using the internal processor.
  • Method Details

    • set

      void set(K key, Object value)
      Sets a value in the memory buffer for the specified key.
      Parameters:
      key - the key where the value should be stored.
      value - the object to store.
    • get

      Object get(K key)
      Retrieves a raw object from memory by its key.
      Parameters:
      key - the key to lookup.
      Returns:
      the stored object, or null if not found.
    • get

      default Object get(K key, Object defaultValue)
      Retrieves an object from memory, returning a default value if the key is missing.
      Parameters:
      key - the key to lookup.
      defaultValue - the value to return if the key does not exist.
      Returns:
      the found value or the default.
    • getString

      String getString(K key)
      Retrieves a value as a String.
      Parameters:
      key - the key to lookup.
      Returns:
      the string representation of the value.
    • getString

      default String getString(K key, String defaultValue, Replacement... replacements)
      Retrieves a string and applies dynamic replacements to it.
      Parameters:
      key - the key to lookup.
      defaultValue - the value to return if not found.
      replacements - a varargs of Replacement to apply to the string.
      Returns:
      the transformed string or the default value.
    • getInt

      int getInt(K key, int defaultValue)
      Retrieves a value as an integer.
    • getBoolean

      boolean getBoolean(K key, boolean defaultValue)
      Retrieves a value as a boolean.
    • getDouble

      double getDouble(K key, double defaultValue)
      Retrieves a value as a double.
    • getStringList

      List<String> getStringList(K key)
      Retrieves a list of strings from the specified key.
    • contains

      boolean contains(K key)
      Checks if the memory contains a specific key.
    • getKeys

      Set<K> getKeys(K path, boolean deep)
      Retrieves a set of keys under a specific path.
      Parameters:
      path - the parent path.
      deep - whether to include keys from nested sections.
      Returns:
      a set of keys.
    • clear

      void clear()
      Clears all data currently held in memory.
    • getOptional

      default Optional<Object> getOptional(K key)
      Wraps the retrieval of a key in an Optional.
      Parameters:
      key - the key to lookup.
      Returns:
      an Optional containing the value if present.
    • getStringList

      default List<String> getStringList(K key, Replacement... replacements)
      Retrieves a string list and applies dynamic replacements to each entry.
      Parameters:
      key - the key to lookup.
      replacements - a varargs of Replacement to apply.
      Returns:
      a processed list of strings.
    • getProcessor

      ReplacementProcessor getProcessor()
      Provides the ReplacementProcessor associated with this memory instance.

      Every implementation must provide its own processor to define how placeholders are identified and replaced.

      Returns:
      the replacement processor instance.
    • transform

      default String transform(String text, Replacement... replacements)
      Transforms a given text by applying the provided replacements using the internal processor.

      This is a default implementation that delegates work to getProcessor().

      Parameters:
      text - the original text containing placeholders.
      replacements - the replacements to apply.
      Returns:
      the processed text.