How to track changes to an object graph?
<p>I am working on some code that I want to detect when something in the object has changed.  One of the easiest ways to track changes is to keep an old copy of the object around.  However, it looks like getting a copy of the deep graph may be difficult.  Here's what I tried:</p>

<pre>
<code>
public class Old{
    protected Old old;
    protected List stuff;

    //Needed for JUnit
    public Old(){
    }

    public Old(List stuff){
        this.stuff=stuff;
        old=this;
    }

    public void add(){
        stuff.add(2);
    }

    public void match(){
        System.out.printf("old:%d\nnew:%d\n",old.getStuff().size(),stuff.size());
    }

    public List getStuff(){
        return new ArrayList(stuff);
    }

    @Test
    public void testOld(){
        List list=new ArrayList();
        list.add(1);
        Old thing=new Old(list);
        thing.add();
        thing.match();
    }
}
</code>
</pre>

<p>The Output:</p>

<pre>
old:2
new:2
</pre>

<p>So, it appears that by default <code>old=this</code> does not create a deep copy.  All I really want is to track changes to that list and potentially a graph of objects.  What are some other simple options?</p>
