[Logo] Space4J - Java Persistence
  [Search] Search   [Recent Topics] Recent Topics   [Hottest Topics] Hottest Topics   [Members]  Member Listing   [Groups] Back to home page 
[Moderation Log] Moderation Log   [Register] Register / 
[Login] Login 
Indexed example  XML
Forum Index » General Questions
Author Message
zlaja



Joined: 18/10/2008 06:43:16
Messages: 2
Offline

Hi,

I have question about the indexed example. It's about this comment:

// this is not good as we are transversing the whole list twice!
// TODO: Create custom iterator for MultiSortedMap to avoid this?

where the list is traversed twice?


Thanks
saoj



Joined: 05/09/2008 13:26:12
Messages: 26
Online


findUsers iterates through all the found items before it returns the result, which is in turn iterated again.

See the problem?

A better approach instead of iterating through all elements and sticking them in a new list object would be to create a custom iterator so that the findUsers method would return this iterator.

This is not a problem for small results, but for big results (>100k) this is not a good idea.

Did you get it?

To summarize: findUsers return a collection that we just iterate through. Returning a iterator would be more appropriate for large subsets.

But, if you assume that you want a Collection with the returned elements, then this implemenation is appropriate.
zlaja



Joined: 18/10/2008 06:43:16
Messages: 2
Offline

Yes,

The second iteration will be done in a client code.


Thanks for reply
 
Forum Index » General Questions
Go to:   
Powered by JForum 2.1.8 © JForum Team