Note that there are some explanatory texts on larger screens.

plurals
  1. POSorting JDOM elements using Java API
    primarykey
    data
    text
    <p>I need your help with following issue:</p> <p>In my code I have a list of elements, I need to sort this list according to 2 attributes: season and number.</p> <p>List example:</p> <pre><code>&lt;episode_list&gt; &lt;episode id="280" number="13" season="1"&gt; &lt;title&gt;&lt;![CDATA[Bowl Game]]&gt;&lt;/title&gt; &lt;/episode&gt; &lt;episode id="314" number="12" season="1"&gt; &lt;title&gt;&lt;![CDATA[Piss Test]]&gt;&lt;/title&gt; &lt;/episode&gt; &lt;episode id="730" number="11" season="1"&gt; </code></pre> <p>I use Collections.sort(), but getting exception. As I understand I can't use it with JDOM Elements:</p> <pre><code>List&lt;Element&gt; episodes; Collections.sort(episodes, new Comparator&lt;Element&gt;() { @Override public int compare(Element elem1, Element elem2) { Integer seasonNumber1 = Integer.valueOf(myService.valueOfAttribute("season", elem1)); Integer seasonNumber2 = Integer.valueOf(myService.valueOfAttribute("season", elem2)); int seasonComp = seasonNumber1.compareTo(seasonNumber2); if (seasonComp != 0) { return seasonComp; } else { Integer episodeNumber1 = Integer.valueOf(myService.valueOfAttribute("number", elem1)); Integer episodeNumber2 = Integer.valueOf(myService.valueOfAttribute("number", elem2)); return episodeNumber1.compareTo(episodeNumber2); } } }); Exception: java.util.Collections$UnmodifiableList$1.set(Unknown Source) java.util.Collections.sort(Unknown Source) </code></pre> <p>Actually I don't need sorted xml, the only thing I need is the episode attribute "id" (for the lowest season and the lowest episode number).</p> <p>What could you recommend? I have another implementation, where I go through all elements, but I don't think it's a nice solution...I also can create Java class Episode(id, episode, season), transform List to List and sort it, but also don't think it's a good idea. There is also sortContent method for Element, but I'm not sure how to implement it.</p> <p>I'll appreciate any help.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload