You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xmlbeans.apache.org by "Adrian Grealish (JIRA)" <xm...@xml.apache.org> on 2006/08/29 21:17:23 UTC

[jira] Commented: (XMLBEANS-252) List returned by generated getFooList() is not sortable

    [ http://issues.apache.org/jira/browse/XMLBEANS-252?page=comments#action_12431326 ] 
            
Adrian Grealish commented on XMLBEANS-252:
------------------------------------------

I am seeing a similar issue except duplicates in the list after sorting.

When I sort a list returned from getFooList() using Collections.sort I am getting a duplicate in the list and teh collection size does not change.

If I try to sort list "aPLugin", "bPlugin", "cPLugin"

List<Plugin> pluginsList = xmlPlugins.getPluginList());
Collections.sort(pluginsList , new Comparator<Plugin>() {
                   public int compare(Plugin o1, Plugin o2) {
                           return o1.getName().compareTo(o2.getName());
                   }});


I get back plugins "aPLugin", "bPlugin", "aPLugin".

Plugins.getPluginList() (actually PluginsImpl.getPluginList()) returns a PluginList, which extends AbstractList<com.bea.usagetrack.protocol.v100.Plugin>. PluginList's get() and set() methods do some twisty stuff that looks like it should work for sort(), but obviously doesn't. Looks like some indirection in PluginsImpl is biting us for the sort().

If I create a new ArrayList first then it works

List<Plugin> newList = new ArrayList<Plugin>(xmlPlugins.getPluginList());
Collections.sort(newList, new Comparator<Plugin>() {
                      public int compare(Plugin o1, Plugin o2) {
                                 return o1.getName().compareTo(o2.getName());
                      }});




> List<Type> returned by generated getFooList() is not sortable
> -------------------------------------------------------------
>
>                 Key: XMLBEANS-252
>                 URL: http://issues.apache.org/jira/browse/XMLBEANS-252
>             Project: XMLBeans
>          Issue Type: Bug
>    Affects Versions: Version 2.1
>         Environment: Win XP SP2, JRE 1.5.0_06-b05, XMLBeans 2.1.0
>            Reporter: Erik Godding Boye
>            Priority: Minor
>
> I am trying to sort the list returned by the generated getFooList() [multiple occurrence method] using java.util.Collections#sort(java.util.List<Type>, java.util.Comparator<Type>). The elements are not sorted, and no exception is thrown. I would expect either, but I do not see any reason for the list to be unmodifiable (and thus throwing exception when trying to sort it). A simple workaround is to create a new list supplying the original list (from the generated method) in the constructor. The new list is sortable without any problems.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org