TreeSet problem:

Hello All,

I'm working on an app that is dumping a sql resultset into an arrayList and then into a TreeSet. I've never done work with a TreeSet before, but what I have is one large object of data, with no keys to separate the key/value pairs that are enclosed. What I understand is that there are no keys to try and pull the values out with.

The data is similar to this in the TreeSet:

[model.Role@c7d55 code = [audit] desc = [Access to JIMS usage data] name = [JIMS Audit], model.Role@4455 code = [basic] desc = [Basic access to JIMS ] name = [JIMS Basic], model.Role@3c43 code = [privacy] description = [Access to JIMS privacy data] name = [JIMS Privacy], etc... ]]

My questions are these:

1.) Is there a way to take a treeSet and create a treeMap with ordered key/value pairs? I didn't see any code on this. What I need are separate groupings of key/value pairs.

2.) What is the best collection object to use for this?

Thank you,

James

[999 byte] By [jamesEstona] at [2007-11-26 12:29:46]
# 1

This is not a TreeSet problem. If you don't have keys, you cannot create a Map. An SQL result set usually will have some key-value background, either by the order you defined in the SQL request's SELECT statement or by any OR mapping you applied.

What is the use of putting the resulting set into a list and afterwards into a set, btw.? Both are collections taking objects as members. You should actually put or create key-value pairs from result set into the Map.

Get knowledge about what objects the result set contains and treat those as you need to. According to your data print it seems to me, that the result set contains Objects of Type Role in a package called model. Take whatever attribute should be used as key and stuff those into the map with the object as value.

stefan.schulza at 2007-7-7 15:39:37 > top of Java-index,Core,Core APIs...
# 2

I agree it's a data problem. So since I've got multiples of key/value pairs in the data, with a few groupings of the data up to several dozen, what is the best way to structure this with collection objects, keeping performance in mind? What I'm asking is I could do HashMaps, but I'm wondering if ArrayLists or LinkedList might be a better fit for this data structure? What I'm seeking is the best way to store the data and retrieve it from a collection or group of collection objects.

After looking at more of the code it uses helper DAO objects to hold parts of the information and to retrieve it from the TreeSet objects. Maybe that is the best collection object after all as it needs to hold multiple sets of key/value pairs in separate groups. Does anyone know of more complex code examples of TreeSets?

Message was edited by:

jamesEston

jamesEstona at 2007-7-7 15:39:37 > top of Java-index,Core,Core APIs...
# 3

>what is the best way to structure this with collection

> objects, keeping performance in mind?

I would think about the best way to do it. And if that isn't fast enough, then do your optimizations.

Anway, if you don't have keys then a HashMap is not what you want. It seems like all you need is a List that has been sorted. You can sort the items in SQL before you pull them out of the result set. Or you can use the Collections.sort() method to sort a list after you put them into it.

Maybe I don't fully understand, but if you have duplicates then you don't want a Set.Because a set doesn't allow duplicates.

zadoka at 2007-7-7 15:39:37 > top of Java-index,Core,Core APIs...
# 4

No, it's much more complicated than what I've explained. I'm maintaining some very complicated, convuluted code, at least in my opinion. There are no duplicates here.

What I have is a single DAO object, containing TreeSets that are each a large, single collection object with sorted groupings of object data in key/value pairs. This single DAO is tightly coupled with two other DAO obects that are used to extract the treeset data throughout the app.

I've used all kinds of collection objects before, but I have never seen this kind of structure and wasn't aware of this type of functionality.

Currently I'm just integrating the existing code with a new object until I can come up with some other mechanism to do the same thing without the other tightly coupled objects because maintaining this code looks like a formidable task as these objects are everywhere in the code. The altered code snippet I provided is part of a 5 item Treeset. Here is another that is part of a 30 value TreeSet:

[[], [model.Function@b4de code = [Utilization] description = [Access to Utilization] name = [Utilization], model.Function@b59a code = [Onhand] description = [Access to Onhand] name = [Onhand], etc...

Each value in the TreeSet is made up of 3 key/value pairs and like I said there are 30 values in this TreeSet, sorted of course, and 5 in another. Then in some of the TreeSets there are arrayList groupings, usually 2 or 3, of the previously mentioned data that are dumped into a TreeSet and the result is one very large object, with all these groupings of data that are difficult to work with (impossible for me so far) to extract without using the existing code.

Does this make more sense of what I'm dealing with?

jamesEstona at 2007-7-7 15:39:37 > top of Java-index,Core,Core APIs...
# 5

> Does this make more sense of what I'm dealing with?

Not really.

You say very large tree sets but then you say 30 items? When I think very large I am thinking in the ten thousands.

It sounds like a lot of data that should be modeled into Objects rather than a bunch of sets. (However, you said you will be making changes later).

What is the problem with using the TreeSets? If you are going to improve it later, is your problem that it doesn't work now? I think all these details have clouded the question in my head.

zadoka at 2007-7-7 15:39:37 > top of Java-index,Core,Core APIs...
# 6

The problem is I have to integrate a new object and new sql/tables into the code. If you think the details I've given are complicated, you should see the code! Everytime I try to integrate a small piece of code it breaks in a hundred places, so I'm trying to get used to TreeSets and how to extract the data out properly to make the integration work for now and refactor later. My goal is to get it working with the integration to make the deadline and then fix everything later.

jamesEstona at 2007-7-7 15:39:37 > top of Java-index,Core,Core APIs...
# 7
I'm closing this out and restating it as a new post to get it down to it's essentials. Thanks for viewing and responding Zadok.
jamesEstona at 2007-7-7 15:39:37 > top of Java-index,Core,Core APIs...