Mercurial > hg > Members > shoshi > TreeCMSv1
changeset 0:f815c7c1fb38
hg init
author | shoshi |
---|---|
date | Fri, 27 Aug 2010 15:26:20 +0900 |
parents | |
children | 9d7863f367bb |
files | .classpath .project .settings/org.eclipse.jdt.core.prefs src/treecms/proto/api/BrowseAPI.java src/treecms/proto/api/EditAPI.java src/treecms/proto/api/NodeAPI.java src/treecms/proto/api/NodeAPITreeBuilder.java src/treecms/proto/simple/SimpleNodeAPI.java src/treecms/proto/simple/SimpleNodeAPITreeBuilder.java src/treecms/proto/test/PreOrderTreeWalker.java src/treecms/proto/test/Test1.java src/treecms/proto/test/Test2.java |
diffstat | 12 files changed, 317 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.classpath Fri Aug 27 15:26:20 2010 +0900 @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> + <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> + <classpathentry kind="output" path="bin"/> +</classpath>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.project Fri Aug 27 15:26:20 2010 +0900 @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>TreeCMSPrototype1</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.settings/org.eclipse.jdt.core.prefs Fri Aug 27 15:26:20 2010 +0900 @@ -0,0 +1,12 @@ +#Thu Aug 26 16:39:12 JST 2010 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/treecms/proto/api/BrowseAPI.java Fri Aug 27 15:26:20 2010 +0900 @@ -0,0 +1,6 @@ +package treecms.proto.api; + +public interface BrowseAPI +{ + NodeAPI useContents(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/treecms/proto/api/EditAPI.java Fri Aug 27 15:26:20 2010 +0900 @@ -0,0 +1,7 @@ +package treecms.proto.api; + +public interface EditAPI extends BrowseAPI +{ + void login(String user,String pass); + void logout(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/treecms/proto/api/NodeAPI.java Fri Aug 27 15:26:20 2010 +0900 @@ -0,0 +1,23 @@ +package treecms.proto.api; + +import java.util.Iterator; + +import java.util.List; + +public interface NodeAPI extends Iterable<NodeAPI> +{ + Iterator<NodeAPI> iterator(); + List<NodeAPI> getChildList(); + boolean isChild(NodeAPI _child); + + NodeAPI addChild(); + void removeChild(NodeAPI _child); + + void up(NodeAPI _child); + void down(NodeAPI _child); + + void setClassName(String _class); + void setTitle(String _title); + String getClassName(); + String getTitle(); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/treecms/proto/api/NodeAPITreeBuilder.java Fri Aug 27 15:26:20 2010 +0900 @@ -0,0 +1,6 @@ +package treecms.proto.api; + +public interface NodeAPITreeBuilder +{ + NodeAPI getContents(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/treecms/proto/simple/SimpleNodeAPI.java Fri Aug 27 15:26:20 2010 +0900 @@ -0,0 +1,98 @@ +package treecms.proto.simple; + +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +import treecms.proto.api.NodeAPI; + +class SimpleNodeAPI implements NodeAPI +{ + private LinkedList<NodeAPI> m_childs; + + private String m_class; + private String m_title; + + public SimpleNodeAPI() + { + m_childs = new LinkedList<NodeAPI>(); + m_class = ""; + m_title = ""; + } + + @Override + public List<NodeAPI> getChildList() + { + // TODO Auto-generated method stub + return m_childs; + } + + @Override + public boolean isChild(NodeAPI _child) { + // TODO Auto-generated method stub + return m_childs.contains(_child); + } + + @Override + public NodeAPI addChild() { + // TODO Auto-generated method stub + NodeAPI newChild = new SimpleNodeAPI(); + m_childs.add(newChild); + return newChild; + } + + @Override + public void removeChild(NodeAPI _child) { + // TODO Auto-generated method stub + m_childs.remove(_child); + } + + @Override + public void up(NodeAPI _child) { + // TODO Auto-generated method stub + int curPos = m_childs.indexOf(_child); + if(curPos - 1 > 0){ + m_childs.add(curPos - 1,m_childs.remove(curPos)); + } + } + + @Override + public void down(NodeAPI _child) { + // TODO Auto-generated method stub + int curPos = m_childs.indexOf(_child); + if(curPos + 1 < m_childs.size()){ + m_childs.add(curPos + 1,m_childs.remove(curPos)); + } + } + + @Override + public void setClassName(String _class) { + // TODO Auto-generated method stub + this.m_class = _class; + } + + @Override + public void setTitle(String _title) { + // TODO Auto-generated method stub + this.m_title = _title; + } + + @Override + public String getClassName() { + // TODO Auto-generated method stub + return this.m_class; + } + + @Override + public String getTitle() { + // TODO Auto-generated method stub + return this.m_title; + } + + @Override + public Iterator<NodeAPI> iterator() { + // TODO Auto-generated method stub + return m_childs.iterator(); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/treecms/proto/simple/SimpleNodeAPITreeBuilder.java Fri Aug 27 15:26:20 2010 +0900 @@ -0,0 +1,15 @@ +package treecms.proto.simple; + +import treecms.proto.api.*; + +public class SimpleNodeAPITreeBuilder implements NodeAPITreeBuilder +{ + public SimpleNodeAPITreeBuilder() + { + return; + } + public NodeAPI getContents() + { + return new SimpleNodeAPI(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/treecms/proto/test/PreOrderTreeWalker.java Fri Aug 27 15:26:20 2010 +0900 @@ -0,0 +1,75 @@ +package treecms.proto.test; + +import java.util.Iterator; +import java.util.LinkedList; + +import treecms.proto.api.NodeAPI; + +public class PreOrderTreeWalker implements Iterator<NodeAPI> , Iterable<NodeAPI> +{ + private NodeAPI m_root; + private LinkedList<Iterator<NodeAPI>> m_childs; + + private int m_pos; + public PreOrderTreeWalker(NodeAPI _root) + { + m_root = _root; + m_childs = new LinkedList<Iterator<NodeAPI>>(); + + for(NodeAPI child : _root.getChildList()){ + m_childs.add((new PreOrderTreeWalker(child)).iterator()); + } + + m_pos = -2; + } + + @Override + public Iterator<NodeAPI> iterator() { + // TODO Auto-generated method stub + return this; + } + + @Override + public boolean hasNext() { + // TODO Auto-generated method stub + int next = m_pos + 1; + + if(next < 0){ + return true; + } + + for(;next < m_childs.size();next ++){ + System.out.println(m_pos); + if(m_childs.get(next).hasNext()){ + return true; + } + } + + return false; + } + + @Override + public NodeAPI next() { + // TODO Auto-generated method stub + m_pos++; + + if(m_pos < 0){ + return this.m_root; + } + + for(;m_pos < m_childs.size();m_pos ++){ + NodeAPI nextNode = m_childs.get(m_pos).next(); + if(nextNode != null){ + return nextNode; + } + } + + return null; + } + + @Override + public void remove() { + // TODO Auto-generated method stub + + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/treecms/proto/test/Test1.java Fri Aug 27 15:26:20 2010 +0900 @@ -0,0 +1,44 @@ +package treecms.proto.test; + +import java.util.Iterator; + +import treecms.proto.api.*; +import treecms.proto.simple.*; + +public class Test1 +{ + public static void main(String _arg[]) + { + NodeAPI root = (new SimpleNodeAPITreeBuilder()).getContents(); + root.setTitle("root"); + + NodeAPI child1 = root.addChild(); + child1.setTitle("child1"); + NodeAPI child2 = root.addChild(); + child2.setTitle("child2"); + + NodeAPI child11 = child1.addChild(); + child11.setTitle("child11"); + NodeAPI child12 = child1.addChild(); + child12.setTitle("child12"); + NodeAPI child13 = child1.addChild(); + child13.setTitle("child13"); + + NodeAPI child21 = child2.addChild(); + child21.setTitle("child21"); + + NodeAPI child211 = child21.addChild(); + child211.setTitle("child211"); + NodeAPI child212 = child21.addChild(); + child212.setTitle("child212"); + + + PreOrderTreeWalker walker = new PreOrderTreeWalker(root); + Iterator<NodeAPI> itr = walker.iterator(); + while(itr.hasNext()){ + NodeAPI node = itr.next(); + System.out.println(node.getTitle()); + } + + } +}