Package me.a8kj.util

Class MapStructureUtils

java.lang.Object
me.a8kj.util.MapStructureUtils

public final class MapStructureUtils extends Object
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 Details

    • MapStructureUtils

      public MapStructureUtils()
  • Method Details

    • flatten

      public static void flatten(String prefix, Map<String,Object> source, DataMemory<String> memory)
      Flattens a nested Map into a flat structure using dot-separated keys.

      Nested maps are recursively processed, and non-map values are stored in the provided DataMemory instance.

      Parameters:
      prefix - the current key prefix (use empty string for top-level)
      source - the nested map to flatten
      memory - the target DataMemory to store flattened entries
    • unflatten

      public static Map<String,Object> unflatten(Map<String,Object> flatMap)
      Reconstructs a nested Map from 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 Map representing the original hierarchy
    • unflattenUnderPath

      public static Map<String,Object> unflattenUnderPath(String path, DataMemory<String> memory)
      Extracts a nested map from a DataMemory under a specific path.
      Parameters:
      path - the root path to extract
      memory - the DataMemory instance
      Returns:
      a nested map of values under the path