Class YamlStorageProvider<T>

java.lang.Object
dev.crafty.core.storage.AbstractStorageProvider<T,String>
dev.crafty.core.storage.providers.YamlStorageProvider<T>
Type Parameters:
T - The type of object to store
All Implemented Interfaces:
StorageProvider<T,String>

public class YamlStorageProvider<T> extends AbstractStorageProvider<T,String>
A storage provider that stores objects in YAML files.
Since:
1.0.0
  • Constructor Details

    • YamlStorageProvider

      public YamlStorageProvider(Class<T> valueType, Path directory)
      Creates a new YamlStorageProvider.
      Parameters:
      valueType - The class of the value type
      directory - The directory to store files in
    • YamlStorageProvider

      public YamlStorageProvider(Class<T> valueType, Path directory, String fileExtension)
      Creates a new YamlStorageProvider with a custom file extension.
      Parameters:
      valueType - The class of the value type
      directory - The directory to store files in
      fileExtension - The file extension to use (including the dot)
  • Method Details

    • initialize

      public CompletableFuture<Void> initialize()
      Initializes the storage provider. This method should be called before using the provider.
      Specified by:
      initialize in interface StorageProvider<T,String>
      Overrides:
      initialize in class AbstractStorageProvider<T,String>
      Returns:
      A CompletableFuture that completes when initialization is done
    • save

      public CompletableFuture<Void> save(String key, T value)
      Saves an object to the storage.
      Parameters:
      key - The key to identify the object
      value - The object to save
      Returns:
      A CompletableFuture that completes when the operation is done
    • get

      public CompletableFuture<Optional<T>> get(String key)
      Retrieves an object from the storage.
      Parameters:
      key - The key of the object to retrieve
      Returns:
      A CompletableFuture that completes with the retrieved object, or empty if not found
    • getAll

      public CompletableFuture<Collection<T>> getAll()
      Retrieves all objects from the storage.
      Returns:
      A CompletableFuture that completes with a collection of all objects
    • delete

      public CompletableFuture<Void> delete(String key)
      Deletes an object from the storage.
      Parameters:
      key - The key of the object to delete
      Returns:
      A CompletableFuture that completes when the operation is done