Class ScreenContextManager.ScreenContextHolder
- Enclosing class:
ScreenContextManager
ScreenContext objects, each identified by a unique screen ID.
This class provides thread-safe operations for creating, retrieving, and managing screen-specific contexts within the application.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a newScreenContextHolderfor managing multipleScreenContextobjects. -
Method Summary
Modifier and TypeMethodDescriptionvoidRemoves all screen contexts stored in thisScreenContextHolder.voidclearContext(String screenId) Removes theScreenContextassociated with the provided screen ID from the internal storage.getOrCreateContext(String screenId) Retrieves an existingScreenContextfor the given screen ID or creates a new one if it does not already exist.
-
Constructor Details
-
ScreenContextHolder
public ScreenContextHolder()Creates a newScreenContextHolderfor managing multipleScreenContextobjects.Initializes an internal thread-safe
ConcurrentHashMapto store screen contexts, with each context mapped to a unique screen ID.
-
-
Method Details
-
getOrCreateContext
Retrieves an existingScreenContextfor the given screen ID or creates a new one if it does not already exist.This method ensures that each screen ID is associated with a unique
ScreenContext. If the context for the provided screen ID is not already stored, it will initialize and map a new instance ofScreenContextto the given ID.- Parameters:
screenId- The unique identifier for the screen. Must not be null or empty. Used to retrieve or initialize the correspondingScreenContext.- Returns:
- The
ScreenContextobject associated with the given screen ID. If the context does not already exist, a new one is created and returned.
-
clearContext
Removes theScreenContextassociated with the provided screen ID from the internal storage.After this operation, the screen ID will no longer be mapped to a
ScreenContext. If no context exists for the specified screen ID, the method will have no effect.- Parameters:
screenId- The unique identifier for the screen. Must not be null or empty. Used to locate and remove the associatedScreenContext.- Throws:
NullPointerException- IfscreenIdis null.
-
clearAllContexts
public void clearAllContexts()Removes all screen contexts stored in thisScreenContextHolder.This method clears the internal storage of all
ScreenContextobjects, effectively resetting the state of theScreenContextHolder. Any further access to previously stored contexts will result in their recreation usinggetOrCreateContext(String).
-