java.lang.Object
no.ntnu.principes.controller.screen.ScreenContext
Manages a context for a specific screen by storing and retrieving parameters
tied to a unique screen identifier.
-
Constructor Summary
ConstructorsConstructorDescriptionScreenContext(String screenId) Initializes a new screen context identified by a unique screen ID and prepares storage for parameters associated with the screen. -
Method Summary
Modifier and TypeMethodDescriptionvoidRemoves all parameters stored in the current screen context.<T> TgetParameter(String key) Retrieves the value associated with the specified key from the parameter map, cast to the expected type.Returns an unmodifiable view of the parameters map.getParameters(String... keys) Retrieves a filtered map of parameters based on the specified keys.voidsetParameter(String key, Object value) Adds or updates a parameter in the context associated with the screen.toString()
-
Constructor Details
-
ScreenContext
Initializes a new screen context identified by a unique screen ID and prepares storage for parameters associated with the screen.- Parameters:
screenId- The unique identifier for the screen. Must not be null or empty. This ID is used to differentiate between contexts for different screens.
-
-
Method Details
-
setParameter
Adds or updates a parameter in the context associated with the screen.- Parameters:
key- A non-null string that identifies the parameter. Must not be empty.value- The value to associate with the key. Can be any object, including null, which will overwrite any existing value for the key.
-
getParameter
Retrieves the value associated with the specified key from the parameter map, cast to the expected type.- Type Parameters:
T- The expected type of the value.- Parameters:
key- The key to look up in the parameter map. Must not be null. If the key does not exist, this method returns null.- Returns:
- The value associated with the key, cast to the expected type, or null if the key is not present in the map.
- Throws:
ClassCastException- If the value associated with the key cannot be cast to the specified type.
-
clearParameters
public void clearParameters()Removes all parameters stored in the current screen context. -
getParameters
Returns an unmodifiable view of the parameters map.- Returns:
- a
Map<String, Object>containing the current parameters; modifications to the returned map are not allowed.
-
getParameters
Retrieves a filtered map of parameters based on the specified keys. Only includes entries where the key exists in the `parameters` map.- Parameters:
keys- The keys to filter and retrieve from the parameters map. Non-existent keys are skipped.- Returns:
- A map containing key-value pairs for all valid keys found in the `parameters` map. If no keys match, returns an empty map.
-
toString
-