This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Cattle Drive and the fly likes OOP-4 Lookup hashmap Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "OOP-4 Lookup hashmap" Watch "OOP-4 Lookup hashmap" New topic
Author

OOP-4 Lookup hashmap

K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2994
    
    9

I once done this assignment a while back and now trying to enhance it and stuff. But I found a potential problem with my implementation.

When the hashmap is created should the value be a "Thing" or "String" through the getDescription() method?
eg HashMap<Integer, String> hMap ... or HashMap<Integer,Thing> hMap ...
assuming I populate the hashmap like this:
hMap.put(1, new BookOnTape()); //<Integer,Thing>
hMap.put(1, new BookOnTape().getDescription()); //<Integer,String>

Another way of asking is once the hashmap is populated, should the Thing's serial number be the same as the hashmap key?

Thanks


K. Tsang JavaRanch SCJP5 SCJD OCPJP7 OCPWCD5 OCPBCD5 OCPWSD5 OCMJEA5 part 1 part 2/3
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9056
    
  12
The value should be a Thing.

It is ok if the Thing's serial number is the same as the hashmap key, but the value should be the Thing, not the Thing's description.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2994
    
    9

Thanks Marilyn, I got the serial number same as hashmap key
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: OOP-4 Lookup hashmap
 
It's not a secret anymore!