Solved

How to use a nested TreeMap

Posted on 2003-11-25
6
464 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
countX 22 70
array6 challenfge 6 63
Java asynchronous logging 4 34
Java Loop 4 14
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This video teaches viewers about errors in exception handling.

757 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