Class DataStore

java.lang.Object
starfederation.datastar.utils.DataStore

public class DataStore extends Object
A simple data store for managing key-value pairs with serialization/deserialization support.
  • Constructor Details

    • DataStore

      public DataStore()
  • Method Details

    • put

      public void put(String key, Object value)
      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

      public <T> T get(String key, Class<T> clazz)
      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

      public void putAll(Map<String,Object> data)
      Adds all entries from the given map to the store.
      Parameters:
      data - The map of key-value pairs.
    • getStore

      public ConcurrentMap<String,Object> 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

      public String toJson()
      Serializes the store to a JSON string.
      Returns:
      The JSON representation of the store.
    • fromJson

      public void fromJson(String json)
      Deserializes the given JSON string into the store.
      Parameters:
      json - The JSON string.
      Throws:
      IllegalArgumentException - if the JSON is invalid.
    • toString

      public String toString()
      Overrides:
      toString in class Object