• 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 ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Collections

 
Ranch Hand
Posts: 397
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I receive two collections - units and subunits.
Units contain one or more of subunits.
Each SubUnit has a unitId to which it belongs to.

I need to paint them like

Unit 1 Unit 2 Unit3

SubUnit1 SubUnit1 Subunit1
SubUnit2 SubUnit2
SubUnit3

How do I loop through the subunit collection and put them in appropriate collections of units and then do the paiting as above?

Any help is greatly appreciated.

Thanks,
Vasu
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is some pseudo-code if that helps.
 
vasu maj
Ranch Hand
Posts: 397
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, I thought of this but I do not know how many units and subsunits are coming. I do not know how to name the collections dynamically and then populate them.

I tried naming the collections with the unit name in the for loop but I didn't quite get how to do it.

Thanks,
Vasu
 
Matthew Mellott
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you be more specific and post some code? For instance, where are you getting input?

Also, from what you have said so far, I think you might find LinkedLists helpful. Here is a brief overview.
 
Marshal
Posts: 75617
354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you got a Unit class which encapsulates the Subunits?
 
vasu maj
Ranch Hand
Posts: 397
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I get the UnitDTOs and SubUnitDTOs come from resultset from a database call.
Unit class doesn't encompass SubUnit class but they are diff classes. Something like a buidling and room.

Thanks very much for your time.
 
Campbell Ritchie
Marshal
Posts: 75617
354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A building encompasses rooms, so the one definitely could be a field of the other class.
 
vasu maj
Ranch Hand
Posts: 397
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My problem is how do I create the collection objects on the fly as I do not know how many I get.
I need to fill them with a collection of subunits, each of the subunit going to the unit that it belongs to ( it has a field called unitId).

So if I lood through the subunits in a switch as suggested, how do I know where to send them ( which collection? What should be the name).
If I want to call the collections as unit1Collection or UnitsOne or something similar where do I give them the names. I tried to use a String object and append it the name of the unit in the loop but it is not compiling...

Like in the for loop of unitDTOs...

List<UnitDTO> new String("Unit").append(unitId) = new someList...


Thanks,
Vasu
 
Matthew Mellott
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, here's some more pseudo code. I am making the assumption that Units also have a unitId that corresponds to the subunits unitId (if they don't, then you need to find some way of make the subunits unitId correspond to the units position in the linked list). So below I use parallel linked lists (ll), sort of. The first ll is of units. The second ll is a ll of lls of subunits. The index of the each unit in the first ll corresponds to the ll of its subunits in the second ll.Hope this helps.
 
You have to be odd to be #1 - Seuss. An odd little ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic