Mercurial > hg > Members > shoshi > jungle > jungle-core
changeset 9:bb96e631f022
added HyperTree
author | shoshi <shoshi@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 06 Jul 2012 21:43:45 +0900 |
parents | abed5bd92fcb |
children | a2c019a77c27 |
files | src/main/java/jungle/core/graph/simple/SimpleVertexContext.java src/main/java/jungle/impl/SimpleTree.java src/main/java/jungle/kernel/hypertree/Edge.java src/main/java/jungle/kernel/hypertree/HyperTree.java src/main/java/jungle/kernel/hypertree/Node.java src/main/java/jungle/kernel/hypertree/db/HyperTreeDatabaseService.java src/main/java/jungle/util/Triple.java |
diffstat | 7 files changed, 154 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jungle/core/graph/simple/SimpleVertexContext.java Fri Jul 06 21:43:45 2012 +0900 @@ -0,0 +1,64 @@ +package jungle.core.graph.simple; + +import java.util.concurrent.atomic.AtomicReference; + +import fj.Ord; +import fj.data.List; +import fj.data.TreeMap; + +public class SimpleVertexContext +{ + private final AtomicReference<TreeMap<String,String>> propertiesHolder; + private final AtomicReference<TreeMap<String,List<SimpleVertex>>> relationsHolder; + + private static final TreeMap<String,String> NIL_PROPERTIES = TreeMap.empty(Ord.stringOrd); + private static final TreeMap<String,List<SimpleVertex>> NIL_RELATIONS = TreeMap.empty(Ord.stringOrd); + + public SimpleVertexContext() + { + this(NIL_PROPERTIES,NIL_RELATIONS); + } + + public SimpleVertexContext(TreeMap<String,String> _properties,TreeMap<String,List<SimpleVertex>> _relations) + { + if(_properties == null || _relations == null){ + throw new NullPointerException("_properties and _relations must not be null."); + } + + propertiesHolder = new AtomicReference<TreeMap<String,String>>(_properties); + relationsHolder = new AtomicReference<TreeMap<String,List<SimpleVertex>>>(_relations); + } + + public TreeMap<String,String> getProperties() + { + return propertiesHolder.get(); + } + + public boolean compareAndSwapProperties(TreeMap<String,String> _expect,TreeMap<String,String> _update) + { + return propertiesHolder.compareAndSet(_expect,_update); + } + + public TreeMap<String,List<SimpleVertex>> getRelations() + { + return relationsHolder.get(); + } + + public boolean compareAndSwapRelations(TreeMap<String,List<SimpleVertex>> _expect, + TreeMap<String,List<SimpleVertex>> _update) + { + return relationsHolder.compareAndSet(_expect,_update); + } + + public SimpleVertexContext snapshot() + { + TreeMap<String,String> propertiesSnapshot = propertiesHolder.get(); + TreeMap<String,List<SimpleVertex>> relationsSnapshot = null; + + do{ + relationsSnapshot = relationsHolder.get(); + }while(!(propertiesHolder.get() == propertiesSnapshot)); + + return new SimpleVertexContext(propertiesSnapshot,relationsSnapshot); + } +}
--- a/src/main/java/jungle/impl/SimpleTree.java Tue Jul 03 18:59:28 2012 +0900 +++ b/src/main/java/jungle/impl/SimpleTree.java Fri Jul 06 21:43:45 2012 +0900 @@ -10,7 +10,7 @@ public class SimpleTree implements Tree { - private final SimpleTreeGroup group; + private final HyperTree group; private final Graph graph; private final Vertex vertex;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jungle/kernel/hypertree/Edge.java Fri Jul 06 21:43:45 2012 +0900 @@ -0,0 +1,13 @@ +package jungle.kernel.hypertree; + +import jungle.util.Pair; +import jungle.util.Triple; + +public interface Edge +{ + Node getNodeAt(int _index); + Triple<HyperTree,Edge,Node> createAnonymousNode(Pair<String,String>... _keyValues); + Triple<HyperTree,Edge,Node> createNode(String _id,Pair<String,String>... _keyValues); + Pair<HyperTree,Edge> removeNode(Node _node); + Triple<HyperTree,Edge,Node> insertAnonymouseNodeAt(int _index); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jungle/kernel/hypertree/HyperTree.java Fri Jul 06 21:43:45 2012 +0900 @@ -0,0 +1,7 @@ +package jungle.kernel.hypertree; + +public interface HyperTree +{ + public Node find(String _id); + public Node rootNode(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jungle/kernel/hypertree/Node.java Fri Jul 06 21:43:45 2012 +0900 @@ -0,0 +1,13 @@ +package jungle.kernel.hypertree; + +import jungle.util.Pair; +import jungle.util.Triple; + +public interface Node +{ + String getProperty(String _key); + Pair<HyperTree,Node> setProperties(Pair<String,String>... _keyValues); + Triple<HyperTree,Node,Edge> createEdge(String... _edgeNames); + Edge getEdge(String _edgeName); + Pair<HyperTree,Node> removeEdge(String... _edgeNames); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jungle/kernel/hypertree/db/HyperTreeDatabaseService.java Fri Jul 06 21:43:45 2012 +0900 @@ -0,0 +1,11 @@ +package jungle.kernel.hypertree.db; + +import jungle.kernel.hypertree.HyperTree; + +public interface HyperTreeDatabaseService +{ + public HyperTree createHyperTree(String _id); + public HyperTree getHyperTree(String _id); + public void removeHyperTree(String _id); + public String askID(HyperTree _tree); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jungle/util/Triple.java Fri Jul 06 21:43:45 2012 +0900 @@ -0,0 +1,45 @@ +package jungle.util; + +public class Triple<A,B,C> +{ + private A a; + private B b; + private C c; + + public Triple(A _a,B _b,C _c) + { + a = _a; + b = _b; + c = _c; + } + + public A getA() + { + return a; + } + + public B getB() + { + return b; + } + + public C getC() + { + return c; + } + + public void setA(A _a) + { + a = _a; + } + + public void setB(B _b) + { + b = _b; + } + + public void setC(C _c) + { + c = _c; + } +}