No subject
Sat Nov 12 19:29:10 PST 2005
is in the file (most importantly the order and repetition thereof) then why
not create classes fot the things you need to read and delegate to allowing
them to read the information themselves.
For example you could create Person and Address clasess and simply:
+ create an instance of the Person class
+ ask it to load its information from the data source
+ create an instance of the Address class
+ ask it to load its information from the data source
This may not be as abstract as you propose in your solution but may work out
for the best especially if you want to encapsulate specific behaviour that
acts on the data (e.g. you can ask the address instance to validate changes
to the address).
This can also allow to expand the solution to support multiple people with
their respective addresses - Unless you affix some data (like a sequence/row
number) to the fields that you are storing in your HashMap you won't be able
to support more than one person without creating an outer datastructure.
Anyways all these ideas are food for thought as they may or may not conform
nicely to your requirements (which you didn't necessarily mention outside of
the problem itself ;-)
HTH.
--Nikolaos
> -----Original Message-----
> From: advanced-java-admin at lists.xcf.berkeley.edu
> [mailto:advanced-java-admin at lists.xcf.berkeley.edu]On Behalf Of Dave
> Wathen
> Sent: Saturday, May 25, 2002 10:15 PM
> To: Laszlo Nadai; advanced-java at lists.xcf.berkeley.edu
> Subject: RE: [Advanced-java] HashMap Q.
>
>
> If you're using 1.4 you could use a LinkedHashMap. If not you could
> implement the equivalent - a HashMap whose entries form a linked list
> - yourself.
>
> However the overhead maintaining a HashMap and an ArrayList is not much
> more than this scheme so unless you've got some compelling reason not to
> I'd just go with that.
>
> Dave Wathen
> Canzonet Limited
> http://www.canzonet.com
> mailto:dave.wathen at canzonet.com
>
> -----Original Message-----
> From: advanced-java-admin at lists.xcf.berkeley.edu
> [mailto:advanced-java-admin at lists.xcf.berkeley.edu]On Behalf Of Laszlo
> Nadai
> Sent: 25 May 2002 21:51
> To: advanced-java at lists.xcf.berkeley.edu
> Subject: [Advanced-java] HashMap Q.
>
>
> Hello Gurus,
> Let's say I have a plain text file names, addresses,....
> I read it into some type of Collection. From every input I build a Name
> and an Address object.
> I wanted to use HashMap, so I can find an Address object by using a key
> (Name).
> My problem is that I need to remember the original order (I have to
> write it back in the same order).
> I was trying to use a class with an additional int (order) property in
> addition to the String name and then I can
> make the class Comparable and sort.
> But the problem is that when I want to find an Address, I only know the
> String name (not the order).
> I could have 2 Collections (and Arraylist and a HashMap).
> Or I could use 2 HashMaps (Name, order) and (order,Address) but I don't
> like that either.
> Anyone with an elegant solution?
> (RTFM's are also welcome...)
> Thanks,
> laszlo
>
> _______________________________________________
> Advanced-java mailing list
> Advanced-java at lists.xcf.berkeley.edu
> http://lists.xcf.berkeley.edu/mailman/listinfo/advanced-java
>
> _______________________________________________
> Advanced-java mailing list
> Advanced-java at lists.xcf.berkeley.edu
> http://lists.xcf.berkeley.edu/mailman/listinfo/advanced-java
>
More information about the Advanced-java
mailing list