Class AbstractConfig

  • All Implemented Interfaces:
    Config, UnmodifiableConfig, java.lang.Cloneable
    Direct Known Subclasses:
    AbstractCommentedConfig

    public abstract class AbstractConfig
    extends java.lang.Object
    implements Config, java.lang.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 Detail

      • mapCreator

        protected final java.util.function.Supplier<java.util.Map<java.lang.String,​java.lang.Object>> mapCreator
    • Constructor Detail

      • AbstractConfig

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

        public AbstractConfig​(java.util.function.Supplier<java.util.Map<java.lang.String,​java.lang.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​(java.util.Map<java.lang.String,​java.lang.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,
                              java.util.function.Supplier<java.util.Map<java.lang.String,​java.lang.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 Detail

      • getDefaultMapCreator

        protected static <T> java.util.function.Supplier<java.util.Map<java.lang.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> java.util.function.Supplier<java.util.Map<java.lang.String,​T>> getWildcardMapCreator​(java.util.function.Supplier<java.util.Map<java.lang.String,​java.lang.Object>> mapCreator)
      • getRaw

        public <T> T getRaw​(java.util.List<java.lang.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​(java.util.List<java.lang.String> path,
                         java.lang.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​(java.util.List<java.lang.String> path,
                           java.lang.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​(java.util.List<java.lang.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​(java.util.List<java.lang.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​(java.util.List<java.lang.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 java.util.Map<java.lang.String,​java.lang.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 java.util.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 java.lang.Object
        Returns:
        a new Config that contains the same entries as this config.
      • hashCode

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

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object