473,403 Members | 2,366 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Real Problem with Deep Copy

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 1543
Dököll
2,364 Expert 2GB
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 Expert 8TB
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
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
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)...
2
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: ...
26
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
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 =...
4
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
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...
3
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...
3
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*...
5
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.