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>
A storage provider that stores objects in YAML files.
- Since:
- 1.0.0
-
Field Summary
Fields inherited from class dev.crafty.core.storage.AbstractStorageProvider
valueType
-
Constructor Summary
ConstructorsConstructorDescriptionYamlStorageProvider
(Class<T> valueType, Path directory) Creates a new YamlStorageProvider.YamlStorageProvider
(Class<T> valueType, Path directory, String fileExtension) Creates a new YamlStorageProvider with a custom file extension. -
Method Summary
Modifier and TypeMethodDescriptionDeletes an object from the storage.Retrieves an object from the storage.getAll()
Retrieves all objects from the storage.Initializes the storage provider.Saves an object to the storage.Methods inherited from class dev.crafty.core.storage.AbstractStorageProvider
close, exists
-
Constructor Details
-
YamlStorageProvider
Creates a new YamlStorageProvider.- Parameters:
valueType
- The class of the value typedirectory
- The directory to store files in
-
YamlStorageProvider
Creates a new YamlStorageProvider with a custom file extension.- Parameters:
valueType
- The class of the value typedirectory
- The directory to store files infileExtension
- The file extension to use (including the dot)
-
-
Method Details
-
initialize
Initializes the storage provider. This method should be called before using the provider.- Specified by:
initialize
in interfaceStorageProvider<T,
String> - Overrides:
initialize
in classAbstractStorageProvider<T,
String> - Returns:
- A CompletableFuture that completes when initialization is done
-
save
Saves an object to the storage.- Parameters:
key
- The key to identify the objectvalue
- The object to save- Returns:
- A CompletableFuture that completes when the operation is done
-
get
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
Retrieves all objects from the storage.- Returns:
- A CompletableFuture that completes with a collection of all objects
-
delete
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
-