Interface ConfigurationDefinition<C>
- Type Parameters:
C- the configuration type
- All Known Subinterfaces:
Configuration<C>
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceThe layout of a configuration definition.static interfaceParameters for reading a configuration from a treestatic interfaceParameters for reading a configuration and updating it in-placestatic interfaceParameters for writing a configuration to a tree -
Method Summary
Modifier and TypeMethodDescription@NonNull ConfigurationDefinition.LayoutGets the layout of the configuration interfacegetType()Gets the reified type of the configuration interface@NonNull CLoads the default configuration.@NonNull LoadResult<@NonNull C> readFrom(@NonNull DataTree dataTree, @NonNull ConfigurationDefinition.ReadOptions readOptions) A simple, stateless read from a data tree.@NonNull LoadResult<@NonNull C> readWithUpdate(@NonNull DataTree.Mut dataTree, @NonNull ConfigurationDefinition.ReadWithUpdateOptions readOptions) Reads from the data tree given, and updates it as necessary.voidwriteTo(@NonNull C config, @NonNull DataTree.Mut dataTree, @NonNull ConfigurationDefinition.WriteOptions writeOptions) Writes to the given data tree.
-
Method Details
-
getType
Gets the reified type of the configuration interface- Returns:
- a type token for the config interface
-
getLayout
Gets the layout of the configuration interface- Returns:
- the scanned layout of the configuration interface
-
loadDefaults
@NonNull C loadDefaults()Loads the default configuration.This will build a configuration object using only the default-providing mechanisms (i.e. annotations and default methods). Therefore, to use this method, every configuration entry is required to have a default value attached; if an entry lacks a default value,
DeveloperMistakeExceptionwill be thrown.- Returns:
- a configuration using wholly default values
- Throws:
DeveloperMistakeException- if one of the default-providing methods threw an exception, or gave null. Alternatively, if a configuration entry is lacking a default value set either by default methods or annotations
-
readFrom
@NonNull LoadResult<@NonNull C> readFrom(@NonNull DataTree dataTree, @NonNull ConfigurationDefinition.ReadOptions readOptions) A simple, stateless read from a data tree.This function loads from the data tree without modifying it, and it does not use migrations. The configuration is instantiated and returned upon success.
- Parameters:
dataTree- the data tree to read fromreadOptions- full parameters to customize the operation- Returns:
- the loaded configuration, or an error if failed
-
readWithUpdate
@NonNull LoadResult<@NonNull C> readWithUpdate(@NonNull DataTree.Mut dataTree, @NonNull ConfigurationDefinition.ReadWithUpdateOptions readOptions) Reads from the data tree given, and updates it as necessary.This function loads from the data tree, and it does not use migrations. However, if any entries need updating (as determined by
SerializeDeserialize.deserializeUpdate(DeserializeInput, SerializeOutput)) then the objects will be updated in the data tree. Callers can check whether any updates ocurred by using a load listener in the read options.- Parameters:
dataTree- the data tree to read and updatereadOptions- full parameters to customize the operation- Returns:
- the loaded configuration, or an error if failed
-
writeTo
void writeTo(@NonNull C config, @NonNull DataTree.Mut dataTree, @NonNull ConfigurationDefinition.WriteOptions writeOptions) Writes to the given data tree.The output data tree does not need to be empty, but there are no guarantees that existing data will not be overidden or cleared. The values of the provided configuration are written to it, and it does not matter how the
configparameter is implemented so long as it returns non-null values.Values are guaranteed to be inserted in the provided tree in the same order as the layout of this definition. Note that the order of the layout may differ from the source code order of methods.
- Parameters:
config- the configurationdataTree- the data tree to write towriteOptions- full parameters to customize the operation
-