Record Class SlotKey<T>

java.lang.Object
java.lang.Record
io.mindspice.simplypages.core.SlotKey<T>
Type Parameters:
T - slot value type
Record Components:
name - non-null literal slot name
defaultProvider - nullable default function; not evaluated during construction

public record SlotKey<T>(String name, Function<RenderContext, T> defaultProvider) extends Record
Typed identifier for values stored in a RenderContext.

Names must be non-null and are preserved literally, including empty and blank strings. No trimming, case folding, or Unicode normalization is applied.

Equality and hash code use only name(), not the generic type or default provider. Separately created keys with the same name address the same slot; use a consistent type for each name.

Usage boundary: keys are consumed by slot-aware rendering in either direct component renders or compiled Template renders.

Mutability/thread-safety: immutable and thread-safe. Thread-safety of default evaluation depends on the provided defaultProvider() implementation.

  • Constructor Details

    • SlotKey

      public SlotKey(String name, Function<RenderContext, T> defaultProvider)
      Creates a key without evaluating its default provider.
      Parameters:
      name - non-null literal slot name
      defaultProvider - default function, or null for no default
      Throws:
      NullPointerException - if name is null
  • Method Details

    • of

      public static <T> SlotKey<T> of(String name)
      Creates a key with no default provider.
      Parameters:
      name - non-null literal slot name
      Throws:
      NullPointerException - if name is null
    • of

      public static <T> SlotKey<T> of(String name, T defaultValue)
      Creates a key with a constant default value.
      Parameters:
      name - non-null literal slot name
      defaultValue - default used when slot has no explicit entry
      Throws:
      NullPointerException - if name is null
    • of

      public static <T> SlotKey<T> of(String name, Function<RenderContext, T> defaultProvider)
      Creates a key with a computed default.
      Parameters:
      name - non-null literal slot name
      defaultProvider - default function invoked when slot has no explicit entry, or null for no default; not evaluated during construction
      Throws:
      NullPointerException - if name is null
    • getDefault

      public T getDefault(RenderContext context)
      Resolves the default value for this key.
      Parameters:
      context - render context passed to defaultProvider()
      Returns:
      default value, or null when no provider exists
    • equals

      public boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • hashCode

      public int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • name

      public String name()
      Returns the value of the name record component.
      Returns:
      the value of the name record component
    • defaultProvider

      public Function<RenderContext, T> defaultProvider()
      Returns the value of the defaultProvider record component.
      Returns:
      the value of the defaultProvider record component