Class MacroStringMap
java.lang.Object
com.winterhavenmc.library.messagebuilder.core.maps.MacroStringMap
A specialized map for storing string macro values keyed by
ValidMacroKey.
This map is used during the macro resolution phase of the message pipeline to provide string substitution values for placeholders.
All insertions are validated: null and blank strings are considered invalid, and will trigger a validation warning (but are still inserted).
This class is mutable and not thread-safe. It is expected to be used in a single-threaded message construction context.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancontainsKey(ValidMacroKey key) Returnstrueif this map contains the specified string.static MacroStringMapempty()Returns a new, emptyMacroStringMap.Iterable<? extends Map.Entry<ValidMacroKey, String>> entrySet()Returns the set of string-value entries in this map.get(ValidMacroKey macroKey) Returns the value associated with the given string, ornullif not found.booleanisEmpty()Returnstrueif this map is empty.keySet()Returns the set of keys contained in this map.voidput(ValidMacroKey macroKey, String value) Inserts a string-value pair into the map.voidputAll(MacroStringMap insertionMap) Inserts all entries from anotherMacroStringMapinto this map.voidputIfAbsent(ValidMacroKey macroKey, String value) Inserts a string-value pair into the map only if the string is not already present.intsize()Returns the number of entries in this map.with(ValidMacroKey key, String value) Adds a string-value pair to this map and returns the map itself.
-
Constructor Details
-
MacroStringMap
public MacroStringMap()Constructs an emptyMacroStringMap.
-
-
Method Details
-
put
Inserts a string-value pair into the map. If the value isnullor blank, a validation warning is logged.- Parameters:
macroKey- the macro stringvalue- the string value to associate
-
putIfAbsent
Inserts a string-value pair into the map only if the string is not already present. If the value isnullor blank, a validation warning is logged.- Parameters:
macroKey- the macro stringvalue- the string value to associate
-
get
Returns the value associated with the given string, ornullif not found.- Parameters:
macroKey- the macro string- Returns:
- the associated value, or
nullif not present
-
putAll
Inserts all entries from anotherMacroStringMapinto this map. Existing keys will be overwritten.- Parameters:
insertionMap- the map whose entries should be copied
-
containsKey
Returnstrueif this map contains the specified string.- Parameters:
key- the string to check- Returns:
trueif the string is present
-
entrySet
Returns the set of string-value entries in this map.- Returns:
- an iterable view of the map's entries
-
keySet
Returns the set of keys contained in this map.- Returns:
- a set of macro keys
-
isEmpty
public boolean isEmpty()Returnstrueif this map is empty.- Returns:
trueif there are no entries
-
size
public int size()Returns the number of entries in this map.- Returns:
- the map size
-
empty
Returns a new, emptyMacroStringMap.- Returns:
- an empty instance
-
with
Adds a string-value pair to this map and returns the map itself. This method is useful for fluent building patterns.- Parameters:
key- the macro stringvalue- the string value to associate- Returns:
- this map, with the new entry included
-