You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by lello <rb...@gmail.com> on 2010/12/10 13:54:02 UTC

HashMap vs List in a ListView

Hi all,

from what I have read a ListView model is contained in a List<> object. Is
it possible to use a HashMap instead of a List<>?
-- 
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/HashMap-vs-List-in-a-ListView-tp2063310p2063310.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: HashMap vs List in a ListView

Posted by lello <rb...@gmail.com>.
What you described is my actual implementation. However, the problem comes
when I need to create a new item in the list or remove one from it. The List
is synchronized with a table in an SQL database and my idea was to use the
hash keys as index in the table. I know the problems of the standard
hashCode() in Java, so collisions might be possible, but I was also thinking
about implementing my own hash function.
I think I'll get stuck with the current implementation.
Thanks for your help.
-- 
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/HashMap-vs-List-in-a-ListView-tp2063310p2064468.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: HashMap vs List in a ListView

Posted by Greg Brown <gk...@verizon.net>.
OK - why not just create a Book object and pass a List<Book> to your ListView? Your Book class can have a getHashKey() method that you can use to get the directory name to use (though note that, in the JDK at least, hash keys are not guaranteed to be unique, so you may end up with naming collisions).


On Dec 10, 2010, at 8:09 AM, lello wrote:

> 
> The case is quite simple. I have a collection of data (books for example) and
> I want to associate an hash key 
> to each element. I need the hash key because I want to use it as the name of
> a directory which can contain supplementary information on my data.
> -- 
> View this message in context: http://apache-pivot-users.399431.n3.nabble.com/HashMap-vs-List-in-a-ListView-tp2063310p2063356.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.


Re: HashMap vs List in a ListView

Posted by lello <rb...@gmail.com>.
The case is quite simple. I have a collection of data (books for example) and
I want to associate an hash key 
to each element. I need the hash key because I want to use it as the name of
a directory which can contain supplementary information on my data.
-- 
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/HashMap-vs-List-in-a-ListView-tp2063310p2063356.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: HashMap vs List in a ListView

Posted by Greg Brown <gk...@verizon.net>.
> from what I have read a ListView model is contained in a List<> object.
> Is it possible to use a HashMap instead of a List<>?

A List provides indexed access whereas a Map uses keys (there is no implicit ordering in a Map). In order to use a map, you'd need to wrap it in a list.

Can you describe your use case more specifically? Maybe there is another option.