java.lang.Object
org.bspfsystems.yamlconfiguration.configuration.MemorySection
org.bspfsystems.yamlconfiguration.configuration.MemoryConfiguration
All Implemented Interfaces:
Configuration, ConfigurationSection
Direct Known Subclasses:
FileConfiguration

public class MemoryConfiguration extends MemorySection implements Configuration
Represents an implementation of a configuration that exists only in-memory. This is useful for providing temporary storage and access to data and for providing defaults.

Synchronized with the commit on 07-June-2022.

  • Field Details

  • Constructor Details

    • MemoryConfiguration

      public MemoryConfiguration()
      Constructs an empty memory configuration with no default values.
      See Also:
    • MemoryConfiguration

      public MemoryConfiguration(@Nullable @Nullable Configuration defs)
      Constructs an empty memory configuration using the given configuration as a source for all default values.
      Parameters:
      defs - The default value provider configuration.
      See Also:
  • Method Details

    • addDefault

      public final void addDefault(@NotNull @NotNull String path, @Nullable @Nullable Object value)
      Sets the default value in the root at the given path as provided.

      If no source configuration was provided as a default collection, then a new memory configuration will be created to hold the given default value.

      If value is null, the value will be removed from the default configuration source.

      If the value as returned by ConfigurationSection.getDefaultSection() is null, then this will create a new configuration section at the path, replacing anything that may have existed there previously.

      Specified by:
      addDefault in interface Configuration
      Specified by:
      addDefault in interface ConfigurationSection
      Overrides:
      addDefault in class MemorySection
      Parameters:
      path - The path of the default value to set.
      value - The value to set the default to.
    • addDefaults

      public final void addDefaults(@NotNull @NotNull Map<String,Object> defs)
      Sets the default values of the given paths as provided.

      If no source configuration was provided as a default collection, then a new memory configuration will be created to hold the given default values.

      Specified by:
      addDefaults in interface Configuration
      Parameters:
      defs - A map of paths to values to add to the defaults.
    • addDefaults

      public final void addDefaults(@NotNull @NotNull Configuration defs)
      Sets the default values of the given paths as provided.

      If no source configuration was provided as a default collection, then a new memory configuration will be created to hold the given default values.

      This method will not hold a reference to the given configuration, nor will it automatically update if the given configuration ever changes. If the automatic updates are required, please set the default source with Configuration.setDefaults(Configuration).

      Specified by:
      addDefaults in interface Configuration
      Parameters:
      defs - A configuration holding a map of defaults to copy.
    • setDefaults

      public final void setDefaults(@NotNull @NotNull Configuration defs)
      Sets the source of all default values for this configuration.

      If a previous source was set, or previous default values were defined, then they will not be copied to the new source.

      Specified by:
      setDefaults in interface Configuration
      Parameters:
      defs - New source of default values for this configuration.
    • getDefaults

      @Nullable public final @Nullable Configuration getDefaults()
      Gets the default configuration for this configuration.

      If no configuration source was set, but default values were added, then a memory configuration will be returned. If no source was set and no defaults were set, then this method will return null.

      Specified by:
      getDefaults in interface Configuration
      Returns:
      The configuration source for default values, or null if none exist.
    • getParent

      @Nullable public final @Nullable ConfigurationSection getParent()
      Gets the parent configuration section that directly contains this section.

      If this configuration section is itself a configuration, this will return null.

      If this configuration section is no longer contained within a root configuration for any reason, such as being replaced with a different value, this may return null.

      Specified by:
      getParent in interface ConfigurationSection
      Overrides:
      getParent in class MemorySection
      Returns:
      The parent configuration section containing this section, or null if this section does not have a parent.
    • getOptions

      @NotNull public @NotNull MemoryConfigurationOptions getOptions()
      Gets the options for this configuration.

      All setters through this method are chainable.

      Specified by:
      getOptions in interface Configuration
      Returns:
      The options for this configuration.