You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by "Daniel Adrian (JIRA)" <ji...@apache.org> on 2007/05/22 18:33:16 UTC

[jira] Created: (CONFIGURATION-271) BaseConfiguration duplicates multi value keys values

BaseConfiguration duplicates multi value keys values
----------------------------------------------------

                 Key: CONFIGURATION-271
                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-271
             Project: Commons Configuration
          Issue Type: Bug
          Components: Build
    Affects Versions: 1.4
            Reporter: Daniel Adrian


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: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Updated: (CONFIGURATION-271) BaseConfiguration duplicates multi value keys values

Posted by "Emmanuel Bourg (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CONFIGURATION-271?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Emmanuel Bourg updated CONFIGURATION-271:
-----------------------------------------

    Fix Version/s: 1.5

> BaseConfiguration duplicates multi value keys values
> ----------------------------------------------------
>
>                 Key: CONFIGURATION-271
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-271
>             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: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Commented: (CONFIGURATION-271) BaseConfiguration duplicates multi value keys values

Posted by "Daniel Adrian (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CONFIGURATION-271?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12498258 ] 

Daniel Adrian commented on CONFIGURATION-271:
---------------------------------------------

Actually I used ConfigurationUtils. append which uses addProperty...
Maybe some flag to indicate if duplicated values are allowed or not...

> BaseConfiguration duplicates multi value keys values
> ----------------------------------------------------
>
>                 Key: CONFIGURATION-271
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-271
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.4
>            Reporter: Daniel Adrian
>         Assigned To: Emmanuel Bourg
>             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: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Commented: (CONFIGURATION-271) BaseConfiguration duplicates multi value keys values

Posted by "Emmanuel Bourg (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CONFIGURATION-271?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12497977 ] 

Emmanuel Bourg commented on CONFIGURATION-271:
----------------------------------------------

Could you add an example of the expected behavior ?

> BaseConfiguration duplicates multi value keys values
> ----------------------------------------------------
>
>                 Key: CONFIGURATION-271
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-271
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.4
>            Reporter: Daniel Adrian
>
> 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: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Commented: (CONFIGURATION-271) BaseConfiguration duplicates multi value keys values

Posted by "Daniel Adrian (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CONFIGURATION-271?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12498008 ] 

Daniel Adrian commented on CONFIGURATION-271:
---------------------------------------------

yes,

If I have file1.ini and file2.ini and I want to merge the values from file2 to file1.

file1:

[test]
some_key=xxx,yyy
file2:

[test]
some_key=xxx,yyy,zzz,fff

If you'll add all the properties of file2 to file1 the result will be:
[test]
some_key=xxx,yyy,xxx,yyy,zzz,fff

where is should be:
[test]
some_key=xxxx,yyy,zzz,fff



> BaseConfiguration duplicates multi value keys values
> ----------------------------------------------------
>
>                 Key: CONFIGURATION-271
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-271
>             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: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Commented: (CONFIGURATION-271) BaseConfiguration duplicates multi value keys values

Posted by "Emmanuel Bourg (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CONFIGURATION-271?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12498025 ] 

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();
config.load("file1.ini");
config.load("file2.ini");
config.save("file1.ini");

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) keys.next();

            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 {
                    values.add(value1);
                }
                
                if (value2 instanceof Collection) {
                    values.addAll((Collection) value2);
                } else {
                    values.add(value2);
                }

                target.setProperty(key, values);
            }
        }
    }

> BaseConfiguration duplicates multi value keys values
> ----------------------------------------------------
>
>                 Key: CONFIGURATION-271
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-271
>             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: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Updated: (CONFIGURATION-271) BaseConfiguration duplicates multi value keys values

Posted by "Daniel Adrian (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CONFIGURATION-271?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Daniel Adrian updated CONFIGURATION-271:
----------------------------------------

    Component/s:     (was: Build)

> BaseConfiguration duplicates multi value keys values
> ----------------------------------------------------
>
>                 Key: CONFIGURATION-271
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-271
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.4
>            Reporter: Daniel Adrian
>
> 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: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org