Class ImmutableSection

java.lang.Object
cc.carm.lib.configuration.source.section.ImmutableSection
All Implemented Interfaces:
ConfigureSection

public class ImmutableSection extends Object implements ConfigureSection
  • Field Details

  • Method Details

    • of

      public static ImmutableSection of(@NotNull @NotNull ConfigureSection section)
    • parent

      @Nullable public @Nullable ImmutableSection parent()
      Description copied from interface: ConfigureSection
      Gets the parent section of this section.

      For root sections, this will return null.

      Specified by:
      parent in interface ConfigureSection
      Returns:
      Parent section, or null if this is a root section.
    • path

      @NotNull public @NotNull String path()
      Description copied from interface: ConfigureSection
      Get the current section's path from ConfigureSection.parent() of this section.
      Specified by:
      path in interface ConfigureSection
      Returns:
      The current path of this section, if ConfigureSection.isRoot(), return empty string.
    • getValues

      @NotNull public @NotNull @UnmodifiableView Map<String,Object> getValues(boolean deep)
      Description copied from interface: ConfigureSection
      Gets a set containing all values in this section.

      If deep is set to true, then this will contain all the keys within any child ConfigureSections (and their children paths).

      If deep is set to false, then this will contain only the keys of any direct children, and not their own children.

      Specified by:
      getValues in interface ConfigureSection
      Parameters:
      deep - Whether to get a deep list.
      Returns:
      Map of data values contained within this Section.
    • set

      public void set(@NotNull @NotNull String path, @Nullable @Nullable Object value)
      Description copied from interface: ConfigureSection
      Sets the value at the given path.

      Null values will be kept, if you want to remove a value use ConfigureSection.remove(String) Path separator depends on holder's StandardOptions.PATH_SEPARATOR

      Specified by:
      set in interface ConfigureSection
      Parameters:
      path - The path to set the value at.
      value - The value to set.
    • remove

      public void remove(@NotNull @NotNull String path)
      Description copied from interface: ConfigureSection
      Removes the value at the given path.

      Path separator depends on holder's StandardOptions.PATH_SEPARATOR

      Specified by:
      remove in interface ConfigureSection
      Parameters:
      path - The path to remove the value at.
    • createSection

      @NotNull public @NotNull ImmutableSection createSection(@NotNull @NotNull String path, @NotNull @NotNull Map<?,?> data)
      Description copied from interface: ConfigureSection
      Creates a new ConfigureSection with specified values.

      The ConfigureSection.parent() of the new section will be this section.

      This section will not be saved until ConfigureSection.set(String, Object) is called.

      If you want to create and use a section and set it to this section, use ConfigureSection.computeSection(String).

      Specified by:
      createSection in interface ConfigureSection
      Parameters:
      data - The data to be used to create section.
      Returns:
      Newly created section
    • get

      @Nullable public @Nullable Object get(@NotNull @NotNull String path)
      Description copied from interface: ConfigureSection
      Get the origin value of the path.
      Specified by:
      get in interface ConfigureSection
      Parameters:
      path - The path to get the value from.
      Returns:
      The value at the path, or null if not found.
    • getSection

      @Nullable public @Nullable ConfigureSection getSection(@NotNull @NotNull String path)
      Description copied from interface: ConfigureSection
      Get the value as a ConfigureSection from the specified path.
      Specified by:
      getSection in interface ConfigureSection
      Parameters:
      path - The path to get the section.
      Returns:
      The section if the path exists and is a section, otherwise null.
    • pathSeparator

      public char pathSeparator()
      Description copied from interface: ConfigureSection
      Get the path separator for the section.
      Specified by:
      pathSeparator in interface ConfigureSection
      Returns:
      The path separator
    • isRoot

      public boolean isRoot()
      Description copied from interface: ConfigureSection
      Gets if this section is a root section.
      Specified by:
      isRoot in interface ConfigureSection
      Returns:
      True if this section is a root section, false otherwise.
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: ConfigureSection
      Gets if this section is empty.
      Specified by:
      isEmpty in interface ConfigureSection
      Returns:
      True if this section is empty, false otherwise.
    • getKeys

      @NotNull public @NotNull @UnmodifiableView Set<String> getKeys(boolean deep)
      Description copied from interface: ConfigureSection
      Gets a set containing all keys in this section.

      If deep is set to true, then this will contain all the keys within any child ConfigureSections (and their children paths).

      If deep is set to false, then this will contain only the keys of any direct children, and not their own children.

      Specified by:
      getKeys in interface ConfigureSection
      Parameters:
      deep - Whether to get a deep list.
      Returns:
      Set of keys contained within this Section.
    • keys

      @NotNull public @NotNull @UnmodifiableView Set<String> keys()
      Description copied from interface: ConfigureSection
      Gets a set containing all primary keys in this section.
      Specified by:
      keys in interface ConfigureSection
      Returns:
      Set of keys contained within this Section.
    • values

      @NotNull public @NotNull @UnmodifiableView Map<String,Object> values()
      Description copied from interface: ConfigureSection
      Gets a set containing all key-values in this section.
      Specified by:
      values in interface ConfigureSection
      Returns:
      Map of data values contained within this Section.
      See Also:
    • asMap

      @NotNull public @NotNull @UnmodifiableView Map<String,Object> asMap()
      Description copied from interface: ConfigureSection
      Get this section as a map.

      In this map, child ConfigureSections will also be represented as Maps.

      Specified by:
      asMap in interface ConfigureSection
      Returns:
      Map of data values contained within this Section.
    • stream

      public Stream<Map.Entry<String,Object>> stream()
      Description copied from interface: ConfigureSection
      Create a stream of all values in this section.
      Specified by:
      stream in interface ConfigureSection
      Returns:
      Stream of all values in this section.
    • forEach

      public void forEach(@NotNull @NotNull BiConsumer<String,Object> action)
      Description copied from interface: ConfigureSection
      Iterates over all key-values in this section (include child sections)
      Specified by:
      forEach in interface ConfigureSection
      Parameters:
      action - The action to apply to each key.
    • contains

      public boolean contains(@NotNull @NotNull String path)
      Description copied from interface: ConfigureSection
      Check if the given path is present.

      Path separator depends on holder's StandardOptions.PATH_SEPARATOR

      Specified by:
      contains in interface ConfigureSection
      Parameters:
      path - The path to check.
      Returns:
      True if the value is present, false otherwise.
    • containsValue

      public boolean containsValue(@NotNull @NotNull String path)
      Description copied from interface: ConfigureSection
      Check if the value of given path is present.

      Path separator depends on holder's StandardOptions.PATH_SEPARATOR

      Specified by:
      containsValue in interface ConfigureSection
      Parameters:
      path - The path to check.
      Returns:
      True if the value is present, false otherwise.
    • isType

      public <T> boolean isType(@NotNull @NotNull String path, @NotNull @NotNull Class<T> typeClass)
      Description copied from interface: ConfigureSection
      Predicate the value of given path is specific type.
      Specified by:
      isType in interface ConfigureSection
      Type Parameters:
      T - The type to check.
      Parameters:
      path - The path to check.
      typeClass - The type's class
      Returns:
      True if the value is present and is the correct type, false otherwise.
    • isList

      public boolean isList(@NotNull @NotNull String path)
      Description copied from interface: ConfigureSection
      Predicate the value of given path is a List.
      Specified by:
      isList in interface ConfigureSection
      Parameters:
      path - The path to check.
      Returns:
      True if the value is present and is a list, false otherwise.
    • getList

      @Nullable public @Nullable List<?> getList(@NotNull @NotNull String path)
      Description copied from interface: ConfigureSection
      Get the value as a List from the specified path.
      Specified by:
      getList in interface ConfigureSection
      Parameters:
      path - The path to get the List.
      Returns:
      The list if the path exists and is a list, otherwise null.
    • isSection

      public boolean isSection(@NotNull @NotNull String path)
      Description copied from interface: ConfigureSection
      Predicate the value of given path is a ConfigureSection.
      Specified by:
      isSection in interface ConfigureSection
      Parameters:
      path - The path to check.
      Returns:
      True if the value is present and is a section, false otherwise.
    • get

      @Nullable public <T> T get(@NotNull @NotNull String path, @NotNull @NotNull Class<T> type)
      Description copied from interface: ConfigureSection
      Get the value of the path for specific type, if the path does not exist, return null.
      Specified by:
      get in interface ConfigureSection
      Type Parameters:
      T - The type of the value
      Parameters:
      path - The path to get the value from.
      type - The type class of the value
      Returns:
      The value at the path, or the default value if not found.
    • get

      @Nullable public <T> T get(@NotNull @NotNull String path, @NotNull @NotNull DataFunction<@Nullable Object,T> parser)
      Description copied from interface: ConfigureSection
      Get the value of the path using a parser function, if the path does not exist, return NULL.
      Specified by:
      get in interface ConfigureSection
      Type Parameters:
      T - The type of the value
      Parameters:
      path - The path to get the value from.
      parser - The function to parse the value
      Returns:
      The value at the path, or null if not found.
    • get

      @Nullable public <T> T get(@NotNull @NotNull String path, T defaults, @NotNull @NotNull Class<T> clazz)
      Description copied from interface: ConfigureSection
      Get the value of the path for specific type, if the path does not exist, return the default value.
      Specified by:
      get in interface ConfigureSection
      Type Parameters:
      T - The type of the value
      Parameters:
      path - The path to get the value from.
      defaults - The default value to return if the path does not exist.
      clazz - The type class of the value
      Returns:
      The value at the path, or the default value if not found.
    • get

      @Nullable public <T> T get(@NotNull @NotNull String path, T defaultValue, @NotNull @NotNull DataFunction<Object,T> parser)
      Description copied from interface: ConfigureSection
      Get the value of the path using a parser function, if the path does not exist, return the default value.
      Specified by:
      get in interface ConfigureSection
      Type Parameters:
      T - The type of the value
      Parameters:
      path - The path to get the value from.
      defaultValue - The default value to return if the path does not exist.
      parser - The function to parse the value
      Returns:
      The value at the path, or the default value if not found.
    • isBoolean

      public boolean isBoolean(@NotNull @NotNull String path)
      Description copied from interface: ConfigureSection
      Predicate the value of given path is a Boolean.
      Specified by:
      isBoolean in interface ConfigureSection
      Parameters:
      path - The path to check.
      Returns:
      True if the value is present and is a boolean, false otherwise.
    • getBoolean

      public boolean getBoolean(@NotNull @NotNull String path)
      Description copied from interface: ConfigureSection
      Get the value as a Boolean from the specified path.
      Specified by:
      getBoolean in interface ConfigureSection
      Parameters:
      path - The path to get the boolean.
      Returns:
      The boolean if the path exists and is a boolean, otherwise false.
    • getBoolean

      @Nullable public @Nullable Boolean getBoolean(@NotNull @NotNull String path, @Nullable @Nullable Boolean def)
      Description copied from interface: ConfigureSection
      Get the value as a Boolean from the specified path.
      Specified by:
      getBoolean in interface ConfigureSection
      Parameters:
      path - The path to get the boolean.
      def - The default value to return if the path does not exist.
      Returns:
      The boolean if the path exists and is a boolean, otherwise the default value.
    • isByte

      @Nullable public @Nullable Boolean isByte(@NotNull @NotNull String path)
      Description copied from interface: ConfigureSection
      Predicate the value of given path is a Byte.
      Specified by:
      isByte in interface ConfigureSection
      Parameters:
      path - The path to check.
      Returns:
      True if the value is present and is a byte, false otherwise.
    • getByte

      @Nullable public @Nullable Byte getByte(@NotNull @NotNull String path)
      Description copied from interface: ConfigureSection
      Get the value as a Byte from the specified path.
      Specified by:
      getByte in interface ConfigureSection
      Parameters:
      path - The path to get the byte.
      Returns:
      The byte if the path exists and is a byte, otherwise 0.
    • getByte

      @Nullable public @Nullable Byte getByte(@NotNull @NotNull String path, @Nullable @Nullable Byte def)
      Description copied from interface: ConfigureSection
      Get the value as a Byte from the specified path.
      Specified by:
      getByte in interface ConfigureSection
      Parameters:
      path - The path to get the byte.
      def - The default value to return if the path does not exist.
      Returns:
      The byte if the path exists and is a byte, otherwise the default value.
    • isShort

      public boolean isShort(@NotNull @NotNull String path)
      Description copied from interface: ConfigureSection
      Predicate the value of given path is a Short.
      Specified by:
      isShort in interface ConfigureSection
      Parameters:
      path - The path to check.
      Returns:
      True if the value is present and is a short, false otherwise.
    • getShort

      @Nullable public @Nullable Short getShort(@NotNull @NotNull String path)
      Description copied from interface: ConfigureSection
      Get the value as a Short from the specified path.
      Specified by:
      getShort in interface ConfigureSection
      Parameters:
      path - The path to get the short.
      Returns:
      The short if the path exists and is a short, otherwise 0.
    • getShort

      @Nullable public @Nullable Short getShort(@NotNull @NotNull String path, @Nullable @Nullable Short def)
      Description copied from interface: ConfigureSection
      Get the value as a Short from the specified path.
      Specified by:
      getShort in interface ConfigureSection
      Parameters:
      path - The path to get the short.
      def - The default value to return if the path does not exist.
      Returns:
      The short if the path exists and is a short, otherwise the default value.
    • isInt

      public boolean isInt(@NotNull @NotNull String path)
      Description copied from interface: ConfigureSection
      Predicate the value of given path is a Integer.
      Specified by:
      isInt in interface ConfigureSection
      Parameters:
      path - The path to check.
      Returns:
      True if the value is present and is an int, false otherwise.
    • getInt

      @Nullable public @Nullable Integer getInt(@NotNull @NotNull String path)
      Description copied from interface: ConfigureSection
      Get the value as a Integer from the specified path.
      Specified by:
      getInt in interface ConfigureSection
      Parameters:
      path - The path to get the int.
      Returns:
      The int if the path exists and is an int, otherwise 0.
    • getInt

      @Nullable public @Nullable Integer getInt(@NotNull @NotNull String path, @Nullable @Nullable Integer def)
      Description copied from interface: ConfigureSection
      Get the value as a Integer from the specified path.
      Specified by:
      getInt in interface ConfigureSection
      Parameters:
      path - The path to get the int.
      def - The default value to return if the path does not exist.
      Returns:
      The int if the path exists and is an int, otherwise the default value.
    • isLong

      public boolean isLong(@NotNull @NotNull String path)
      Description copied from interface: ConfigureSection
      Predicate the value of given path is a Long.F
      Specified by:
      isLong in interface ConfigureSection
      Parameters:
      path - The path to check.
      Returns:
      True if the value is present and is a long, false otherwise.
    • getLong

      @Nullable public @Nullable Long getLong(@NotNull @NotNull String path)
      Description copied from interface: ConfigureSection
      Get the value as a Long from the specified path.
      Specified by:
      getLong in interface ConfigureSection
      Parameters:
      path - The path to get the long.
      Returns:
      The long if the path exists and is a long, otherwise 0.
    • getLong

      @Nullable public @Nullable Long getLong(@NotNull @NotNull String path, @Nullable @Nullable Long def)
      Description copied from interface: ConfigureSection
      Get the value as a Long from the specified path.
      Specified by:
      getLong in interface ConfigureSection
      Parameters:
      path - The path to get the long.
      def - The default value to return if the path does not exist.
      Returns:
      The long if the path exists and is a long, otherwise the default value.
    • isFloat

      public boolean isFloat(@NotNull @NotNull String path)
      Description copied from interface: ConfigureSection
      Predicate the value of given path is a Float.
      Specified by:
      isFloat in interface ConfigureSection
      Parameters:
      path - The path to check.
      Returns:
      True if the value is present and is a float, false otherwise.
    • getFloat

      @Nullable public @Nullable Float getFloat(@NotNull @NotNull String path)
      Description copied from interface: ConfigureSection
      Get the value as a Float from the specified path.
      Specified by:
      getFloat in interface ConfigureSection
      Parameters:
      path - The path to get the float.
      Returns:
      The float if the path exists and is a float, otherwise 0.
    • getFloat

      @Nullable public @Nullable Float getFloat(@NotNull @NotNull String path, @Nullable @Nullable Float def)
      Description copied from interface: ConfigureSection
      Get the value as a Float from the specified path.
      Specified by:
      getFloat in interface ConfigureSection
      Parameters:
      path - The path to get the float.
      def - The default value to return if the path does not exist.
      Returns:
      The float if the path exists and is a float, otherwise the default value.
    • isDouble

      public boolean isDouble(@NotNull @NotNull String path)
      Description copied from interface: ConfigureSection
      Predicate the value of given path is a Double.
      Specified by:
      isDouble in interface ConfigureSection
      Parameters:
      path - The path to check.
      Returns:
      True if the value is present and is a double, false otherwise.
    • getDouble

      @Nullable public @Nullable Double getDouble(@NotNull @NotNull String path)
      Description copied from interface: ConfigureSection
      Get the value as a Double from the specified path.
      Specified by:
      getDouble in interface ConfigureSection
      Parameters:
      path - The path to get the double.
      Returns:
      The double if the path exists and is a double, otherwise 0.
    • getDouble

      @Nullable public @Nullable Double getDouble(@NotNull @NotNull String path, @Nullable @Nullable Double def)
      Description copied from interface: ConfigureSection
      Get the value as a Double from the specified path.
      Specified by:
      getDouble in interface ConfigureSection
      Parameters:
      path - The path to get the double.
      def - The default value to return if the path does not exist.
      Returns:
      The double if the path exists and is a double, otherwise the default value.
    • isChar

      public boolean isChar(@NotNull @NotNull String path)
      Description copied from interface: ConfigureSection
      Predicate the value of given path is a Character.
      Specified by:
      isChar in interface ConfigureSection
      Parameters:
      path - The path to check.
      Returns:
      True if the value is present and is a char, false otherwise.
    • getChar

      @Nullable public @Nullable Character getChar(@NotNull @NotNull String path)
      Description copied from interface: ConfigureSection
      Get the value as a Character from the specified path.
      Specified by:
      getChar in interface ConfigureSection
      Parameters:
      path - The path to get the char.
      Returns:
      The char if the path exists and is a char, otherwise null.
    • getChar

      @Nullable public @Nullable Character getChar(@NotNull @NotNull String path, @Nullable @Nullable Character def)
      Description copied from interface: ConfigureSection
      Get the value as a Character from the specified path.
      Specified by:
      getChar in interface ConfigureSection
      Parameters:
      path - The path to get the char.
      def - The default value to return if the path does not exist.
      Returns:
      The char if the path exists and is a char, otherwise the default value.
    • isString

      public boolean isString(@NotNull @NotNull String path)
      Description copied from interface: ConfigureSection
      Predicate the value of given path is a String.
      Specified by:
      isString in interface ConfigureSection
      Parameters:
      path - The path to check.
      Returns:
      True if the value is present and is a string, false otherwise.
    • getString

      @Nullable public @Nullable String getString(@NotNull @NotNull String path)
      Description copied from interface: ConfigureSection
      Get the value as a String from the specified path.
      Specified by:
      getString in interface ConfigureSection
      Parameters:
      path - The path to get the string.
      Returns:
      The string if the path exists and is a string, otherwise null.
    • getString

      @Nullable public @Nullable String getString(@NotNull @NotNull String path, @Nullable @Nullable String def)
      Description copied from interface: ConfigureSection
      Get the value as a String from the specified path.
      Specified by:
      getString in interface ConfigureSection
      Parameters:
      path - The path to get the string.
      def - The default value to return if the path does not exist.
      Returns:
      The string if the path exists and is a string, otherwise the default value.
    • getList

      @NotNull public <V> @NotNull List<V> getList(@NotNull @NotNull String path, @NotNull @NotNull DataFunction<Object,V> parser)
      Description copied from interface: ConfigureSection
      Get a list of values from current section

      If the path does not exist, an empty list will be returned
      Any changes please use ConfigureSection.set(String, Object) after changes

      Specified by:
      getList in interface ConfigureSection
      Type Parameters:
      V - The type of the values
      Parameters:
      path - The path to get the list from
      parser - The function to parse the values
      Returns:
      The list of values
    • getStringList

      @NotNull public @NotNull List<String> getStringList(@NotNull @NotNull String path)
      Description copied from interface: ConfigureSection
      Get a list of strings from current section

      Limitations see ConfigureSection.getList(String, DataFunction)

      Specified by:
      getStringList in interface ConfigureSection
      Parameters:
      path - The path to get the list from
      Returns:
      The list of strings
    • getIntegerList

      @NotNull public @NotNull List<Integer> getIntegerList(@NotNull @NotNull String path)
      Description copied from interface: ConfigureSection
      Get a list of integer from current section

      Limitations see ConfigureSection.getList(String, DataFunction)

      Specified by:
      getIntegerList in interface ConfigureSection
      Parameters:
      path - The path to get the list from
      Returns:
      The list of int values
    • getLongList

      @NotNull public @NotNull List<Long> getLongList(@NotNull @NotNull String path)
      Description copied from interface: ConfigureSection
      Get a list of long from current section

      Limitations see ConfigureSection.getList(String, DataFunction)

      Specified by:
      getLongList in interface ConfigureSection
      Parameters:
      path - The path to get the list from
      Returns:
      The list of long values
    • getDoubleList

      @NotNull public @NotNull List<Double> getDoubleList(@NotNull @NotNull String path)
      Description copied from interface: ConfigureSection
      Get a list of double from current section

      Limitations see ConfigureSection.getList(String, DataFunction)

      Specified by:
      getDoubleList in interface ConfigureSection
      Parameters:
      path - The path to get the list from
      Returns:
      The list of doubles
    • getFloatList

      @NotNull public @NotNull List<Float> getFloatList(@NotNull @NotNull String path)
      Description copied from interface: ConfigureSection
      Get a list of floats from current section

      Limitations see ConfigureSection.getList(String, DataFunction)

      Specified by:
      getFloatList in interface ConfigureSection
      Parameters:
      path - The path to get the list from
      Returns:
      The list of floats
    • getByteList

      @NotNull public @NotNull List<Byte> getByteList(@NotNull @NotNull String path)
      Description copied from interface: ConfigureSection
      Get a list of bytes from current section

      Limitations see ConfigureSection.getList(String, DataFunction)

      Specified by:
      getByteList in interface ConfigureSection
      Parameters:
      path - The path to get the list from
      Returns:
      The list of bytes
    • getCharList

      @NotNull public @NotNull List<Character> getCharList(@NotNull @NotNull String path)
      Description copied from interface: ConfigureSection
      Get a list of char from current section

      Limitations see ConfigureSection.getList(String, DataFunction)

      Specified by:
      getCharList in interface ConfigureSection
      Parameters:
      path - The path to get the list from
      Returns:
      The list of char
    • getSectionList

      @NotNull public @NotNull List<ConfigureSection> getSectionList(@NotNull @NotNull String path)
      Description copied from interface: ConfigureSection
      Get a list of ConfigureSection from current section
      Specified by:
      getSectionList in interface ConfigureSection
      Parameters:
      path - The path to get the list from
      Returns:
      The list of ConfigureSection
    • getCollection

      @NotNull public <T, C extends Collection<T>> C getCollection(@NotNull @NotNull String path, @NotNull @NotNull Supplier<C> constructor, @NotNull @NotNull DataFunction<Object,T> parser)
      Description copied from interface: ConfigureSection
      Get the specific type of collection from current section.
      Specified by:
      getCollection in interface ConfigureSection
      Type Parameters:
      T - The type of the values
      C - The type of the collection
      Parameters:
      path - The path to get the collection from
      constructor - The constructor of the collection
      parser - The function to parse the values
      Returns:
      The collection of values
    • stream

      @NotNull public @NotNull Stream<?> stream(@NotNull @NotNull String path)
      Description copied from interface: ConfigureSection
      Get the specific type of steam from current section.
      Specified by:
      stream in interface ConfigureSection
      Parameters:
      path - The path to get the stream from
      Returns:
      The stream of values
    • stream

      @NotNull public <T> @NotNull Stream<T> stream(@NotNull @NotNull String path, @NotNull @NotNull Function<Object,T> parser)
      Description copied from interface: ConfigureSection
      Get the specific type of steam from current section.
      Specified by:
      stream in interface ConfigureSection
      Type Parameters:
      T - The type of the values
      Parameters:
      path - The path to get the stream from
      parser - The function to parse the values
      Returns:
      The stream of values
    • childPath

      public String childPath(String path)
      Specified by:
      childPath in interface ConfigureSection
    • hashCode

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

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