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

Cloning a complex tree structure

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am currently involved in a project were we implement a propiatory cgi c++ based web framework in java.
I have a page object which represents a html page containing special tags (not jsp tags).
The page object contains a tree structure of the actual html page.
I have a repository class in the framework where all page objects are held. Each time
a user makes a request for a page the framework picks the page object from the repository and
runs the runtime engine over it.
The problem I am facing is that I have to make a copy of the original page object in the repository
for the user to work with but could not find an easy or working way to do this.
Has anybody an idea how to solve this problem elegantly and most of all in a fast ( runtime that is ) manner.
Thanks for your helpful comments.
Best regards,
jay
----------
SCJP, SCJD
 
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Has anybody an idea how to solve this problem elegantly and most of all in a fast ( runtime that is ) manner.
One option is to recursively call clone() on the object, so all its data members are copied deeply (as opposed to a shallow copy)
Another option is to use what is equivalent to a copy constructor in C++.
In both cases, care must be taken so that you don't miss the references to mutable objects while copying the source.
Eugene.
 
It is difficult to free fools from the chains they revere - Voltaire. tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic