commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Emmanuel Bourg (JIRA)" <>
Subject [jira] Commented: (CONFIGURATION-271) BaseConfiguration duplicates multi value keys values
Date Tue, 22 May 2007 21:34:16 GMT


Emmanuel Bourg commented on CONFIGURATION-271:

I guess you merge the files by loading twice the same configuration instance ? Something like
this :

INIConfiguration config = new INIConfiguration();

Multi value properties have a list semantic and not a set semantic (i.e no duplicates), this
is not something that can be changed. The best is to use another method to merge your properties.
Here is an example of a function merging 2 configurations and eliminating redundant values

    public void merge(Configuration source, Configuration target)
        Iterator keys = source.getKeys();
        while (keys.hasNext())
            String key = (String);

            Object value1 = source.getProperty(key);
            Object value2 = target.getProperty(key);

            if (value2 == null) {
                target.setProperty(key, value1);
            } else {
                Set values = new HashSet();
                if (value1 instanceof Collection) {
                    values.addAll((Collection) value1);
                } else {
                if (value2 instanceof Collection) {
                    values.addAll((Collection) value2);
                } else {

                target.setProperty(key, values);

> BaseConfiguration duplicates multi value keys values
> ----------------------------------------------------
>                 Key: CONFIGURATION-271
>                 URL:
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.4
>            Reporter: Daniel Adrian
>             Fix For: 1.5
> In addPropertyDirect(String key, Object value) the method adds the new value to the property.
> If the property has the same value in the list, it will get duplicated.
> The method should check if the list contains the value and only if the result is false
add the value. 
> There is no logic in saving a multi value key with more than one instance of a value.

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message