Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   HashMap implementation question (http://www.velocityreviews.com/forums/t134975-hashmap-implementation-question.html)

hal@no_spam_statsbiblioteket.dk 07-07-2004 01:14 PM

HashMap implementation question
 
I have a HashMap containing references to rather large value objects (
Vector objects containing > 1000 other objects each )
I rarely need to actually access these values -> and performance in
accessing them is not an issue.
Therefore I have made my own implementation of the HashMap where I
overwrite get and put and instead of putting in a reference to the
objects I serialize the values and store a String with a path to the
serialized object ( get reads the object - so the implementation is
somewhat transparent though any object stored now is immutable ).

Now in rare cases I need to loop through the entire Map using the
Map.Entity collection.
How do I control when the objects are deserialized in the loop in a way
that is transparent to the user of the HashMap? What implementing method
is called when calling getValue() on a Map.Entity object?

Regards
Hans Lund

Chris Smith 07-07-2004 05:52 PM

Re: HashMap implementation question
 
hal@no_spam_statsbiblioteket.dk wrote:
> I have a HashMap containing references to rather large value objects (
> Vector objects containing > 1000 other objects each )
> I rarely need to actually access these values -> and performance in
> accessing them is not an issue.
> Therefore I have made my own implementation of the HashMap where I
> overwrite get and put and instead of putting in a reference to the
> objects I serialize the values and store a String with a path to the
> serialized object ( get reads the object - so the implementation is
> somewhat transparent though any object stored now is immutable ).


A better implementation would be to write your own class implementing
the Map interface (possibly by extending java.util.AbstractMap), and use
a HashMap internally to store the path names, never exposing that
HashMap to your client. You'd then just return a Set from entrySet that
also knows to deserialize objects, and in turn it would return an
Iterator that returns Map.Entry objects that know how to deserialize
objects. Same for the Collection returned by values().

If you still want to extend HashMap, you'll still need to override
entrySet() and values() to return something that knows how to
deserialize your objects.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

Mark McConnell 07-07-2004 10:03 PM

Re: HashMap implementation question
 
hal@no_spam_statsbiblioteket.dk wrote in message news:<ccgslu$tjj$1@news.net.uni-c.dk>...
> How do I control when the objects are deserialized in the loop in a way
> that is transparent to the user of the HashMap? What implementing method
> is called when calling getValue() on a Map.Entity object?


You might want to look at the source code for HashMap and Map.Entry.
It is usually in src.zip in the top directory where Java is installed.

Andrew Thompson 07-08-2004 12:31 AM

Re: HashMap implementation question
 
On 7 Jul 2004 15:03:18 -0700, Mark McConnell wrote:

> You might want to look at the source code for HashMap and Map.Entry.


<http://www.physci.org/source.jsp?class=java.util.HashMap>
<http://www.physci.org/source.jsp?class=java.util.Map>

HTH

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology


All times are GMT. The time now is 01:26 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.