Class SlotKeyMap

java.lang.Object
io.mindspice.simplypages.core.SlotKeyMap

public class SlotKeyMap extends Object
Mutable string-keyed slot value map used mainly as a legacy bridge API.

This map stores values as TypedValue to preserve runtime type metadata. For modern rendering, prefer RenderContext and SlotKey directly.

Mutability/thread-safety: mutable and not thread-safe. Treat as request-scoped data. For reuse, stop mutating shared instances and render stable structures with per-request context data.

  • Method Details

    • create

      public static SlotKeyMap create()
      Factory for an empty slot map.
    • putString

      public SlotKeyMap putString(String slotName, String value)
      Stores a string value for slotName.
    • putBoolean

      public SlotKeyMap putBoolean(String slotName, Boolean value)
      Stores a boolean value for slotName.
    • putInt

      public SlotKeyMap putInt(String slotName, Integer value)
      Stores an integer value for slotName.
    • put

      public SlotKeyMap put(String slotName, Class<?> type, Object value)
      Stores value with an explicit runtime type token.
      Parameters:
      slotName - slot name
      type - expected runtime type of value
      value - value to store; may be null
      Returns:
      this map
    • get

      public Optional<TypedValue> get(String slotName)
      Returns the typed value wrapper for slotName, when present.
    • getValue

      public <T> Optional<T> getValue(String slotName, Class<T> expectedType)
      Returns the value for slotName cast as expectedType.
    • getOrDefault

      public <T> T getOrDefault(String slotName, T defaultValue)
      Returns the stored value, or defaultValue when absent.
    • withDefaults

      public SlotKeyMap withDefaults(SlotKeyMap defaults)
      Returns a merged copy where this map overrides defaults for duplicate keys.
    • fromMap

      public static SlotKeyMap fromMap(Map<String,?> plainMap)
      Converts a plain object map into a typed slot map.

      Entries with null values are skipped.

    • fromRenderContext

      public static SlotKeyMap fromRenderContext(RenderContext context)
      Legacy bridge: convert explicit entries from a render context into a string-key map. Slot names are derived from SlotKey.name().
    • toRenderContext

      public RenderContext toRenderContext(Map<String, SlotKey<?>> slotMapping)
      Legacy bridge: convert this string-key map to a render context using the provided slot key mapping. Entries with no matching key are ignored.
    • toPlainMap

      public Map<String,Object> toPlainMap()
      Returns a mutable plain object copy of this map's values.
    • getValues

      public Map<String, TypedValue> getValues()
      Returns an unmodifiable snapshot of internal typed values.
    • isEmpty

      public boolean isEmpty()
      Returns whether the map has no entries.
    • size

      public int size()
      Returns the number of stored entries.