HashMap implementation question

H

hal

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
 
C

Chris Smith

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
 
M

Mark McConnell

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top