Ok so i need to be able to clone objects with two arraylists of the same object. Thus when i try and clone recursion occurs. I need to clone the objects because I have to be able to have a list divided up into tabs and have it ordered into elements depending on the tabs. Here is my class without a clone method. Please help!
import java.util.*;
im
public class Element
{
private String text;
private Element parent;
private ArrayList<Element> children;
private ArrayList<Element> syblings;
public Element(String text, Element parent, ArrayList<Element> children, ArrayList<Element> syblings)
{
this.text = text;
this.parent = parent;
this.children = children;
this.syblings = syblings;
}
public String getText()
{
return this.text;
}
public void setText(String text)
{
this.text = text;
}
public Element getParent()
{
return this.parent;
}
public void addChild(Element child)
{
this.children.add(child);
System.out.println("ello");
}
public ArrayList<Element> getChildren()
{
return this.children;
}
public Element getChild(int i)
{
return this.children.get(i);
}
public ArrayList<Element> getSyblings()
{
return this.syblings;
}
public Element getSybling(int i)
{
return this.syblings.get(i);
}
public void addSybling(Element sybling)
{
if (sybling == this) return;
boolean exists = false;
for (int i = 0; i < this.syblings.size(); i++)
{
if (this.syblings.get(i) == sybling)
{
exists = true;
break;
}
}
if (!exists) this.syblings.add(sybling);
}
public void setParent(Element parent)
{
this.parent = parent;
this.parent.addChild(this);
}
}