LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 12-16-2002, 10:43 PM   #1
tunedLow
Member
 
Registered: Sep 2001
Location: Salt Lake City
Distribution: Slackware 8.1
Posts: 133

Rep: Reputation: 15
java data structures


I am fairly new to programming, and am writing a simple GUI address book in java. (This is _not_ any kind of homework problem, just for fun).

I have a simple class called Entry.java, which describes each entry into the address book - name, number, address, comments.

In the main class, Address.java, the GUI is drawn, and action events such as "Add entry", "Delete entry" etc. are handled.

The GUI uses tabs to move between different functions of the address book (as in add, delete, search). The first tab displays the entries by first name, last name, and number, a-c, d-f, etc, each again tabbed (sounds a bit confusing, but is actually easy to work with).

I am currently using java's TreeMap to hold all the entries, because they will be ordered, and give fast look up times. I need them to be ordered so that the panel the panel that displays the lists of names, can simply iterate through each name and decide on which subpanel to draw it to (m-0, or x-z for example).

My question is - how might I handle duplicate entries. I am now using the first name as a key to the TreeMap, so they can be ordered by first name. I need to be able to handle mulitple identical first names. If I map the entries using, say, the phone number, I could have multiple identical first names, but then they won't be in the order.

I think I need use a different data structure, say an ArrayList, and then when I want the panel to display the names in order, dump the ArrayList into something else that can order them. But not sure how I could do this - short of write my own implementation of ArrayList and add an sort() method.

Any ideas would be appreciated.
Thanks!
 
Old 12-16-2002, 11:31 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,005
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
You might look at hashtables ... that's a structure that supports
unique entries ...

Cheers,
Tink
 
Old 12-17-2002, 01:00 AM   #3
tunedLow
Member
 
Registered: Sep 2001
Location: Salt Lake City
Distribution: Slackware 8.1
Posts: 133

Original Poster
Rep: Reputation: 15
Well, from what I can tell in the api is that Hashtable implements the Map interface, which doesn't allow duplicates. And I need both duplicates and sorting. I would like to be able to have two identical entries in to the Address book.

So using an Array or Linked list would allow the duplicates, but then I'd have to sort them some other way.

Using a TreeMap would sort them as I entered them, but not allow duplicates.

Using some Hashing implementation wouldn't let me do either.

That's why I'm thinking ArrayList, and then have a sorting function built in. So each time I added an entry, I would just call my sort() method on it right after.

Please correct me if my understanding is off - still new to this.
Thanks again.
 
Old 12-17-2002, 08:14 AM   #4
cybercop12us
Member
 
Registered: Aug 2001
Posts: 60

Rep: Reputation: 15
cant u use mulitmap kind of thing which will support duplication
 
Old 12-17-2002, 12:51 PM   #5
tunedLow
Member
 
Registered: Sep 2001
Location: Salt Lake City
Distribution: Slackware 8.1
Posts: 133

Original Poster
Rep: Reputation: 15
Thanks, that was a good keyword, found lots of folks classes named that. Will see about adding that package.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Data structures - Trees rahul_kulkarni Programming 1 05-16-2005 06:45 AM
[java]removing unwanted data from a file djadhav Programming 1 10-24-2004 09:32 AM
JAVA:Problems in Displaying Data to Terminal.. nedian123 Programming 1 07-06-2004 11:13 PM
perl->large data structures->copying lackluster Programming 0 08-20-2003 11:27 AM
Are there man pages for data structures? concoran Programming 3 07-05-2002 04:07 PM


All times are GMT -5. The time now is 01:54 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration