Package me.a8kj.util
Class MapStructureUtils
java.lang.Object
me.a8kj.util.MapStructureUtils
Utility class for transforming between hierarchical and flat map structures.
Provides methods to flatten nested Map structures into dot-notated
key/value pairs compatible with DataMemory and to reconstruct
nested maps from such flat representations.
Useful for YAML/JSON processing and in-memory configuration management.
This is a utility class and cannot be instantiated.
- Since:
- 0.3
- Author:
- a8kj7sea
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidFlattens a nestedMapinto a flat structure using dot-separated keys.Reconstructs a nestedMapfrom a flat map with dot-separated keys.unflattenUnderPath(String path, DataMemory<String> memory) Extracts a nested map from a DataMemory under a specific path.
-
Constructor Details
-
MapStructureUtils
public MapStructureUtils()
-
-
Method Details
-
flatten
Flattens a nestedMapinto a flat structure using dot-separated keys.Nested maps are recursively processed, and non-map values are stored in the provided
DataMemoryinstance.- Parameters:
prefix- the current key prefix (use empty string for top-level)source- the nested map to flattenmemory- the targetDataMemoryto store flattened entries
-
unflatten
Reconstructs a nestedMapfrom a flat map with dot-separated keys.Each key in the flat map is split by dots to create hierarchical nesting of maps. Original values are preserved at leaf nodes.
- Parameters:
flatMap- the flat map containing dot-notated keys- Returns:
- a nested
Maprepresenting the original hierarchy
-
unflattenUnderPath
Extracts a nested map from a DataMemory under a specific path.- Parameters:
path- the root path to extractmemory- the DataMemory instance- Returns:
- a nested map of values under the path
-