Mercurial > hg > Members > shoshi > TreeCMSv1
view src/treecms/proto/test/SimpleEditorTest1.java @ 30:8d733b98c5de
added Node API
setLinkedNode,getLinkedNode for create link to other node.
but not implemented yet.
author | Shoshi TAMAKI |
---|---|
date | Wed, 10 Nov 2010 00:36:51 +0900 |
parents | 64359341c04a |
children |
line wrap: on
line source
/** * SimpleEditorTest1 * * testClone * test monotonic-tree modification */ package treecms.proto.test; import org.junit.Test; import java.util.concurrent.atomic.AtomicReference; import org.junit.runner.JUnitCore; import treecms.proto.api.*; import treecms.proto.simple.*; public class SimpleEditorTest1 { public static void main(String _args[]) { JUnitCore.main(SimpleEditorTest1.class.getName()); } private AtomicReference<Node> m_root; private Node m_target1; private Node m_target2; public SimpleEditorTest1() { //create tree Node root = new SimpleNode(); root.setTitle("root"); Node child1 = root.addChild(new SimpleNode()); child1.setTitle("child1"); Node child2 = root.addChild(new SimpleNode()); child2.setTitle("child2"); Node child11 = child1.addChild(new SimpleNode()); child11.setTitle("child11"); Node child12 = child1.addChild(new SimpleNode()); child12.setTitle("child12"); //AtomicReference<T> to use CompareAndSet m_root = new AtomicReference<Node>(root); m_target1 = child2; m_target2 = child11; } @Test public void testClone() { SimpleEditor editor = new SimpleEditor(m_root); Node node = editor.edit(m_target1); node.setTitle("*"+node.getTitle()); System.out.println("-----------------------------------------------"); print(editor.getUncommited(),0); node = editor.edit(m_target2); node.setTitle("*"+node.getTitle()); System.out.println("-----------------------------------------------"); print(editor.getUncommited(),0); } private void print(Node _root,int _indent) { for(int i = 0;i < _indent;i ++){ System.out.print("\t"); } System.out.println(_root.getTitle()+"["+_root.getID()+"]"); for(Node child : _root.getChildren()){ print(child,_indent+1); } } }