Class Configuration

java.lang.Object
br.net.dd.netherwingcore.common.configuration.Configuration

public class Configuration extends Object
The Configuration class represents a structure for managing configuration data. It organizes the data into sections and items, supporting the retrieval of specific configuration values by keys.

This class is designed to encapsulate a configuration's metadata such as a description and a service name, while also storing the configuration's hierarchical structure in sections and groups.

  • Constructor Details

    • Configuration

      public Configuration()
      Constructs an empty Configuration object with default values: - an empty description - an empty service name - an empty list of sections.
    • Configuration

      public Configuration(Description description, String serviceName)
      Constructs a Configuration object with the specified description and service name, initializing the sections list as empty.
      Parameters:
      description - A Description object representing the configuration description.
      serviceName - A String representing the service name associated with the configuration.
  • Method Details

    • addSection

      public Configuration addSection(Section section)
      Adds a new section to the configuration.
      Parameters:
      section - A Section object to be added.
      Returns:
      The Configuration object to allow method chaining.
    • get

      public Item get(Key key)
      Retrieves an Item from the configuration that matches the specified key.
      Parameters:
      key - The Key to be matched against the items in the configuration.
      Returns:
      The first Item that matches the key, or null if no matching item is found.
    • get

      public Integer get(String key, Integer defaultValue)
      Retrieves an integer value from the configuration based on the given key. Returns a default value if the item is not found or if the type does not match.
      Parameters:
      key - A String representing the key of the desired value.
      defaultValue - The default integer value to return if the key is not found.
      Returns:
      The integer value associated with the key, or the default value if not found.
    • get

      public String get(String key, String defaultValue)
      Retrieves a string value from the configuration based on the given key. Returns a default value if the item is not found or if the type does not match.
      Parameters:
      key - A String representing the key of the desired value.
      defaultValue - The default string value to return if the key is not found.
      Returns:
      The string value associated with the key, or the default value if not found.
    • getDescription

      public Description getDescription()
      Gets the description of the configuration.
      Returns:
      A Description object containing the configuration description.
    • getServiceName

      public String getServiceName()
      Gets the name of the service associated with the configuration.
      Returns:
      A String representing the service name.
    • getSections

      public List<Section> getSections()
      Gets the list of sections in the configuration.
      Returns:
      A list of Section objects representing the structure of the configuration.