2

i did search for information on this, but unfortunately couldnt find one .. Can anyone help with this ?

Example :

        URL feed = new URL(feedUrl);
        SyndFeedInput input = new SyndFeedInput();
        SyndFeed feedAllData = input.build(new XmlReader(feed));
        List<SyndEntry> data =  feedAllData.getEntries();

Does the List object "data" always contain the feed entries in the order that the feed published (i.e. the latest feed first and the rest in descending order of published date) ?

the outputs i got do list it in that order but im not a 100% sure whether its dependable and i can forgo the sorting excess.

Yoseph
  • 41
  • 1
  • 2
  • Just consult Rome source code, it's pretty clean and easy to read through. Can be very informative. – Victor Sorokin Mar 19 '12 at 20:37
  • Technically the feed order and the published date need not align. (Although I do not have a "live" counter-example handy, consider a naive feed aggregator.) As such, I would recommend *always* sorting on the published date *unless* such sorting is already done by ROME internally. The overhead is inconsequential. –  Mar 19 '12 at 21:12
  • Thanks. I did look there. It is not explicitly sorted. Was just a bit confused why it gave the output in order everytime i ran it. Anyways gonna explicitly sort it anyway. – Yoseph Mar 19 '12 at 23:48

1 Answers1

0

If you need the results to come out sorted, then sorting every time is the way to go. If it does happen to be the case that the result list is already sorted, the sort will be very fast O(n) since it doesn't really do any work, and if it needed to be sorted, you are covered.

As others have said, looking at the source is always a good idea if possible, but forcing it to be sorted yourself protects you if the dependent behavior changes in the future.

cdeszaq
  • 30,869
  • 25
  • 117
  • 173
  • @Yoseph - Glad to help. If you've found an answer useful, please consider giving that answer an up-vote. If an answer provides the solution to your problem, please consider marking that answer as the accepted answer. – cdeszaq Mar 20 '12 at 12:33