Class ScreenContextManager

java.lang.Object
no.ntnu.principes.controller.screen.ScreenContextManager

public class ScreenContextManager extends Object
Manages the creation, retrieval, and lifecycle of screen contexts associated with unique controllers. Provides an interface to manage contexts for screens by controller identifiers.
  • Method Details

    • getHolder

      public static ScreenContextManager.ScreenContextHolder getHolder(UUID controllerId)
      Retrieves the ScreenContextManager.ScreenContextHolder associated with the specified controller ID. If no holder exists for the given ID, a new one is created and returned.
      Parameters:
      controllerId - The UUID representing the unique identifier for a screen controller. Must not be null.
      Returns:
      The ScreenContextManager.ScreenContextHolder associated with the given controller ID. A new instance is created if none exists.
    • getInstance

      public static ScreenContextManager getInstance()
      Retrieves the singleton instance of ScreenContextManager, ensuring that only one instance of the manager exists throughout the application lifecycle.
      Returns:
      The single ScreenContextManager instance, responsible for managing screen contexts associated with unique controllers.
    • getOrCreateHolder

      public ScreenContextManager.ScreenContextHolder getOrCreateHolder(UUID controllerId)
      Retrieves the ScreenContextManager.ScreenContextHolder associated with the specified controller ID. If no holder exists for the given controller ID, a new ScreenContextManager.ScreenContextHolder is created, stored, and returned.
      Parameters:
      controllerId - The unique UUID for the screen controller. Cannot be null. Used as a key to identify and store the corresponding holder.
      Returns:
      The ScreenContextManager.ScreenContextHolder associated with the given controller ID. A new instance is created and stored if no holder exists for the ID.
      Throws:
      NullPointerException - If controllerId is null.
    • clearContext

      public void clearContext(UUID controllerId)
      Removes the screen context associated with the given controller ID from the internal storage. This operation effectively frees any resources held by the corresponding ScreenContextHolder. If no context exists for the specified controller ID, the method does nothing.
      Parameters:
      controllerId - The unique UUID identifier for the screen controller to clear. Must not be null.
      Throws:
      NullPointerException - If controllerId is null.
    • clearAllContexts

      public void clearAllContexts()
      Clears all stored screen context holders managed by this instance.

      This method removes all entries in the internal map used to store ScreenContextHolder instances.