Class AbstractConfig

java.lang.Object
com.electronwill.nightconfig.core.AbstractConfig
All Implemented Interfaces:
Config, UnmodifiableConfig, Cloneable
Direct Known Subclasses:
AbstractCommentedConfig

public abstract class AbstractConfig extends Object implements Config, Cloneable
An abstract Config that uses a Map to store its values. In practice it's often a HashMap, or a ConcurrentHashMap if the config is concurrent, but it accepts any type of Map.
  • Field Details

  • Constructor Details

    • AbstractConfig

      public AbstractConfig(boolean concurrent)
      Creates a new AbstractConfig backed by a new Map.
    • AbstractConfig

      public AbstractConfig(Supplier<Map<String,Object>> mapCreator)
      Creates a new AbstractConfig with all backing maps supplied by the given Supplier.
      Parameters:
      mapCreator - A supplier that will be called to create all config maps
    • AbstractConfig

      public AbstractConfig(Map<String,Object> map)
      Creates a new AbstractConfig backed by the specified Map.
      Parameters:
      map - the map to use to store the config values.
    • AbstractConfig

      public AbstractConfig(UnmodifiableConfig toCopy, boolean concurrent)
      Creates a new AbstractConfig that is a copy of the specified config.
      Parameters:
      toCopy - the config to copy
    • AbstractConfig

      public AbstractConfig(UnmodifiableConfig toCopy, Supplier<Map<String,Object>> mapCreator)
      Creates a new AbstractConfig that is a copy of the specified config, and with all backing maps supplied by the given Supplier.
      Parameters:
      toCopy - the config to copy
      mapCreator - A supplier that will be called to create all config maps
  • Method Details

    • getDefaultMapCreator

      protected static <T> Supplier<Map<String,T>> getDefaultMapCreator(boolean concurrent)
      Description copied from interface: Config
      Returns a map supplier that fullfills the given requirements. It preserves (or not) the insertion order of its values according to Config.isInsertionOrderPreserved().
      Parameters:
      concurrent - true to make the maps thread-safe
      Returns:
      a map supplier corresponding to the given settings
    • getWildcardMapCreator

      protected static <T> Supplier<Map<String,T>> getWildcardMapCreator(Supplier<Map<String,Object>> mapCreator)
    • getRaw

      public <T> T getRaw(List<String> path)
      Description copied from interface: UnmodifiableConfig
      Gets a value from the config. Doesn't convert NullObject.NULL_OBJECT to null.
      Specified by:
      getRaw in interface UnmodifiableConfig
      Type Parameters:
      T - the value's type
      Parameters:
      path - the value's path, each element of the list is a different part of the path.
      Returns:
      the value at the given path, or null if there is no such value.
    • set

      public <T> T set(List<String> path, Object value)
      Description copied from interface: Config
      Sets a config value.
      Specified by:
      set in interface Config
      Type Parameters:
      T - the type of the old value
      Parameters:
      path - the value's path, each element of the list is a different part of the path.
      value - the value to set
      Returns:
      the old value if any, or null
    • add

      public boolean add(List<String> path, Object value)
      Description copied from interface: Config
      Adds a config value. The value is set iff there is no value associated with the given path.
      Specified by:
      add in interface Config
      Parameters:
      path - the value's path, each element of the list is a different part of the path.
      value - the value to set
      Returns:
      true if the value has been added, false if a value is already associated with the given path
    • remove

      public <T> T remove(List<String> path)
      Description copied from interface: Config
      Removes a value from the config.
      Specified by:
      remove in interface Config
      Type Parameters:
      T - the type of the old value
      Parameters:
      path - the value's path, each element of the list is a different part of the path.
      Returns:
      the old value if any, or null
    • contains

      public boolean contains(List<String> path)
      Description copied from interface: UnmodifiableConfig
      Checks if the config contains a value at some path.
      Specified by:
      contains in interface UnmodifiableConfig
      Parameters:
      path - the path to check, each element of the list is a different part of the path.
      Returns:
      true if the path is associated with a value, false if it's not.
    • isNull

      public boolean isNull(List<String> path)
      Description copied from interface: UnmodifiableConfig
      Checks if the config contains a null value at some path.
      Specified by:
      isNull in interface UnmodifiableConfig
      Parameters:
      path - the path to check, each element of the list is a different part of the path.
      Returns:
      true if the path is associated with NullObject.NULL_OBJECT, false if it's associated with another value or with no value.
    • clear

      public void clear()
      Description copied from interface: Config
      Removes all values from the config.
      Specified by:
      clear in interface Config
    • size

      public int size()
      Description copied from interface: UnmodifiableConfig
      Gets the size of the config.
      Specified by:
      size in interface UnmodifiableConfig
      Returns:
      the number of top-level elements in the config.
    • valueMap

      public Map<String,Object> valueMap()
      Description copied from interface: Config
      Returns a Map view of the config's values. Any change to the map is reflected in the config and vice-versa.
      Specified by:
      valueMap in interface Config
      Specified by:
      valueMap in interface UnmodifiableConfig
      Returns:
      a Map view of the config's values.
    • entrySet

      public Set<? extends Config.Entry> entrySet()
      Description copied from interface: Config
      Returns a Set view of the config's entries. Any change to the set or to the entries is reflected in the config, and vice-versa.
      Specified by:
      entrySet in interface Config
      Specified by:
      entrySet in interface UnmodifiableConfig
      Returns:
      a Set view of the config's entries.
    • clone

      public abstract AbstractConfig clone()
      Creates and return a copy of this config.
      Overrides:
      clone in class Object
      Returns:
      a new Config that contains the same entries as this config.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object