Interface ConfigurationDefinition<C>

Type Parameters:
C - the configuration type
All Known Subinterfaces:
Configuration<C>

public interface ConfigurationDefinition<C>
Provides the minimal methods for reading and writing configurations from data trees
  • Method Details

    • getType

      @NonNull TypeToken<C> getType()
      Gets the reified type of the configuration interface
      Returns:
      a type token for the config interface
    • getLayout

      @API(status=MAINTAINED) @NonNull ConfigurationDefinition.Layout 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, DeveloperMistakeException will 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 from
      readOptions - 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 update
      readOptions - 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 config parameter 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 configuration
      dataTree - the data tree to write to
      writeOptions - full parameters to customize the operation