• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Question about TreeMaps, HashMaps etc. ...

Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everybody,

I have a question regarding my Model implementation (URLyBird Client):

I want to store the Rooms in a certain order but still be able to access them in a fast way.

Right now I am doing the following:

I keep a TreeMap<Integer, Room> which sorts the rooms by their Room Number.

To allow a fast access, I defined a second map

HashMap<Integer, Integer> which maps the Room Numbers in an order that can be accessed by the Table Model.
If the Table Model wants to have the 5th entry it would be like that :

Integer roomNumber = hashmap.get(5)
Room room = treemap.get(roomNumber);

Is this ok, or how did you do it ?
Posts: 11604
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Daniel,

First of all: why would you need a map to sort the rooms by room number (recNo)? I don't think a CSR is interested in a recNo, I guess they would be more interested in a sort on name and/or location. I simply used a List to store the rooms and that's it. If in a next release a request to sort the records is asked, I will implement a TableRowSorter for example. But now that's not needed, so simple don't do it.
Here you can read some details about my approach with the List.

Kind regards,
    Bookmark Topic Watch Topic
  • New Topic