Package starfederation.datastar.utils
Class DataStore
java.lang.Object
starfederation.datastar.utils.DataStore
A simple data store for managing key-value pairs with serialization/deserialization support.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidDeserializes the given JSON string into the store.<T> TRetrieves the value associated with the given key, cast to the specified type.getStore()Gets the underlying ConcurrentMap store.voidAdds a key-value pair to the store.voidAdds all entries from the given map to the store.toJson()Serializes the store to a JSON string.toString()
-
Constructor Details
-
DataStore
public DataStore()
-
-
Method Details
-
put
Adds a key-value pair to the store.- Parameters:
key- The key (must be non-null and non-blank).value- The value (can be null).
-
get
Retrieves the value associated with the given key, cast to the specified type.- Parameters:
key- The key.clazz- The expected type of the value.- Returns:
- The value associated with the key, or null if not found.
- Throws:
IllegalArgumentException- if the value is not of the expected type.
-
putAll
Adds all entries from the given map to the store.- Parameters:
data- The map of key-value pairs.
-
getStore
Gets the underlying ConcurrentMap store. Note: This provides direct access to the internal store. Use with caution as it bypasses type checking.- Returns:
- The underlying ConcurrentMap store.
-
toJson
Serializes the store to a JSON string.- Returns:
- The JSON representation of the store.
-
fromJson
Deserializes the given JSON string into the store.- Parameters:
json- The JSON string.- Throws:
IllegalArgumentException- if the JSON is invalid.
-
toString
-