HashMap implementation question

Discussion in 'Java' started by hal@no_spam_statsbiblioteket.dk, Jul 7, 2004.

  1. 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
     
    hal@no_spam_statsbiblioteket.dk, Jul 7, 2004
    #1
    1. Advertising

  2. hal@no_spam_statsbiblioteket.dk

    Chris Smith Guest

    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
     
    Chris Smith, Jul 7, 2004
    #2
    1. Advertising

  3. hal@no_spam_statsbiblioteket.dk wrote in message news:<ccgslu$tjj$-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.
     
    Mark McConnell, Jul 7, 2004
    #3
  4. 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
     
    Andrew Thompson, Jul 8, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vince Darley
    Replies:
    4
    Views:
    4,429
    emilchacko
    Mar 2, 2010
  2. JR
    Replies:
    4
    Views:
    701
  3. Shawn

    a HashMap question

    Shawn, Sep 11, 2006, in forum: Java
    Replies:
    2
    Views:
    367
    Shawn
    Sep 11, 2006
  4. Rakesh
    Replies:
    10
    Views:
    12,180
    Mike Schilling
    Apr 8, 2008
  5. Andreas Leitgeb

    Question about HashMap and Map.Entry ...

    Andreas Leitgeb, Aug 30, 2012, in forum: Java
    Replies:
    15
    Views:
    695
    Robert Klemme
    Sep 1, 2012
Loading...

Share This Page