Mercurial > hg > Members > shoshi > jungle > jungle-core
changeset 13:a46ff0114a9e
commit
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/ChangeSet.java Fri Dec 14 21:23:23 2012 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/ChangeSet.java Sat Dec 15 18:48:06 2012 +0900 @@ -1,8 +1,10 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Tree; + public interface ChangeSet { - public TraversableTree getTree(); + public Tree getTree(); public ChangeSet prev(); public String uuid();
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/TreeEditor.java Fri Dec 14 21:23:23 2012 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/TreeEditor.java Sat Dec 15 18:48:06 2012 +0900 @@ -1,19 +1,18 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store; import java.nio.ByteBuffer; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.NodeTransformer; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.NodeEditor; public interface TreeEditor { public TraversableTree getTree(); - public Result appendChildBehindOf(NodePath _path); - public Result appendChildInfrontOf(NodePath _path); + public Result appendChild(NodePath _path,int _pos); public Result deleteChild(NodePath _path); public Result putAttribute(NodePath _path,ByteBuffer _key,ByteBuffer _value); public Result deleteAttribute(NodePath _path,ByteBuffer _key,ByteBuffer _value); - public Result edit(NodePath _path,NodeTransformer _transformer); + public Result edit(NodePath _path,NodeEditor _transformer); public boolean success(); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultChangeSet.java Fri Dec 14 21:23:23 2012 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultChangeSet.java Sat Dec 15 18:48:06 2012 +0900 @@ -1,6 +1,7 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl; import fj.data.List; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Tree; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.ChangeSet; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.Command; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TraversableTree; @@ -12,9 +13,9 @@ private final long revision; private final List<Command> commands; - private final TraversableTree tree; + private final Tree tree; - public DefaultChangeSet(TraversableTree _tree,List<Command> _commands,String _uuid,long _revision,ChangeSet _prev) + public DefaultChangeSet(Tree _tree,List<Command> _commands,String _uuid,long _revision,ChangeSet _prev) { tree = _tree; commands = _commands; @@ -48,7 +49,7 @@ } @Override - public TraversableTree getTree() + public Tree getTree() { return tree; }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultChildren.java Fri Dec 14 21:23:23 2012 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultChildren.java Sat Dec 15 18:48:06 2012 +0900 @@ -7,33 +7,34 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Children; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Node; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.IterableWrapper; public class DefaultChildren implements Children { - private final List<Node> children; - private static final List<Node> EMPTY = List.nil(); + private final List<DefaultNode> children; + private static final List<DefaultNode> EMPTY = List.nil(); public DefaultChildren() { this(EMPTY); } - public DefaultChildren(List<Node> _children) + public DefaultChildren(List<DefaultNode> _children) { children = _children; } - public DefaultChildren add(Node _newNode) + public DefaultChildren add(DefaultNode _newNode) { return new DefaultChildren(children.snoc(_newNode)); } - public DefaultChildren insert(Node _newNode,int _pos) + public DefaultChildren insert(DefaultNode _newNode,int _pos) { check(_pos); - P2<List<Node>,List<Node>> split = children.splitAt(_pos); - List<Node> newChildren = split._1().snoc(_newNode).append(split._2()); + P2<List<DefaultNode>,List<DefaultNode>> split = children.splitAt(_pos); + List<DefaultNode> newChildren = split._1().snoc(_newNode).append(split._2()); return new DefaultChildren(newChildren); } @@ -42,8 +43,8 @@ { check(_pos); - P2<List<Node>,List<Node>> split = children.splitAt(_pos); - List<Node> newChildren = split._1().init().append(split._2()); + P2<List<DefaultNode>,List<DefaultNode>> split = children.splitAt(_pos); + List<DefaultNode> newChildren = split._1().init().append(split._2()); return new DefaultChildren(newChildren); } @@ -58,6 +59,6 @@ @Override public Iterator<Node> iterator() { - return null; + return (new IterableWrapper<Node>(children)).iterator(); } }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultNode.java Fri Dec 14 21:23:23 2012 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultNode.java Sat Dec 15 18:48:06 2012 +0900 @@ -6,13 +6,18 @@ public class DefaultNode implements Node { - public DefaultNode attrs; - public ChildrenImpl children; + public DefaultAttributes attrs; + public DefaultChildren children; public DefaultNode() { - attrs = new DefaultAttributes(); - children = new DefaultChildren(); + this(new DefaultChildren(),new DefaultAttributes()); + } + + public DefaultNode(DefaultChildren _children,DefaultAttributes _attrs) + { + attrs = _attrs; + children = _children; } @Override
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultTree.java Sat Dec 15 18:48:06 2012 +0900 @@ -0,0 +1,22 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Node; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Tree; + +public class DefaultTree implements Tree +{ + private final DefaultNode root; + + public static final DefaultTree EMPTY = new DefaultTree(); + + public DefaultTree() + { + root = new DefaultNode(); + } + + @Override + public Node getRoot() + { + return root; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultTreeEditor.java Sat Dec 15 18:48:06 2012 +0900 @@ -0,0 +1,68 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl; + +import java.nio.ByteBuffer; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.ChangeSet; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.Result; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TraversableTree; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TreeEditor; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.NodeTransformer; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultTraverser; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.TraverseResult; + +public class DefaultTreeEditor implements TreeEditor +{ + private final TreeRepository repo; + private final ChangeSet tip; + + public DefaultTreeEditor(TreeRepository _repo) + { + repo = _repo; + tip = _repo.getCurrentChangeSet(); + } + + @Override + public TraversableTree getTree() + { + return new DefaultTraversableTree(tip.getTree(),new DefaultTraverser()); + } + + @Override + public Result appendChild(NodePath _path,int _pos) + { + TraversableTree tree = getTree(); + Iterable<TraverseResult> result = tree.traverse(_path); + return null; + } + + + @Override + public Result deleteChild(NodePath _path) + { + return null; + } + + @Override + public Result putAttribute(NodePath _path, ByteBuffer _key,ByteBuffer _value) + { + return null; + } + + @Override + public Result deleteAttribute(NodePath _path, ByteBuffer _key,ByteBuffer _value) + { + return null; + } + + @Override + public boolean success() + { + return false; + } + + @Override + public Result edit(NodePath _path, NodeTransformer _transformer) + { + return null; + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultTreeStore.java Sat Dec 15 18:48:06 2012 +0900 @@ -0,0 +1,28 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TreeEditor; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TreeStore; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultTraverser; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.Traverser; + +public class DefaultTreeStore implements TreeStore +{ + public TreeRepository repository; + + public DefaultTreeStore() + { + repository = new TreeRepository(); + } + + @Override + public TreeEditor getCurrentTree() + { + return new DefaultTreeEditor(repository); + } + + @Override + public Traverser getTraverser() + { + return new DefaultTraverser(); + } +}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/ModifiedTreeEditorImpl.java Fri Dec 14 21:23:23 2012 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/ModifiedTreeEditorImpl.java Sat Dec 15 18:48:06 2012 +0900 @@ -4,6 +4,7 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Tree; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.Result; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TraversableTree; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TreeEditor; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.NodeTransformer; @@ -11,7 +12,7 @@ { @Override - public Tree getTree() + public TraversableTree getTree() { return null; }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/TreeEditorImpl.java Fri Dec 14 21:23:23 2012 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,71 +0,0 @@ -package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl; - -import java.nio.ByteBuffer; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Tree; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.ChangeSet; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.Result; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TraversableTree; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TreeEditor; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.NodeTransformer; - -public class TreeEditorImpl implements TreeEditor -{ - private final TreeRepository repo; - private final ChangeSet tip; - - public TreeEditorImpl(TreeRepository _repo) - { - repo = _repo; - tip = _repo.getCurrentChangeSet(); - } - - @Override - public TraversableTree getTree() - { - return tip.getTree(); - } - - @Override - public Result appendChildBehindOf(NodePath _path) - { - return null; - } - - @Override - public Result appendChildInfrontOf(NodePath _path) - { - return null; - } - - @Override - public Result deleteChild(NodePath _path) - { - return null; - } - - @Override - public Result putAttribute(NodePath _path, ByteBuffer _key,ByteBuffer _value) - { - return null; - } - - @Override - public Result deleteAttribute(NodePath _path, ByteBuffer _key,ByteBuffer _value) - { - return null; - } - - @Override - public boolean success() - { - return false; - } - - @Override - public Result edit(NodePath _path, NodeTransformer _transformer) - { - return null; - } - -}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/TreeRepository.java Fri Dec 14 21:23:23 2012 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/TreeRepository.java Sat Dec 15 18:48:06 2012 +0900 @@ -9,26 +9,24 @@ public class TreeRepository { - private final AtomicReference<ChangeSetImpl> changeSet; + private final AtomicReference<DefaultChangeSet> changeSet; - public TreeRepository(TraverserProvider _provider) + public TreeRepository() { List<Command> emptyCommands = List.nil(); - TraversableTreeImpl ttree = new TraversableTreeImpl(_provider); - - changeSet = new AtomicReference<ChangeSetImpl>( - new ChangeSetImpl(TreeImpl.EMPTY,emptyCommands, + changeSet = new AtomicReference<DefaultChangeSet>( + new DefaultChangeSet(DefaultTree.EMPTY,emptyCommands, Constants.DEFAULT_OWNER,Constants.DEFAULT_REVISION_START_NUMBER,null) ); } - public ChangeSetImpl getCurrentChangeSet() + public DefaultChangeSet getCurrentChangeSet() { return changeSet.get(); } - public boolean commitChangeSet(ChangeSetImpl _newChangeSet,ChangeSetImpl _currentChangeSet) + public boolean commitChangeSet(DefaultChangeSet _newChangeSet,DefaultChangeSet _currentChangeSet) { return changeSet.compareAndSet(_currentChangeSet,_newChangeSet); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/TreeStoreImpl.java Fri Dec 14 21:23:23 2012 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl; - -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TreeEditor; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TreeStore; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultTraverser; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.Traverser; - -public class TreeStoreImpl implements TreeStore -{ - public TreeRepository repository; - - public TreeStoreImpl() - { - repository = new TreeRepository(); - } - - @Override - public TreeEditor getCurrentTree() - { - return new TreeEditorImpl(repository); - } - - @Override - public Traverser getTraverser() - { - return new DefaultTraverser(); - } -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/trasnformer/DefaultNodeEditResult.java Sat Dec 15 18:48:06 2012 +0900 @@ -0,0 +1,25 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer; + +public class DefaultNodeEditResult implements NodeEditResult +{ + private final NodeEditResultStatus status; + private final EditableNode node; + + public DefaultNodeEditResult(NodeEditResultStatus _status,EditableNode _node) + { + status = _status; + node = _node; + } + + @Override + public EditableNode getEditableNode() + { + return node; + } + + @Override + public NodeEditResultStatus getStatus() + { + return status; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/trasnformer/DeleteAttribute.java Sat Dec 15 18:48:06 2012 +0900 @@ -0,0 +1,12 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer; + +public class DeleteAttribute implements NodeEditor +{ + + @Override + public Transformation transform(EditableNode _e) + { + return null; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/trasnformer/NodeEditResult.java Sat Dec 15 18:48:06 2012 +0900 @@ -0,0 +1,7 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer; + +public interface NodeEditResult +{ + EditableNode getEditableNode(); + NodeEditResultStatus getStatus(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/trasnformer/NodeEditResultStatus.java Sat Dec 15 18:48:06 2012 +0900 @@ -0,0 +1,6 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer; + +public enum NodeEditResultStatus +{ + SUCCESS,FAIL; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/trasnformer/NodeEditor.java Sat Dec 15 18:48:06 2012 +0900 @@ -0,0 +1,6 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer; + +public interface NodeEditor +{ + public NodeEditResult edit(EditableNode _e); +}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/trasnformer/NodeTransformer.java Fri Dec 14 21:23:23 2012 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer; - -public interface NodeTransformer -{ - public Transformation transform(EditableNode _e); -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/trasnformer/SetAttribute.java Sat Dec 15 18:48:06 2012 +0900 @@ -0,0 +1,22 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer; + +import java.nio.ByteBuffer; + +public class SetAttribute implements NodeEditor +{ + private final String key; + private final ByteBuffer value; + + public SetAttribute(String _key,ByteBuffer _value) + { + key = _key; + value = _value; + } + + @Override + public Transformation transform(EditableNode _e) + { + EditableAttributes attrs = _e.getAttributes(); + return new DefaultTransformation(Transformation.Result.SUCCESS,attrs.put(key,value)); + } +}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/trasnformer/TransformResult.java Fri Dec 14 21:23:23 2012 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer; - -public enum TransformResult -{ - SUCCESS,FAIL; -}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/trasnformer/Transformation.java Fri Dec 14 21:23:23 2012 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,7 +0,0 @@ -package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer; - -public interface Transformation -{ - EditableNode getEditableNode(); - TransformResult getResult(); -}