Mercurial > hg > Members > shoshi > TreeCMS > TreeCMSPrototype1
changeset 14:ce6e4523b284
hogehoge
author | shoshi |
---|---|
date | Sun, 29 Aug 2010 20:46:21 +0900 |
parents | 3bccd745f2e2 |
children | 6b8f33b7e09f |
files | src/treecms/proto/edit/EditableNodeAPITreeBuilder.java src/treecms/proto/test/SearchPathRootToChildTest.java |
diffstat | 2 files changed, 96 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/treecms/proto/edit/EditableNodeAPITreeBuilder.java Sun Aug 29 12:07:03 2010 +0900 +++ b/src/treecms/proto/edit/EditableNodeAPITreeBuilder.java Sun Aug 29 20:46:21 2010 +0900 @@ -1,18 +1,42 @@ package treecms.proto.edit; +import java.util.LinkedList; import java.util.List; import java.util.UUID; import treecms.proto.api.NodeAPI; import treecms.proto.api.NodeAPITreeBuilder; +import treecms.proto.test.PreOrderTreeWalkerRecursive; public class EditableNodeAPITreeBuilder implements NodeAPITreeBuilder { private NodeAPITreeBuilder m_builder; + private NodeAPI m_newRoot; + private NodeAPI m_oldRoot; - public EditableNodeAPITreeBuilder(NodeAPITreeBuilder _builder) + public EditableNodeAPITreeBuilder(NodeAPI _target,NodeAPITreeBuilder _builder) { m_builder = _builder; + m_newRoot = m_builder.createNode(); + + //search path + m_oldRoot = _builder.getContents(); + Iterable<NodeAPI> itr = new PreOrderTreeWalkerRecursive(m_oldRoot); + + LinkedList<NodeAPI> reverse = new LinkedList<NodeAPI>(); + for(NodeAPI child : itr){ + reverse.addFirst(child); + } + + LinkedList<NodeAPI> path = new LinkedList<NodeAPI>(); + NodeAPI target = _target; + for(NodeAPI node : reverse){ + if(node.isChild(target)){ + path.addFirst(target); + target = node; + } + } + } @Override
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/treecms/proto/test/SearchPathRootToChildTest.java Sun Aug 29 20:46:21 2010 +0900 @@ -0,0 +1,71 @@ +package treecms.proto.test; + +import java.util.Iterator; +import java.util.LinkedList; + +import treecms.proto.api.*; +import treecms.proto.simple.*; + +public class SearchPathRootToChildTest +{ + public static void main(String _arg[]) + { + NodeAPITreeBuilder builder = new SimpleNodeAPITreeBuilder(); + NodeAPI root = builder.getContents(); + root.setTitle("root"); + + NodeAPI child1 = builder.createNode(); + child1.setTitle("+-child1"); + NodeAPI child2 = builder.createNode(); + child2.setTitle("+-child2"); + + root.addChild(child1); + root.addChild(child2); + + NodeAPI child11 = builder.createNode(); + child11.setTitle(" +-child11"); + NodeAPI child12 = builder.createNode(); + child12.setTitle(" +-child12"); + NodeAPI child13 = builder.createNode(); + child13.setTitle(" +-child13"); + + child1.addChild(child11); + child1.addChild(child12); + child1.addChild(child13); + + NodeAPI child21 = builder.createNode(); + child21.setTitle(" +-child21"); + + child2.addChild(child21); + + NodeAPI child211 = builder.createNode(); + child211.setTitle(" +-child211"); + NodeAPI child212 = builder.createNode(); + child212.setTitle(" +-child212"); + + child21.addChild(child211); + child21.addChild(child212); + + + PreOrderTreeWalkerRecursive walker = new PreOrderTreeWalkerRecursive(root); + Iterator<NodeAPI> itr = walker.iterator(); + + LinkedList<NodeAPI> reverse = new LinkedList<NodeAPI>(); + while(itr.hasNext()){ + reverse.addFirst(itr.next()); + } + + NodeAPI target = child212; + LinkedList<NodeAPI> path = new LinkedList<NodeAPI>(); + for(NodeAPI node : reverse){ + if(node.isChild(target)){ + path.addFirst(target); + target = node; + } + } + + for(NodeAPI node : path){ + System.out.println(node.getTitle()); + } + } +}