Interface Config

    • Method Detail

      • set

        default <T> T set​(java.lang.String path,
                          java.lang.Object value)
        Sets a config value.
        Type Parameters:
        T - the type of the old value
        Parameters:
        path - the value's path, each part separated by a dot. Example "a.b.c"
        value - the value to set
        Returns:
        the old value if any, or null
      • set

        <T> T set​(java.util.List<java.lang.String> path,
                  java.lang.Object value)
        Sets a config value.
        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

        boolean add​(java.util.List<java.lang.String> path,
                    java.lang.Object value)
        Adds a config value. The value is set iff there is no value associated with the given path.
        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
      • add

        default boolean add​(java.lang.String path,
                            java.lang.Object value)
        Adds a config value. The value is set iff there is no value associated with the given path.
        Parameters:
        path - the value's path, each part separated by a dot. Example "a.b.c"
        value - the value to set
        Returns:
        true if the value has been added, false if a value is already associated with the given path
      • addAll

        default void addAll​(UnmodifiableConfig config)
        Adds all the values of a config to this config, without replacing existing entries.
        Parameters:
        config - the source config
      • putAll

        default void putAll​(UnmodifiableConfig config)
        Copies all the values of a config into this config. Existing entries are replaced, missing entries are created.
        Parameters:
        config - the source config
      • remove

        default <T> T remove​(java.lang.String path)
        Removes a value from the config.
        Type Parameters:
        T - the type of the old value
        Parameters:
        path - the value's path, each part separated by a dot. Example "a.b.c"
        Returns:
        the old value if any, or null
      • remove

        <T> T remove​(java.util.List<java.lang.String> path)
        Removes a value from the 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
      • removeAll

        default void removeAll​(UnmodifiableConfig config)
        Removes all the values of the given config from this config.
        Parameters:
        config - the values to remove
      • clear

        void clear()
        Removes all values from the config.
      • unmodifiable

        default UnmodifiableConfig unmodifiable()
        Returns an Unmodifiable view of the config. Any change to the original (modifiable) config is still reflected to the returned UnmodifiableConfig, so it's unmodifiable but not immutable.
        Returns:
        an Unmodifiable view of the config.
      • checked

        default Config checked()
        Returns a checked view of the config. It checks that all the values put into the config are supported by the config's format (as per the ConfigFormat.supportsType(Class) method. Trying to insert an unsupported value throws an IllegalArgumentException.

        The values that are in the config when this method is called are also checked.

        Returns:
        a checked view of the config.
      • valueMap

        java.util.Map<java.lang.String,​java.lang.Object> valueMap()
        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 UnmodifiableConfig
        Returns:
        a Map view of the config's values.
      • entrySet

        java.util.Set<? extends Config.Entry> entrySet()
        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 UnmodifiableConfig
        Returns:
        a Set view of the config's entries.
      • createSubConfig

        Config createSubConfig()
        Creates a new sub config of this config, as created when a subconfig's creation is implied by set(List, Object) or add(List, Object).
        Returns:
        a new sub config
      • update

        default void update​(java.lang.String path,
                            java.lang.Object value)
        For scala: sets a config value.
        Parameters:
        path - the value's path, each part separated by a dot. Example "a.b.c"
        value - the value to set
        See Also:
        set(String, Object)
      • update

        default void update​(java.util.List<java.lang.String> path,
                            java.lang.Object value)
        For scala: sets a config value.
        Parameters:
        path - the value's path, each element of the list is a different part of the path.
        value - the value to set
        See Also:
        set(List, Object)
      • of

        static Config of​(ConfigFormat<? extends Config> format)
        Creates a Config of the given format.
        Parameters:
        format - the config's format
        Returns:
        a new empty config
      • of

        static Config of​(java.util.function.Supplier<java.util.Map<java.lang.String,​java.lang.Object>> mapCreator,
                         ConfigFormat<?> format)
        Creates a Config backed by a certain kind of map, given by a supplier. If you wish all your configs to preserve insertion order, please have a look at the more practical setting setInsertionOrderPreserved(boolean).
        Parameters:
        mapCreator - a supplier which will be called to create all backing maps for this config (including sub-configs)
        format - the config's format
        Returns:
        a new config backed by the map
      • ofConcurrent

        static Config ofConcurrent​(ConfigFormat<? extends Config> format)
        Creates a thread-safe Config of the given format.
        Parameters:
        format - the config's format
        Returns:
        a new empty, thread-safe config
      • wrap

        static Config wrap​(java.util.Map<java.lang.String,​java.lang.Object> map,
                           ConfigFormat<?> format)
        Creates a Config backed by a Map. Any change to the map is reflected in the config and vice-versa. If you wish all your configs to preserve insertion order, please have a look at the more practical setting setInsertionOrderPreserved(boolean).
        Parameters:
        map - the Map to use
        format - the config's format
        Returns:
        a new config backed by the map
      • copy

        static Config copy​(UnmodifiableConfig config)
        Creates a new Config with the content of the given config. The returned config will have the same format as the copied config.
        Parameters:
        config - the config to copy
        Returns:
        a copy of the config
      • copy

        static Config copy​(UnmodifiableConfig config,
                           java.util.function.Supplier<java.util.Map<java.lang.String,​java.lang.Object>> mapCreator)
        Creates a new Config with the content of the given config. The returned config will have the same format as the copied config, and be backed by the given supplier. If you wish all your configs to preserve insertion order, please have a look at the more practical setting setInsertionOrderPreserved(boolean).
        Parameters:
        config - the config to copy
        mapCreator - a supplier which will be called to create all backing maps for this config (including sub-configs)
        Returns:
        a copy of the config
        See Also:
        of(Supplier, ConfigFormat)
      • copy

        static Config copy​(UnmodifiableConfig config,
                           ConfigFormat<?> format)
        Creates a new Config with the content of the given config.
        Parameters:
        config - the config to copy
        format - the config's format
        Returns:
        a copy of the config
      • copy

        static Config copy​(UnmodifiableConfig config,
                           java.util.function.Supplier<java.util.Map<java.lang.String,​java.lang.Object>> mapCreator,
                           ConfigFormat<?> format)
        Creates a new Config with the content of the given config. The returned config will be backed by the given map supplier. If you wish all your configs to preserve insertion order, please have a look at the more practical setting setInsertionOrderPreserved(boolean).
        Parameters:
        config - the config to copy
        mapCreator - a supplier which will be called to create all backing maps for this config (including sub-configs)
        format - the config's format
        Returns:
        a copy of the config
        See Also:
        of(Supplier, ConfigFormat)
      • concurrentCopy

        static Config concurrentCopy​(UnmodifiableConfig config)
        Creates a new Config with the content of the given config. The returned config will have the same format as the copied config.
        Parameters:
        config - the config to copy
        Returns:
        a thread-safe copy of the config
      • concurrentCopy

        static Config concurrentCopy​(UnmodifiableConfig config,
                                     ConfigFormat<?> format)
        Creates a new Config with the content of the given config.
        Parameters:
        config - the config to copy
        format - the config's format
        Returns:
        a thread-safe copy of the config
      • isInsertionOrderPreserved

        static boolean isInsertionOrderPreserved()
        Checks if the newly created configs keep the insertion order of their content. By default this is not the case. This can be controlled with the `nightconfig.ordered` system property or by calling setInsertionOrderPreserved(boolean).

        This setting does not apply to configurations created from a Map, from another Config, or with a specific map supplier.

        Returns:
        true if the new configs preserve the insertion order of their values, false to give no guarantee about the values ordering.
      • setInsertionOrderPreserved

        static void setInsertionOrderPreserved​(boolean orderPreserved)
        Modifies the behavior of the new configurations with regards to the preservation of the order of config values.

        This setting does not apply to configurations created from a Map, from another Config, or with a specific map supplier.

        Parameters:
        orderPreserved - true to make the new configs preserve the insertion order of their values, false to give no guarantee about the values ordering.
        See Also:
        isInsertionOrderPreserved()
      • getDefaultMapCreator

        static <T> java.util.function.Supplier<java.util.Map<java.lang.String,​T>> getDefaultMapCreator​(boolean concurrent,
                                                                                                             boolean insertionOrderPreserved)
        Returns a map supplier that fulfills the given requirements.
        Parameters:
        concurrent - true to make the maps thread-safe
        insertionOrderPreserved - true to make the maps preserve the insertion order of values
        Returns:
        a map supplier corresponding to the given settings
      • getDefaultMapCreator

        static <T> java.util.function.Supplier<java.util.Map<java.lang.String,​T>> getDefaultMapCreator​(boolean concurrent)
        Returns a map supplier that fullfills the given requirements. It preserves (or not) the insertion order of its values according to isInsertionOrderPreserved().
        Parameters:
        concurrent - true to make the maps thread-safe
        Returns:
        a map supplier corresponding to the given settings