*
The moose likes Java in General and the fly likes Help deciding best type of list for my situation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Help deciding best type of list for my situation" Watch "Help deciding best type of list for my situation" New topic
Author

Help deciding best type of list for my situation

Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 483

I have this code:





Which is going to return anywhere from 1 to 100 values on any given run. I was told on another forum for what Im needing to do I can use "either collections(list), array or maps." So which would be appropriate, or better yet, which will be easiest for me to use. DeviceCollection is just a list<devices> which holds a list of devices from the Device class, so keep in mind I need it to be compatible. So it might be best to just use the same data type that I am using in DeviceCollection
If I could just replace the ..... from that code with something like

byte [] = y;
y.append(x);

It would be preferred. Something that is simple. I will probably make a separate class to hold these values, so instead of y.append(x) I will use class.setValues(x); but the same question remains.
So I am very unfamiliar with collections in java, so what does someone experienced believe I should use here?


True wisdom is in knowing you know nothing - Socrates
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Hi Matt,

So you have a method getDevices() that returns a collection of Device objects, and you want to do something to each Device, but I'm not sure what. Do you want to make a collection of the deviceId values? Is that it? If so, then pretty much any collection would work. What would narrow it down is what you want to do with the collection once you've made it. Do you envision iterating over the deviceIds in order? Then a List is good. Do you want a collection of unique deviceIds, with no duplicates? Maybe a Set would be better, then. Or do you want to quickly lookup a Device given its deviceId? In that case, a Map would fit the bill. Tell us what you want to actually achieve, and we'll help you figure out how to do it.


[Jess in Action][AskingGoodQuestions]
Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 483

Well this object will change session to session, and depending on the user. The value this collection contains will be deviceid like you said, btu eventually there will be many others like project, name, channel, etc
These will be used in a richfaces tree to populate recursive tree nodes, so when a user logs in he will have a project explorer pane (similar to eclipse) that will have his projects as the roots, devices as a child of projects and channels as a child of devices.

-project
---device
------channel

A user can have multiple projects, a project can have multiple devices, adn a device can have multiple channels, so I need something to hold all the values for each which I can then bind to the tree nodnd

On the richfaces forum I was told that the data types I am able to bind to this recursive tree node are "collections(list), array or maps"

Oh and I do have a restriction on client response time (2ms if Im rememebring right), which is why I am asking this, because with my relative inexperience my code is already going to be clunky and sluggish as it is
Kavita Tipnis
Ranch Hand

Joined: Sep 21, 2008
Posts: 177
Matt Kohanek wrote:Well this object will change session to session, and depending on the user. The value this collection contains will be deviceid like you said, btu eventually there will be many others like project, name, channel, etc
These will be used in a richfaces tree to populate recursive tree nodes, so when a user logs in he will have a project explorer pane (similar to eclipse) that will have his projects as the roots, devices as a child of projects and channels as a child of devices.

-project
---device
------channel

A user can have multiple projects, a project can have multiple devices, adn a device can have multiple channels, so I need something to hold all the values for each which I can then bind to the tree nodnd

On the richfaces forum I was told that the data types I am able to bind to this recursive tree node are "collections(list), array or maps"

Oh and I do have a restriction on client response time (2ms if Im rememebring right), which is why I am asking this, because with my relative inexperience my code is already going to be clunky and sluggish as it is

Matt, from what you described I am guessing my post at Last Post
might help.

Root Nodes can refer to you projects in this case,
modify the RootNodes(Projects) to include List<Device>
modify Device to include List<Channel>

and for each user just iterate over this xmldata object.




Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 483

Oh no, I had your post in mind when I made this thread. I definitely plan to make a separate class for this, but I just wanted to use the most optimal data type I could, since as I said the rest of my code is probably going to be slowing me down.
Kavita Tipnis
Ranch Hand

Joined: Sep 21, 2008
Posts: 177
Matt Kohanek wrote:Oh no, I had your post in mind when I made this thread. I definitely plan to make a separate class for this, but I just wanted to use the most optimal data type I could, since as I said the rest of my code is probably going to be slowing me down.


I am not tasking you for not replying to my post ! Ok alternately, you can also use a Map<User,Project> to display the tree nodes
If you are talking in terms of efficiency of iterating through the collection,a brief look at the collections generics tutorial will help
Collections
 
Don't get me started about those stupid light bulbs.
 
subject: Help deciding best type of list for my situation
 
Similar Threads
Trying to add string values to a list or some type of collection through iterator
Trying to bind data to a TreeNode attribute using data read from a web service with simple xml
storing multiple attributes for one entity
If I use println to print out an input stream value, what should it look like?
rich:tree working now... all the work has finally paid off - THANKS