java.lang.Object
com.ultikits.ultitools.abstracts.gui.declarative.core.SlotKey

public final class SlotKey extends Object
SlotKey uniquely identifies a Widget within the Widget tree.

In lists or dynamic content, SlotKey is essential to the diff algorithm. It lets the framework recognize which Widgets are "the same one" (just with changed data) versus which were added or removed, avoiding unnecessary rebuilds.

When to use it:

  • List items need a stable key to preserve state (e.g. scroll position, selection state)
  • Dynamic content needs a key to trigger the correct animation or transition
  • Reusing an Element improves performance

Best practice:


 // Good: use a stable business identifier as the key
 ListView.builder()
     .children(players.stream()
         .map(p -> PlayerWidget.builder()
             .key(SlotKey.of(p.getUniqueId().toString()))  // stable UUID
             .player(p)
             .build())
         .toList())
     .build();

 // Avoid: using the list index as the key (unless the list is static)
 // This makes the key mismatch the actual content once the data updates
 
Since:
6.2.0
Version:
1.0.0
Author:
UltiTools Team
See Also:
  • Field Details

    • value

      @NotNull private final @NotNull String value
  • Constructor Details

    • SlotKey

      private SlotKey(@NotNull @NotNull String value)
  • Method Details

    • of

      @NotNull public static @NotNull SlotKey of(@NotNull @NotNull String value)
      Creates a SlotKey.
      Parameters:
      value - the key value, must not be empty
      Returns:
      a new SlotKey instance
      Throws:
      IllegalArgumentException - if value is empty
    • of

      @NotNull public static @NotNull SlotKey of(@NotNull @NotNull String prefix, @NotNull @NotNull String value)
      Creates a SlotKey with a prefix.
      Parameters:
      prefix - the prefix
      value - the key value
      Returns:
      a new SlotKey instance
    • getValue

      @NotNull public @NotNull String getValue()
      Gets the key's string value.
      Returns:
      the key value
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object