Package io.github.vitalforge.persistlib
Class BasePersist
java.lang.Object
io.github.vitalforge.persistlib.BasePersist
Base class for persisting objects to and from YAML files.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> T
Creates an object from persisted data.createDump
(Object instance, boolean withSuper) Creates persisted data from an object.<T> T
loadFromYaml
(String file, Class<T> clazz) Loads an object from a YAML file.void
saveToYaml
(Object instance, String file) Saves an object to a YAML file.void
saveToYaml
(Object instance, String file, boolean withSuper) Saves an object to a YAML file.<T> T
update
(T instance, PersistData<T, Map<String, Object>> data) Updates an object with persisted data.
-
Constructor Details
-
BasePersist
public BasePersist()Creates a new instance of the BasePersist.
-
-
Method Details
-
loadFromYaml
Loads an object from a YAML file.- Type Parameters:
T
- The type of the object to load.- Parameters:
file
- The file from which to load the object.clazz
- The class of the object to load.- Returns:
- The object loaded from the YAML file.
-
update
Updates an object with persisted data.- Type Parameters:
T
- The type of the object to update.- Parameters:
instance
- The object to update.data
- The persisted data to use for the update.- Returns:
- The updated object.
-
create
Creates an object from persisted data.- Type Parameters:
T
- The type of the object to create.- Parameters:
data
- The persisted data from which to create the object.clazz
- The class of the object to create.- Returns:
- The object created from the persisted data.
-
createDump
Creates persisted data from an object.- Parameters:
instance
- The object from which to create the persisted data.withSuper
- Whether to include fields from superclasses.- Returns:
- The persisted data created from the object.
-
saveToYaml
Saves an object to a YAML file.- Parameters:
instance
- The object to save.file
- The file to which to save the object.withSuper
- Whether to include fields from superclasses.
-
saveToYaml
Saves an object to a YAML file.- Parameters:
instance
- The object to save.file
- The file to which to save the object.
-