Mercurial > hg > Members > tatsuki > bench > jungle-core
changeset 1:b1fa4c494416
added tests , etc..
author | shoshi <shoshi@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 11 Jun 2012 23:45:38 +0900 |
parents | 113050de7f69 |
children | cc30c2773c09 |
files | memo.txt src/main/java/jungle/core/Jungle.java src/main/java/jungle/core/Tree.java src/main/java/jungle/impl/SimpleEditor.java src/main/java/jungle/impl/SimpleJungle.java src/main/java/jungle/impl/SimpleLinks.java src/main/java/jungle/impl/SimpleTree.java src/main/java/jungle/impl/SimpleTreeGroup.java src/main/java/jungle/parsist/NodeProvider.java src/main/java/jungle/util/Pair.java src/test/java/jungle/util/PairTest.java |
diffstat | 11 files changed, 140 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/memo.txt Mon Jun 11 23:45:38 2012 +0900 @@ -0,0 +1,15 @@ +2012/06/11 + ・誰が Editor を提供する API を保持するべきか? + ・Editor の役割 + ・commit したら必要な Node を NodeProvider に push する。 + ・ということは, 内部に NodeProvider への参照を保持してないといけない? NodeProvider へのリンクを保持しているのは Jungle である。 + ・Jungle が NodeProvider を持っているのは正しいのか? TreeGroup でもいいのではないか? + ・commit したら TreeGroup の情報は破壊される。つまり? commit は TreeGroup に対して行われる。 + ・TreeGroup のメソッドで Tree を渡して Editor を作成するが良いか? + ・tree を編集する + ・Editor は TreeGroup が保持するとする。ならば、NodeProvider はどうするか? + ・NodeFactory (?) をつくる? NodeProvider と何が違うのか? + ・NodeProvider は、Tree/TreeNode/Link を作成する。 + ・NodeProvider で、createTreeGroup , createTree , createTreeNode , createLink を依頼する + ・初期では、パスの検索は深さ優先探索で行う + ・TreeGroupについて、TreeGroupは最初に初期Treeを1つ作らなければならない? \ No newline at end of file
--- a/src/main/java/jungle/core/Jungle.java Mon Jun 11 20:10:00 2012 +0900 +++ b/src/main/java/jungle/core/Jungle.java Mon Jun 11 23:45:38 2012 +0900 @@ -4,5 +4,4 @@ { TreeGroup createTreeGroup(); Iterable<TreeGroup> treeGroups(); - Editor newEditor(Tree _t); }
--- a/src/main/java/jungle/core/Tree.java Mon Jun 11 20:10:00 2012 +0900 +++ b/src/main/java/jungle/core/Tree.java Mon Jun 11 23:45:38 2012 +0900 @@ -2,7 +2,6 @@ public interface Tree extends TreeNode { - Editor newEditor(); TreeGroup getGroup(); String treeID(); }
--- a/src/main/java/jungle/impl/SimpleEditor.java Mon Jun 11 20:10:00 2012 +0900 +++ b/src/main/java/jungle/impl/SimpleEditor.java Mon Jun 11 23:45:38 2012 +0900 @@ -1,17 +1,30 @@ package jungle.impl; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicReference; + import jungle.core.Editor; + import jungle.core.Link; import jungle.core.Tree; +import jungle.core.TreeGroup; import jungle.core.TreeNode; +import jungle.core.Node; +import jungle.util.Pair; public class SimpleEditor implements Editor { + private final ConcurrentHashMap<String,Node> changeset; + private final TreeGroup group; private final Tree tree; + private final AtomicReference<Tree> current; - public SimpleEditor(Tree _tree) + public SimpleEditor(TreeGroup _group,Tree _tree) { tree = _tree; + group = _group; + changeset = new ConcurrentHashMap<String,Node>(); + current = new AtomicReference<Tree>(); } public Tree commit() @@ -26,6 +39,8 @@ public Link createLinkAt(TreeNode _target, Tree _linkTarget) { + String cid = _target.cid(); + return null; } @@ -52,5 +67,4 @@ { return null; } - }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jungle/impl/SimpleJungle.java Mon Jun 11 23:45:38 2012 +0900 @@ -0,0 +1,31 @@ +package jungle.impl; + +import java.util.Collections; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; + +import jungle.core.Jungle; +import jungle.core.TreeGroup; + +public class SimpleJungle implements Jungle +{ + private final ConcurrentHashMap<String,TreeGroup> treeGroups; + + public SimpleJungle() + { + treeGroups = new ConcurrentHashMap<String,TreeGroup>(); + } + + public TreeGroup createTreeGroup() + { + String tid = UUID.randomUUID().toString(); + SimpleTreeGroup g = new SimpleTreeGroup(tid); + treeGroups.put(tid,g); + return g; + } + + public Iterable<TreeGroup> treeGroups() + { + return Collections.unmodifiableCollection(treeGroups.values()); + } +}
--- a/src/main/java/jungle/impl/SimpleLinks.java Mon Jun 11 20:10:00 2012 +0900 +++ b/src/main/java/jungle/impl/SimpleLinks.java Mon Jun 11 23:45:38 2012 +0900 @@ -43,4 +43,9 @@ return set.getAt(_pos); } + @Override + public String toString() + { + return set.toString(); + } }
--- a/src/main/java/jungle/impl/SimpleTree.java Mon Jun 11 20:10:00 2012 +0900 +++ b/src/main/java/jungle/impl/SimpleTree.java Mon Jun 11 23:45:38 2012 +0900 @@ -39,11 +39,6 @@ return attrs.get(_key); } - public Editor newEditor() - { - return new SimpleEditor(this); - } - public String treeID() { return tid;
--- a/src/main/java/jungle/impl/SimpleTreeGroup.java Mon Jun 11 20:10:00 2012 +0900 +++ b/src/main/java/jungle/impl/SimpleTreeGroup.java Mon Jun 11 23:45:38 2012 +0900 @@ -1,5 +1,6 @@ package jungle.impl; +import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicReference; import jungle.core.Editor; @@ -10,11 +11,13 @@ { private String id; private AtomicReference<Tree> latestTree; + private AtomicLong revisionCounter; public SimpleTreeGroup(String _id) { latestTree = new AtomicReference<Tree>(); id = _id; + revisionCounter = new AtomicLong(); } public String getID() @@ -26,4 +29,21 @@ { return latestTree.get(); } + + public String newTreeID() + { + return Long.toHexString(revisionCounter.incrementAndGet()); + } + + public Editor newEditor(Tree _t) + { + TreeGroup tg = _t.getGroup(); + + if(tg != this){ + return null; + } + + SimpleEditor editor = new SimpleEditor(this,_t); + return editor; + } }
--- a/src/main/java/jungle/parsist/NodeProvider.java Mon Jun 11 20:10:00 2012 +0900 +++ b/src/main/java/jungle/parsist/NodeProvider.java Mon Jun 11 23:45:38 2012 +0900 @@ -1,11 +1,5 @@ package jungle.parsist; -import jungle.core.Node; - public interface NodeProvider { - public void onInitialize(); - public void onCreateNode(Node _n); - public void onUpdateNode(Node _n); - public void onRemoveNode(Node _n); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jungle/util/Pair.java Mon Jun 11 23:45:38 2012 +0900 @@ -0,0 +1,23 @@ +package jungle.util; + +public class Pair<L,R> +{ + private L left; + private R right; + + public Pair(L _left,R _right) + { + left = _left; + right = _right; + } + + public L left() + { + return left; + } + + public R right() + { + return right; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jungle/util/PairTest.java Mon Jun 11 23:45:38 2012 +0900 @@ -0,0 +1,30 @@ +package jungle.util; + +import junit.framework.Assert; +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +public class PairTest extends TestCase +{ + public PairTest(String _testName) + { + super(_testName); + } + + public static Test suite() + { + return new TestSuite(PairTest.class); + } + + public void testPair() + { + Object left = new Object(); + Object right = new Object(); + + Pair<Object,Object> p = new Pair<Object,Object>(left,right); + + Assert.assertEquals(left,p.left()); + Assert.assertEquals(right,p.right()); + } +}