Class MigrateFromConfiguration<C>

java.lang.Object
space.arim.dazzleconf.migration.MigrateFromConfiguration<C>
Type Parameters:
C - the config type
All Implemented Interfaces:
MigrateSource<C>

public final class MigrateFromConfiguration<C> extends Object implements MigrateSource<C>
A migration source from another configuration with this library.

Warning: This migration source only verifies that the old configuration could be loaded from the current backend, using that backend's recommended key mapper. However, if your old configuration provides default values everywhere, it will load anything, and it will appear to be always detected! See the package javadoc for more information on this problem, or consider adding a MigrateSource.Filter to this migration source.

  • Constructor Details

    • MigrateFromConfiguration

      public MigrateFromConfiguration(@NonNull Configuration<C> config)
      Creates
      Parameters:
      config - the configuration to use
  • Method Details

    • load

      public @NonNull LoadResult<@NonNull C> load(@NonNull MigrateContext migrateContext)
      Description copied from interface: MigrateSource
      Attempts to load this configuration version.

      If the old version isn't detectable or in usable, returns an error.

      Updated paths

      If the loading the old configuration produced any new keys, or updated existing ones, the implementor should use the migration context's load listener to flag these updates. UpdateReason.MIGRATED should be used for all key updates.

      Importantly, updates should only be flagged when the implementation is sure it will return a success value, and after filters have been applied. Please see MigrateFromConfiguration for a reference implementation.

      Specified by:
      load in interface MigrateSource<C>
      Parameters:
      migrateContext - migration context to use if necessary
      Returns:
      the old configuration version, or an error if not found and usable
    • onCompletion

      public void onCompletion()
      Description copied from interface: MigrateSource
      Signals that the migration was fully completed.

      This means that the old config version may not be necessary to keep around. It might be time to delete, or move to a different place (like config_old.yml) for archival purposes.

      Specified by:
      onCompletion in interface MigrateSource<C>
    • addFilter

      public @NonNull MigrateSource<C> addFilter(@NonNull MigrateSource.Filter<C> filter)
      Description copied from interface: MigrateSource
      Returns a new migration source, with the given filter applied.

      Values from the original MigrateSource.load(MigrateContext) will be passed through the filter, and if the filter returns false, the resulting load(MigrateContext) will return an empty error instead.

      Specified by:
      addFilter in interface MigrateSource<C>
      Parameters:
      filter - the source filter to apply
      Returns:
      a new migration source, taking into account the filter