Package me.a8kj.config.template.memory
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 TypeMethodDescriptionvoidclear()Clears all data currently held in memory.booleanChecks if the memory contains a specific key.Retrieves a raw object from memory by its key.default ObjectRetrieves an object from memory, returning a default value if the key is missing.booleangetBoolean(K key, boolean defaultValue) Retrieves a value as a boolean.doubleRetrieves a value as a double.intRetrieves a value as an integer.Retrieves a set of keys under a specific path.getOptional(K key) Wraps the retrieval of a key in anOptional.Provides theReplacementProcessorassociated with this memory instance.Retrieves a value as aString.default StringgetString(K key, String defaultValue, Replacement... replacements) Retrieves a string and applies dynamic replacements to it.getStringList(K key) Retrieves a list of strings from the specified key.getStringList(K key, Replacement... replacements) Retrieves a string list and applies dynamic replacements to each entry.voidSets a value in the memory buffer for the specified key.default Stringtransform(String text, Replacement... replacements) Transforms a given text by applying the provided replacements using the internal processor.
-
Method Details
-
set
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
Retrieves a raw object from memory by its key.- Parameters:
key- the key to lookup.- Returns:
- the stored object, or
nullif not found.
-
get
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
Retrieves a value as aString.- Parameters:
key- the key to lookup.- Returns:
- the string representation of the value.
-
getString
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 ofReplacementto apply to the string.- Returns:
- the transformed string or the default value.
-
getInt
Retrieves a value as an integer. -
getBoolean
Retrieves a value as a boolean. -
getDouble
Retrieves a value as a double. -
getStringList
Retrieves a list of strings from the specified key. -
contains
Checks if the memory contains a specific key. -
getKeys
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
Wraps the retrieval of a key in anOptional.- Parameters:
key- the key to lookup.- Returns:
- an Optional containing the value if present.
-
getStringList
Retrieves a string list and applies dynamic replacements to each entry.- Parameters:
key- the key to lookup.replacements- a varargs ofReplacementto apply.- Returns:
- a processed list of strings.
-
getProcessor
ReplacementProcessor getProcessor()Provides theReplacementProcessorassociated 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
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.
-