Commons Configuration
  1. Commons Configuration
  2. CONFIGURATION-182

[configuration] add new config.subsets() method to return multiple SubsetConfigurationS

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

      Description

      Please consider adding a configuration.subsets(String) method to return a list
      of subset configurations that match the string query. This corresponds to the
      configuration.subset(String) method that returns a single SubsetConfiguration.
      I mentioned this in a thread on the user list [1]. I hope it can be added in
      short order. I'm not sure whether returning a List or an Iterator would be
      best? In any case, I would use it like this (assuming, for now, that it returns
      a list)...

      List subConfigs = config.subsets("tables.table");
      for (Iterator iter = subConfigs.iterator(); iter.hasNext() {
      SubsetConfiguration subConfig = (SubsetConfiguration) iter.next();
      }

      ...where if I was only trying to get one subset configuration at a time, I
      might do...

      SubsetConfiguration subConfig = (SubsetConfiguration)
      config.subset("tables.table(0)");

      Of course, I always use the subset configuration in the context of a
      loop/iteration, since I need to deal with all of them (and where there may be
      any number "tables.table" entries in the XML), not just one at a time leading to
      the rather ugly while loop example I resorted to in the thread I referenced.
      Does this seem reasonable to add to the next release?

      [1] - http://marc.theaimsgroup.com/?l=jakarta-commons-user&m=113528247017087&w=2

      Jake

        Activity

        Hide
        Oliver Heger added a comment -

        Yes, this sounds reasonable.

        When working on the refactoring of the internal node structures used by
        HierarchicalConfiguration I had the idea of a different Configuration class,
        which is very similar to SubsetConfiguration, but more light weight.

        The subset() method in HierarchicalConfiguration as it is implemented ATM is not
        really efficient because it involves copying of whole sub trees. For the special
        case that the subset contains only a single node (which would be the case for
        this use case: a list of subset configurations, each of which represents one
        configuration node), a specialized SubnodeConfiguration could be used. This
        class would wrap a (sub) node of a parent configuration and would perform all of
        its operations directly on this node and its children. So manipulations at the
        SubnodeConfiguration or its parent would directly be visible to each other.

        I will do some experiments with this idea. But whatever the outcome is, this
        feature request in any case makes sense.

        Show
        Oliver Heger added a comment - Yes, this sounds reasonable. When working on the refactoring of the internal node structures used by HierarchicalConfiguration I had the idea of a different Configuration class, which is very similar to SubsetConfiguration, but more light weight. The subset() method in HierarchicalConfiguration as it is implemented ATM is not really efficient because it involves copying of whole sub trees. For the special case that the subset contains only a single node (which would be the case for this use case: a list of subset configurations, each of which represents one configuration node), a specialized SubnodeConfiguration could be used. This class would wrap a (sub) node of a parent configuration and would perform all of its operations directly on this node and its children. So manipulations at the SubnodeConfiguration or its parent would directly be visible to each other. I will do some experiments with this idea. But whatever the outcome is, this feature request in any case makes sense.
        Hide
        Oliver Heger added a comment -

        I have implemented a method that returns a list of sub configurations and that
        should do what you want.

        This method makes use of a new SubnodeConfiguration class that directly operates
        on a node of another HierarchicalConfiguration. So constructing such objects is
        quite efficient, which makes them better suited for this particular use case.

        HierarchicalConfiguration now defines two methods:

        • configurationAt() returns a SubnodeConfiguration for a single selected node
        • configurationsAt() returns a list of SubnodeConfiguration objects for all
          nodes selected by the passed in key; this is the method of choice for your use case.

        I also updated the XML howtos to document these new methods.

        Show
        Oliver Heger added a comment - I have implemented a method that returns a list of sub configurations and that should do what you want. This method makes use of a new SubnodeConfiguration class that directly operates on a node of another HierarchicalConfiguration. So constructing such objects is quite efficient, which makes them better suited for this particular use case. HierarchicalConfiguration now defines two methods: configurationAt() returns a SubnodeConfiguration for a single selected node configurationsAt() returns a list of SubnodeConfiguration objects for all nodes selected by the passed in key; this is the method of choice for your use case. I also updated the XML howtos to document these new methods.
        Hide
        Jacob Kjome added a comment -

        Excellent! Thank you, Oliver

        Jake

        Show
        Jacob Kjome added a comment - Excellent! Thank you, Oliver Jake

          People

          • Assignee:
            Unassigned
            Reporter:
            Jacob Kjome
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development