# HG changeset patch # User Shoshi TAMAKI # Date 1359208352 -32400 # Node ID 35e327577b5827d5f0b7b33d0ce200cd9814732e # Parent 3dfa0be90a0d95f6481fbdb75b5fd0e3dfe1bf4a added transaction diff -r 3dfa0be90a0d -r 35e327577b58 src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/Jungle.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/Jungle.java Sat Jan 26 22:52:32 2013 +0900 @@ -0,0 +1,7 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle; + +public interface Jungle +{ + public JungleTree getTreeByName(String _name); + public JungleTree createNewTree(String _name); +} diff -r 3dfa0be90a0d -r 35e327577b58 src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/JungleTree.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/JungleTree.java Sat Jan 26 22:52:32 2013 +0900 @@ -0,0 +1,9 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Node; + +public interface JungleTree +{ + public JungleTreeEditor getTreeEditor(); + public Node getRootNode(); +} diff -r 3dfa0be90a0d -r 35e327577b58 src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/JungleTreeEditor.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/JungleTreeEditor.java Sat Jan 26 22:52:32 2013 +0900 @@ -0,0 +1,9 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.Transaction; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TreeEditor; + +public interface JungleTreeEditor extends TreeEditor , Transaction +{ + +} diff -r 3dfa0be90a0d -r 35e327577b58 src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/core/Parent.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/core/Parent.java Sat Jan 26 22:52:32 2013 +0900 @@ -0,0 +1,6 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core; + +public interface Parent +{ + public Children getChildren(); +} diff -r 3dfa0be90a0d -r 35e327577b58 src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/Transaction.java --- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/Transaction.java Sat Jan 26 18:41:25 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/Transaction.java Sat Jan 26 22:52:32 2013 +0900 @@ -1,6 +1,7 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; public interface Transaction { diff -r 3dfa0be90a0d -r 35e327577b58 src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/TreeEditor.java --- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/TreeEditor.java Sat Jan 26 18:41:25 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/TreeEditor.java Sat Jan 26 22:52:32 2013 +0900 @@ -5,11 +5,11 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; -public interface TreeEditor +public interface TreeEditor> { - public Either appendChild(NodePath _path,int _pos); - public Either deleteChild(NodePath _path,int _pos); - public Either putAttribute(NodePath _path,String _key,ByteBuffer _value); - public Either deleteAttribute(NodePath _path,String _key); - public Either edit(NodePath _path,NodeEditor _transformer); + public Either appendChild(NodePath _path,int _pos); + public Either deleteChild(NodePath _path,int _pos); + public Either putAttribute(NodePath _path,String _key,ByteBuffer _value); + public Either deleteAttribute(NodePath _path,String _key); + public Either edit(NodePath _path,NodeEditor _transformer); } diff -r 3dfa0be90a0d -r 35e327577b58 src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/ClonableAttributes.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/ClonableAttributes.java Sat Jan 26 22:52:32 2013 +0900 @@ -0,0 +1,8 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableAttributes; + +public interface ClonableAttributes> extends EditableAttributes +{ + +} diff -r 3dfa0be90a0d -r 35e327577b58 src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/ClonableChildren.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/ClonableChildren.java Sat Jan 26 22:52:32 2013 +0900 @@ -0,0 +1,11 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableChildren; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; + +public interface ClonableChildren> extends EditableChildren +{ + public Either replaceNode(int _pos,T _replacement); +} \ No newline at end of file diff -r 3dfa0be90a0d -r 35e327577b58 src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/ClonableNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/ClonableNode.java Sat Jan 26 22:52:32 2013 +0900 @@ -0,0 +1,12 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableNode; + +public interface ClonableNode> extends EditableNode +{ + @Override + public ClonableChildren getChildren(); + + @Override + public ClonableAttributes getAttributes(); +} diff -r 3dfa0be90a0d -r 35e327577b58 src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultAttributes.java --- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultAttributes.java Sat Jan 26 18:41:25 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultAttributes.java Sat Jan 26 22:52:32 2013 +0900 @@ -6,23 +6,23 @@ import fj.data.Option; import fj.data.TreeMap; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Attributes; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableAttributes; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; -public class DefaultAttributes implements EditableAttributes +public class DefaultAttributes implements Attributes { private final TreeMap attrs; - private final List children; - public DefaultAttributes(List _children,TreeMap _attrs) + public DefaultAttributes(TreeMap _attrs) { - children = _children; attrs = _attrs; } + /* @Override public Either put(String _key,ByteBuffer _value) { @@ -31,6 +31,12 @@ return DefaultEither.newB(newNode); } + */ + + public TreeMap getAttributesAsRawMap() + { + return attrs; + } @Override public ByteBuffer get(String _key) @@ -39,16 +45,11 @@ return result.isSome() ? result.some() : null; } + /* @Override public Either delete(String _key) { return null; } - - @Override - public Object get(Object _key) { - // TODO Auto-generated method stub - return null; - } - + */ } diff -r 3dfa0be90a0d -r 35e327577b58 src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultChangeSet.java --- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultChangeSet.java Sat Jan 26 18:41:25 2013 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,60 +0,0 @@ -package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl; - -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeList; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.ChangeSet; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.Operation; - -public class DefaultChangeSet implements ChangeSet -{ - private final ChangeSet prev; - private final String uuid; - private final long revision; - - private final ChangeList changeList; - private final DefaultNode root; - - public DefaultChangeSet(DefaultNode _root,ChangeList _changeList,String _uuid,long _revision,ChangeSet _prev) - { - root = _root; - uuid = _uuid; - revision = _revision; - prev = _prev; - changeList = _changeList; - } - - @Override - public ChangeSet prev() - { - return prev; - } - - @Override - public String uuid() - { - return uuid; - } - - @Override - public long revision() - { - return revision; - } - - @Override - public Iterable getOperations() - { - return changeList; - } - - @Override - public DefaultNode getRoot() - { - return root; - } - - @Override - public ChangeList getChangeList() - { - return changeList; - } -} diff -r 3dfa0be90a0d -r 35e327577b58 src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultChildren.java --- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultChildren.java Sat Jan 26 18:41:25 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultChildren.java Sat Jan 26 22:52:32 2013 +0900 @@ -1,29 +1,22 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl; -import java.nio.ByteBuffer; + import java.util.Iterator; -import fj.P2; import fj.data.List; -import fj.data.TreeMap; +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.store.trasnformer.EditableChildren; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableNode; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.IterableWrapper; -public class DefaultChildren implements EditableChildren +public class DefaultChildren implements Children { private final List children; - private final TreeMap attrs; - public DefaultChildren(List _children,TreeMap _attrs) + public DefaultChildren(List _children) { children = _children; - attrs = _attrs; } + /* public Either replaceNode(DefaultNode _target,int _pos) { if(check(_pos)){ @@ -38,6 +31,7 @@ DefaultNode newNode = new DefaultNode(newList,attrs); return DefaultEither.newB(newNode); } + */ @Override public int size() @@ -45,7 +39,8 @@ return children.length(); } - @Override + /* + public Either addNewChildAt(int _pos) { if(!check(_pos)){ @@ -59,7 +54,6 @@ return DefaultEither.newB(newNode); } - @Override public Either deleteChildAt(int _pos) { if(!check(_pos)){ @@ -74,13 +68,11 @@ return DefaultEither.newB(newNode); } - public boolean check(int _pos) + */ + + public List getChildrenAsRawList() { - if(children.length() < _pos){ - return false; - } - - return true; + return children; } @Override diff -r 3dfa0be90a0d -r 35e327577b58 src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultNode.java --- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultNode.java Sat Jan 26 18:41:25 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultNode.java Sat Jan 26 22:52:32 2013 +0900 @@ -1,15 +1,12 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl; import java.nio.ByteBuffer; -import java.util.Iterator; import fj.Ord; import fj.data.List; import fj.data.TreeMap; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableNode; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.TraversableChildren; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.TraversableNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Node; -public class DefaultNode implements EditableNode , TraversableNode +public class DefaultNode implements Node { public List children; public TreeMap attrs; @@ -36,30 +33,12 @@ @Override public DefaultChildren getChildren() { - return new DefaultChildren(children,attrs); + return new DefaultChildren(children); } @Override public DefaultAttributes getAttributes() { - return new DefaultAttributes(children,attrs); - } - - @Override - public TraversableChildren children() - { - return new TraversableChildren(){ - @Override - public Iterator iterator() - { - return children.iterator(); - } - - @Override - public int size() - { - return children.length(); - } - }; + return new DefaultAttributes(attrs); } } diff -r 3dfa0be90a0d -r 35e327577b58 src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultTreeEditor.java --- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultTreeEditor.java Sat Jan 26 18:41:25 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultTreeEditor.java Sat Jan 26 22:52:32 2013 +0900 @@ -1,19 +1,12 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl; import java.nio.ByteBuffer; -import java.util.Iterator; import fj.data.List; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Node; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeListWriter; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TreeEditor; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TreeEditorError; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.Logger; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.LoggingNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.AppendChildAt; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.DeleteAttribute; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.DeleteChildAt; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.NodeEditor; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.PutAttribute; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultEvaluator; @@ -24,7 +17,7 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; -public class DefaultTreeEditor> +public class DefaultTreeEditor> implements TreeEditor { private final T root; @@ -69,63 +62,57 @@ public Either edit(NodePath _path,NodeEditor _editor) { DefaultEvaluator e = new DefaultEvaluator(_path); + TraversableNodeWrapper wrap = new TraversableNodeWrapper(root); + Either>> either = traverser.traverse(wrap,e); - Either> either = traverser.traverse(root,e); if(either.isA()){ return DefaultEither.newA(either.a()); } - Traversal t = either.b(); + Traversal> t = either.b(); Either ret = clone(t,_editor); return ret; } - private Either clone(Traversal _t,NodeEditor _editor) + private Either clone(Traversal> _t,NodeEditor _editor) { // copying nodes from bottom to root - List> path = List.nil(); - for(Direction direction : _t){ + List>> path = List.nil(); + for(Direction> direction : _t){ path = path.cons(direction); } // target - Direction targetDirection = path.head(); - Either> either = _editor.edit(new LoggingNode(targetDirection.getTarget())); + Direction> targetDirection = path.head(); + T target = targetDirection.getTarget().getWrapped(); + Either either = _editor.edit(target); if(either.isA()){ return DefaultEither.newA(either.a()); } - LoggingNode loggingNode = either.b(); - Logger logger = loggingNode.getLogger(); - DefaultNode newNode = loggingNode.getWrapper(); + T newNode = either.b(); // top int pos = targetDirection.getPosition(); - DefaultNode child = newNode; - for(Direction parentDirection : path.tail()){ - DefaultNode parent = parentDirection.getTarget(); - DefaultChildren chs = parent.getChildren(); - Either ret = chs.replaceNode(child,pos); + T child = newNode; + for(Direction> parentDirection : path.tail()){ + TraversableNodeWrapper parent = parentDirection.getTarget(); + ClonableChildren chs = parent.getWrapped().getChildren(); + + Either ret = chs.replaceNode(pos,child); if(ret.isA()){ return DefaultEither.newA(ret.a()); } - DefaultNode newParent = ret.b(); + T newParent = ret.b(); child = newParent; pos = parentDirection.getPosition(); } - DefaultNode newRoot = child; - TreeEditor newEditor = new DefaultModifiedTreeEditor(logger); + T newRoot = child; + TreeEditor newEditor = new DefaultTreeEditor(newRoot,traverser); return DefaultEither.newB(newEditor); } - - protected Either newEditor(Logger _logger,DefaultNode _newRoot) - { - List logs = List.list(_logger); - TreeEditor newEditor = null; - return DefaultEither.newB(_theB); - } } \ No newline at end of file diff -r 3dfa0be90a0d -r 35e327577b58 src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/TraversableNodeWrapper.java --- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/TraversableNodeWrapper.java Sat Jan 26 18:41:25 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/TraversableNodeWrapper.java Sat Jan 26 22:52:32 2013 +0900 @@ -16,6 +16,11 @@ { wrap = _wrap; } + + public T getWrapped() + { + return wrap; + } @Override public Children> getChildren() diff -r 3dfa0be90a0d -r 35e327577b58 src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/logger/LoggingAttributes.java --- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/logger/LoggingAttributes.java Sat Jan 26 18:41:25 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/logger/LoggingAttributes.java Sat Jan 26 22:52:32 2013 +0900 @@ -1,6 +1,9 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger; import java.nio.ByteBuffer; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.ClonableAttributes; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.ClonableNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.DeleteAttributeOperation; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.Operation; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.SetAttributeOperation; @@ -10,8 +13,8 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; -public class LoggingAttributes> - implements EditableAttributes> +public class LoggingAttributes> + implements ClonableAttributes> { private final EditableAttributes wrap; private final Logger log; diff -r 3dfa0be90a0d -r 35e327577b58 src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/logger/LoggingChildren.java --- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/logger/LoggingChildren.java Sat Jan 26 18:41:25 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/logger/LoggingChildren.java Sat Jan 26 22:52:32 2013 +0900 @@ -1,22 +1,22 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger; import java.util.Iterator; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.ClonableChildren; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.ClonableNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.AppendChildAtOperation; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.DeleteChildAtOperation; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.Operation; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableChildren; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.IterableConverter; -public class LoggingChildren> implements EditableChildren> +public class LoggingChildren> implements ClonableChildren> { - private final EditableChildren wrap; + private final ClonableChildren wrap; private final Logger log; - public LoggingChildren(EditableChildren _wrap,Logger _log) + public LoggingChildren(ClonableChildren _wrap,Logger _log) { wrap = _wrap; log = _log; @@ -84,4 +84,17 @@ return DefaultEither.newB(newLoggingNode); } + + @Override + public Either> replaceNode(int _pos,LoggingNode _replacement) + { + T target = _replacement.getWrapper(); + Either e = wrap.replaceNode(_pos,target); + if(e.isA()){ + return DefaultEither.newA(e.a()); + } + + T newWrap = e.b(); + return DefaultEither.newB(new LoggingNode(newWrap,log)); + } } diff -r 3dfa0be90a0d -r 35e327577b58 src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/logger/LoggingNode.java --- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/logger/LoggingNode.java Sat Jan 26 18:41:25 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/logger/LoggingNode.java Sat Jan 26 22:52:32 2013 +0900 @@ -1,11 +1,14 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.ClonableAttributes; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.ClonableChildren; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.ClonableNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableAttributes; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableChildren; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableNode; -public class LoggingNode> - implements EditableNode> +public class LoggingNode> + implements ClonableNode> { public LoggingNode(T _wrap) { @@ -22,13 +25,13 @@ private final Logger log; @Override - public EditableAttributes> getAttributes() + public ClonableAttributes> getAttributes() { return new LoggingAttributes(wrap.getAttributes(),log); } @Override - public EditableChildren> getChildren() + public ClonableChildren> getChildren() { return new LoggingChildren(wrap.getChildren(),log); } diff -r 3dfa0be90a0d -r 35e327577b58 src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/ClonableDefaultAttributes.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/ClonableDefaultAttributes.java Sat Jan 26 22:52:32 2013 +0900 @@ -0,0 +1,56 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction; + +import java.nio.ByteBuffer; + +import fj.data.TreeMap; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultAttributes; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.ClonableAttributes; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultChildren; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; + +public class ClonableDefaultAttributes implements ClonableAttributes +{ + private final DefaultNode wrap; + + public ClonableDefaultAttributes(DefaultNode _wrap) + { + wrap = _wrap; + } + + @Override + public Either delete(String _key) + { + DefaultAttributes attrs = wrap.getAttributes(); + DefaultChildren children = wrap.getChildren(); + + TreeMap raw = attrs.getAttributesAsRawMap(); + TreeMap newMap = raw.delete(_key); + + DefaultNode newNode = new DefaultNode(children.getChildrenAsRawList(),newMap); + + return DefaultEither.newB(new ClonableDefaultNode(newNode)); + } + + @Override + public Either put(String _key, ByteBuffer _value) + { + DefaultAttributes attrs = wrap.getAttributes(); + DefaultChildren children = wrap.getChildren(); + + TreeMap raw = attrs.getAttributesAsRawMap(); + TreeMap newMap = raw.set(_key,_value); + + DefaultNode newNode = new DefaultNode(children.getChildrenAsRawList(),newMap); + + return DefaultEither.newB(new ClonableDefaultNode(newNode)); + } + + @Override + public ByteBuffer get(String _key) + { + return wrap.getAttributes().get(_key); + } +} diff -r 3dfa0be90a0d -r 35e327577b58 src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/ClonableDefaultChildren.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/ClonableDefaultChildren.java Sat Jan 26 22:52:32 2013 +0900 @@ -0,0 +1,108 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction; + +import java.nio.ByteBuffer; +import java.util.Iterator; +import fj.P2; +import fj.data.List; +import fj.data.TreeMap; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.ClonableChildren; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultAttributes; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultChildren; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.NodeEditorError; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.IterableConverter; + +public class ClonableDefaultChildren implements ClonableChildren +{ + private final DefaultNode node; + + public ClonableDefaultChildren(DefaultNode _node) + { + node = _node; + } + + private boolean boundaryCheck(int _pos) + { + int size = node.getChildren().size(); + if(size <= _pos){ + return false; + } + + return true; + } + + @Override + public Either addNewChildAt(int _pos) + { + if(!boundaryCheck(_pos)){ + return DefaultEither.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); + } + + DefaultChildren children = node.getChildren(); + DefaultAttributes attrs = node.getAttributes(); + + List raw = children.getChildrenAsRawList(); + + P2,List> split = raw.splitAt(_pos); + List newChildren = split._1().snoc(new DefaultNode()).append(split._2()); + DefaultNode newNode = new DefaultNode(newChildren,attrs.getAttributesAsRawMap()); + + return DefaultEither.newB(new ClonableDefaultNode(newNode)); + } + + @Override + public Either deleteChildAt(int _pos) + { + if(!boundaryCheck(_pos)){ + return DefaultEither.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); + } + + DefaultChildren chs = node.getChildren(); + List raw = chs.getChildrenAsRawList(); + + P2,List> split = raw.splitAt(_pos); + List newChildren = split._1().init().append(split._2()); + + DefaultAttributes attrs = node.getAttributes(); + TreeMap map = attrs.getAttributesAsRawMap(); + + DefaultNode newNode = new DefaultNode(newChildren,map); + + return DefaultEither.newB(new ClonableDefaultNode(newNode)); + } + + @Override + public int size() + { + return node.getChildren().size(); + } + + @Override + public Iterator iterator() + { + IterableConverter.Converter converter = new IterableConverter.Converter(){ + @Override + public ClonableDefaultNode conv(DefaultNode _b) + { + return new ClonableDefaultNode(_b); + } + }; + + List raw = node.getChildren().getChildrenAsRawList(); + return new IterableConverter(raw,converter).iterator(); + } + + @Override + public Either replaceNode(int _pos,ClonableDefaultNode _replacement) + { + if(!boundaryCheck(_pos)){ + return DefaultEither.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); + } + + return null; + } +} diff -r 3dfa0be90a0d -r 35e327577b58 src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/ClonableDefaultNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/ClonableDefaultNode.java Sat Jan 26 22:52:32 2013 +0900 @@ -0,0 +1,28 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.ClonableAttributes; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.ClonableChildren; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.ClonableNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNode; + +public class ClonableDefaultNode implements ClonableNode +{ + private final DefaultNode wrap; + + public ClonableDefaultNode(DefaultNode _wrap) + { + wrap = _wrap; + } + + @Override + public ClonableChildren getChildren() + { + return new ClonableDefaultChildren(wrap); + } + + @Override + public ClonableAttributes getAttributes() + { + return new ClonableDefaultAttributes(wrap); + } +} diff -r 3dfa0be90a0d -r 35e327577b58 src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultJungleTreeEditor.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultJungleTreeEditor.java Sat Jan 26 22:52:32 2013 +0900 @@ -0,0 +1,66 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction; + +import java.nio.ByteBuffer; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TreeEditor; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultTreeEditor; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.LoggingNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.NodeEditor; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; + +public class DefaultJungleTreeEditor implements JungleTreeEditor +{ + private final TransactionManager txManager; + private final DefaultNode root; + private final DefaultTreeEditor> editor; + + public DefaultJungleTreeEditor(DefaultNode _root,TransactionManager _txManager) + { + root = _root; + txManager = _txManager; + } + + @Override + public Either appendChild(NodePath _path, int _pos) + { + + + return null; + } + + @Override + public Either deleteChild(NodePath _path, int _pos) + { + return null; + } + + @Override + public Either putAttribute(NodePath _path,String _key,ByteBuffer _value) + { + return null; + } + + @Override + public Either deleteAttribute(NodePath _path, String _key) + { + return null; + } + + @Override + public Either edit(NodePath _path,NodeEditor _transformer) + { + return null; + } + + @Override + public Either success() + { + return null; + } + +} diff -r 3dfa0be90a0d -r 35e327577b58 src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/TransactionManager.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/TransactionManager.java Sat Jan 26 22:52:32 2013 +0900 @@ -0,0 +1,8 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.ChangeSet; + +public interface TransactionManager +{ + public boolean commit(ChangeSet _ch); +}