473,804 Members | 3,021 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Real Problem with Deep Copy

1 New Member
Hi,

I need some help with the following code.
Expand|Select|Wrap|Line Numbers
  1. public class Site 
  2.     {
  3.         Integer NumberOfTeams = new Integer(initialize); 
  4.         Vector<Integer> TeamList = new Vector<Integer>(); 
  5. }
  6.  
  7. public void PrintTerritory (TeamsAndSites T)
  8.     {
  9.         int i = 1;
  10.         System.out.println("Print Territory Procedure");
  11.         //EC -- size of the vector is one.  Correct.
  12.         System.out.println("Territory Size: "+T.Territory.size());
  13.  
  14.         while (i<T.Territory.size())
  15.         {
  16.             // benign
  17.             System.out.print(i+" ");
  18.             System.out.println(T.Territory.get(i).TeamList.toString());
  19.             i++;
  20.         }
  21.     }
  22.  
  23.     public class TeamsAndSites
  24.     {
  25.         Vector<Site> Territory = new Vector<Site>();
  26.     }
  27.  
  28. // in public void BuildTerritory()
  29. {
  30.             TeamsAndSites Temp = new TeamsAndSites();
  31.             Initialize(Temp);
  32.             PrintTerritory(Temp);
  33.             int sitenumber = 1;
  34.             int team = 0;
  35.  
  36.             Vector<Integer> v = new Vector<Integer>();
  37.  
  38.             int startingsite = 1;
  39.             int num = 0;
  40.             Site a = new Site();
  41.  
  42.         while (localRS.next())
  43.         {
  44.             {
  45.                 team = localRS.getInt("team_id");
  46.                 sitenumber = localRS.getInt("site_id");
  47.  
  48.                 if (sitenumber != startingsite)
  49.                 {
  50.                     a.NumberOfTeams = (int)v.size();
  51.                     a.TeamList = v;
  52.                     //Temp.DeepCopy(v, sitenumber);
  53.                     //Temp.Territory.elementAt(sitenumber).TeamList = (Vector)v.clone();
  54.                     for (int i = 0; i<v.size(); i++)
  55.                     {
  56.  
  57.                         num = v.elementAt(i).intValue();
  58.                         System.out.print(i+" "+num+" ");
  59.  
  60.                         Temp.Territory.elementAt(sitenumber).TeamList.add(num);
  61.                         if (Temp.Territory.elementAt(sitenumber-1).TeamList.get(0)==0)
  62.                                 Temp.Territory.elementAt(sitenumber-1).TeamList.remove(0);
  63.                         System.out.print("\nTemp: "+Temp.Territory.elementAt(sitenumber-1).TeamList.get(i)+" "+"\n");
  64.                         System.out.print("Site Number: "+sitenumber+"\n");
  65.                     }
  66.                     //Temp.Territory.elementAt(sitenumber).TeamList = (Vector) copy(v);
  67.                     //System.out.println();
  68.  
  69.                     //PrintTerritory(Temp);
  70.                     //v.clear();
  71.                     startingsite++;
  72.                     a.TeamList.clear();
  73.                     a.NumberOfTeams = 0;
  74.                     v.add(team);
  75.                 }
  76.                 else
  77.                 {
  78.                     if (startingsite == 0)
  79.                     {
  80.                         ;
  81.                     }
  82.                     else
  83.                     {
  84.                         v.add(team);
  85.                     }
  86.                 }            
  87.             }    
  88.         }
  89.  
  90.         System.out.println("\n\n\nThis is Temp:\n");
  91.         PrintTerritory(Temp);
  92.  
/* The problem is that the TeamsAndSites object won't increment to the
element so it builds one long vector as opposed to 27 short vectors. I have been beating my head against a wall forever now so help please! */
Nov 14 '08 #1
2 1578
Dököll
2,364 Recognized Expert Top Contributor
Sorry you did not get an answer on this one, I am not skilled at these too much, I do mostly web stuff as of now.

Do stay tuned though, I may be able to find you a bit of code.

Also have you searched the whole forum on this, I would...

In a bit!

Here you go curtissumpter:

http://www.google.com/search?sourcei...r+Java+example
Nov 20 '08 #2
JosAH
11,448 Recognized Expert MVP
Your code doesn't compile: that first method is outside any class and none of
the Java compilers like that. Fix that first and then come back again if needed.

kind regards,

Jos
Nov 20 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
12354
by: Alex | last post by:
Entering the following in the Python shell yields >>> help(dict.copy) Help on method_descriptor: copy(...) D.copy() -> a shallow copy of D >>>
4
52312
by: fperfect13 | last post by:
Hi, I wanted to perform a deep copy of an array. Searching on google I ran into different opinions : C# Interview Questions (http://blogs.wwwcoder.com/tsvmadhav/archive/2005/04/08/2882.aspx) 10.What's the difference between the System.Array.CopyTo() and System.Array.Clone()?
2
10121
by: bonk | last post by:
I have come across the need to distinguish between the creation of a deep and a shallow copy and with great interest I have read this article: http://blogs.msdn.com/brada/archive/2004/05/03/125427.aspx This artivle seems to hint that I should not use System.IClonable but instead define my own interface(s) for cloning. Now since this article is rather old and since they did not obsolete IClonable there might be a new "best practise".
26
15817
by: saxenavaibhav17 | last post by:
what is Deep Copy, Shallow copy and Bitwise copy, Memberwise copy? and what is the difference between them? pls help vaibhav
22
15952
by: Steven Blair | last post by:
I need to perform a Deep Copy on an ArrayList. I wrote a small sample app to prove this could be done: ArrayList a = new ArrayList(); ArrayList b = new ArrayList(); a.Add("Hello"); b = (ArrayList) a.Clone();
4
3150
by: shuisheng | last post by:
Dear All, Is there any easy way to make sure all my object copies are deep copy or shallow copy? I do not like to implement it in each class one by one. Thanks, Shuisheng
7
2164
by: pallav | last post by:
I'm having some trouble with my copy constructor. I've tried using gdb to find the bug, but it seg faults in the destructor. I'm not able to see what I'm doing wrong. Since I'm using pointers, I need deep copy and I believe I'm doing that in my constructors. Can someone help me see what I'm missing out? Here is my code. typedef boost::shared_ptr<FactorFactorPtr; enum FactorTypeT
3
8754
by: raylopez99 | last post by:
The "C# Cookbook" (O'Reilly / Jay Hilyard), section 3.26, is on deep cloning versus shallow cloning. The scanned pages of this book are found here: http://www.sendspace.com/file/mjyocg (Word format, 3 pp) My question, coming from a C++ background where deep copying is done, is why in C# you would do either deep or shallow copying as suggested by O'Reilly (using the "ICloneable" inhereited interface), at least for the .NET framework. ...
3
3913
by: jacek.dziedzic | last post by:
Hello! Suppose I have a class base, with virtual methods and a virtual destructor and a bunch of classes, derived1, derived2, ... which publicly derive from base. I then have a pointer base* foo; which a complicated code allocates as one of derived's and sets up.
5
6632
by: jgscott | last post by:
I've been trawling around for an answer to this question and thought I'd try here. I have a class Graph, which has a std::list<Nodeas a class member. Node it itself a class that makes extensive use of pointers to represent various forms of data in the nodes of graphs, along with pointers to neighboring nodes. This necessitates a deep copy that iterators over the list. My copy constructor looks like: ...
0
10583
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10337
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10323
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10082
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9160
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6854
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5654
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2995
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.