Solved

How to use a nested TreeMap

Posted on 2003-11-25
6
470 Views
Last Modified: 2006-11-17
Hi,

I have data in the following form: Library Case Study example

String borrower, Object loanstate, Object loanitem.

I have many borrowers, loanstate is either borrowed or returned and the loanitem
would be say a bookitem.

What I would like to do is output in the form:

Borrower:      Borrowed       Book1
                              Book2
                              Book3
                              ..etc
               Returned       Book1
                              Book3

I thought maybe a nested TreeMap would allow me to do this i.e.

Key, (key, value)

borrower (loanstate, loanitem) would allow me to do this.

Any suggestions on how to code this up ?

Thanks

Drew
0
Comment
Question by:DrewAllan
  • 2
  • 2
6 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 9817812
Your Borrower should be one entity. It should have a list of Books. One of the fields of Book should be loan state. The way you organise the collection of books is up to you. It could be a TreeMap keyed on the book's UID (ISBN)
0
 

Author Comment

by:DrewAllan
ID: 9817868
Can you give me an example of how to code it ?

Thanks
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9817886
Sorry - no. This is clearly class work and as such, it's against the Member Agreement to do this. We can certainly help with code you have already produced.
0
 

Author Comment

by:DrewAllan
ID: 9830355
Ok I can appreciate that but it was more an example of how to constuct it I was after.

How me suggesting an example of how to construct the Nested TreeMap

would it be

Map(index,[indexOuter,[[indexInner1, [value1, value2,... ],[indexInner22, [value22, value23,... ], [indexInner3, [value31, value32,... ],[indexInner4, [value42, value43,... ]..etc])

where index would be string object called Borrower and the outer nest value [index,[values]] would be say an ArrayList and then the inner nest values would be another ArrayList.

Do you think this would work or would there be a better way of doing it?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
What is the latest versions eclipse neon 2 139
Java asynchronous logging 4 50
Java passing arguments (type error) 2 48
servlet  URL Rewriting 1 25
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now