• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to generate sequenced group number and sub-group number?

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi folks,
I'm new here, really need help!
I need to generate sequence numbers for groups of objects. the sequenced group numbers can have sub-group numbers, the display would be like this:
1. This is header
1.1. This is sub-header
1.1.1. This is sub-sub-hearder
1.2. Thank you
1.3. Welcome
Also I need to auto update the numbers if I change the sequence, for example, if I move "1.3. Welcome" to in front of "1.1. This is sub-hearder", the display would change to:
1. This is header
1.1. Welcome
1.2. This is sub-header
1.2.1. This is sub-sub-hearder
1.3. Thank you
Can anyone give me some hints please?
Thanks a lot
 
Ranch Hand
Posts: 539
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One approach to this would be to use the composite pattern for number generation.
Better than this would be to make a composite tree of objects (whatever they may be), and use the visitor pattern to traverse the tree and output the numbers as needed. This assumes that the numbers aren't a fundamental property of the objects, rather it's a property of the object's location in the tree.
That's one approach, anyway. Your design will depend a lot on how complex the whole thing will get and how much functionality each object has - composite & visitor may be overkill for simple situations, but it's a very extensible model.

Cheers,
-Tim
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do you get the information to put into the outline? If somebody hands you a tree of data you're most of the way there. Say each node of the tree looks like:

Zat make any sense? You'll have to adjust a bit. I bet your outline has a level "2." so you don't print your root, but 1, 2, 3 are the children of the invisible root. And that's not all exactly Java.
I assumed a tree of data, and standard output. If you're doing another form of input or maybe a Swing display, nearly everything changes.
 
richard chang
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tim and James,
Thank you very much for your help. I'll look into composit pattern and visitor pattern. And the display will be on web pages, so in my mind I would use JSP to publish the data.
James, yes my outline would have 2.-2.1-2.1.1, 3.-3.1-3.2, etc.
Any more ideas would be appreciated. I'll try above suggestion and let you guys know later.
Cheers
reply
    Bookmark Topic Watch Topic
  • New Topic