Mercurial > hg > Members > shoshi > jungle > jungle-core
changeset 52:8c6ff361b68a
sleepy
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/TreeEditor.java Fri Feb 08 02:21:00 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/TreeEditor.java Fri Feb 08 03:50:21 2013 +0900 @@ -1,11 +1,11 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.ClonableNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; 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 interface TreeEditor { - public <T extends ClonableNode<T>> Either<Error,T> edit(T _root,NodePath _path,NodeEditor _transformer); + public <T extends TreeNode<T>> Either<Error,T> edit(T _root,NodePath _path,NodeEditor _transformer); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/ClonableAttributes.java Fri Feb 08 02:21:00 2013 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -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<T extends ClonableNode<T>> extends EditableAttributes<T> -{ - -}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/ClonableChildren.java Fri Feb 08 02:21:00 2013 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -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<T extends EditableNode<T>> extends EditableChildren<T> -{ - public Either<Error,T> addNewChildAt(int _pos,T _newChild); - public Either<Error,T> replaceNode(int _pos,T _replacement); -} \ No newline at end of file
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/ClonableNode.java Fri Feb 08 02:21:00 2013 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ -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<T extends ClonableNode<T>> extends EditableNode<T> -{ - @Override - public ClonableChildren<T> getChildren(); - - @Override - public ClonableAttributes<T> getAttributes(); - - public T createNewNode(); -}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultTreeEditor.java Fri Feb 08 02:21:00 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultTreeEditor.java Fri Feb 08 03:50:21 2013 +0900 @@ -22,7 +22,7 @@ } @Override - public <T extends ClonableNode<T>> Either<Error,T> edit(T _root,NodePath _path,NodeEditor _editor) + public <T extends TreeNode<T>> Either<Error,T> edit(T _root,NodePath _path,NodeEditor _editor) { DefaultEvaluator e = new DefaultEvaluator(_path); TraversableNodeWrapper<T> wrap = new TraversableNodeWrapper<T>(_root); @@ -38,7 +38,7 @@ return ret; } - private <T extends ClonableNode<T>> Either<Error,T> clone(Traversal<TraversableNodeWrapper<T>> _t,NodeEditor _editor) + private <T extends TreeNode<T>> Either<Error,T> clone(Traversal<TraversableNodeWrapper<T>> _t,NodeEditor _editor) { // copying nodes from bottom to root @@ -50,19 +50,20 @@ // target Direction<TraversableNodeWrapper<T>> targetDirection = path.head(); T target = targetDirection.getTarget().getWrapped(); - Either<Error,T> either = _editor.edit(target); + EditableNodeWrapper<T> wrapper = new EditableNodeWrapper<T>(target); + Either<Error,EditableNodeWrapper<T>> either = _editor.edit(wrapper); if(either.isA()){ return DefaultEither.newA(either.a()); } - T newNode = either.b(); + T newNode = either.b().getWrap(); // top int pos = targetDirection.getPosition(); T child = newNode; for(Direction<TraversableNodeWrapper<T>> parentDirection : path.tail()){ TraversableNodeWrapper<T> parent = parentDirection.getTarget(); - ClonableChildren<T> chs = parent.getWrapped().getChildren(); + TreeNodeChildren<T> chs = parent.getWrapped().getChildren(); Either<Error,T> ret = chs.replaceNode(pos,child); if(ret.isA()){
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/EditableNodeWrapper.java Fri Feb 08 03:50:21 2013 +0900 @@ -0,0 +1,151 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl; + +import java.nio.ByteBuffer; +import java.util.Iterator; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Node; +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; +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 EditableNodeWrapper<T extends TreeNode<T>> implements EditableNode<EditableNodeWrapper<T>> +{ + private final T wrap; + + public EditableNodeWrapper(T _wrap) + { + wrap = _wrap; + } + + @Override + public EditableAttributes<EditableNodeWrapper<T>> getAttributes() + { + return new EditableAttributesWrapper<T>(wrap); + } + + @Override + public EditableChildren<EditableNodeWrapper<T>> getChildren() + { + return null; + } + + public T getWrap() + { + return wrap; + } + + private static class EditableAttributesWrapper<T extends TreeNode<T>> implements EditableAttributes<EditableNodeWrapper<T>> + { + private final TreeNodeAttributes<T> attributes; + + public EditableAttributesWrapper(T _wrap) + { + attributes = _wrap.getAttributes(); + } + + @Override + public ByteBuffer get(String _key) + { + return attributes.get(_key); + } + + @Override + public Either<Error, EditableNodeWrapper<T>> delete(String _key) + { + Either<Error,T> either = attributes.delete(_key); + if(either.isA()){ + return DefaultEither.newA(either.a()); + } + + T newWrap = either.b(); + EditableNodeWrapper<T> newWrapper = new EditableNodeWrapper<T>(newWrap); + return DefaultEither.newB(newWrapper); + } + + @Override + public Either<Error, EditableNodeWrapper<T>> put(String _key,ByteBuffer _value) + { + Either<Error,T> either = attributes.put(_key,_value); + if(either.isA()){ + return DefaultEither.newA(either.a()); + } + + T newWrap = either.b(); + EditableNodeWrapper<T> newWrapper = new EditableNodeWrapper<T>(newWrap); + return DefaultEither.newB(newWrapper); + } + } + + public static class EditableChildrenWrapper<T extends TreeNode<T>> implements EditableChildren<EditableNodeWrapper<T>> + { + private final TreeNodeChildren<T> children; + + public EditableChildrenWrapper(T _wrap) + { + children = _wrap.getChildren(); + } + + @Override + public Either<Error,Node> at(int _pos) + { + Either<Error,T> either = children.at(_pos); + if(either.isA()){ + return DefaultEither.newA(either.a()); + } + + T target = either.b(); + Node newWrapper = new NodeWrapper<T>(target); + return DefaultEither.newB(newWrapper); + } + + @Override + public int size() + { + return children.size(); + } + + @Override + public Iterator<Node> iterator() + { + IterableConverter.Converter<Node,T> converter = new IterableConverter.Converter<Node,T>(){ + @Override + public Node conv(T _b){ + return new NodeWrapper<T>(_b); + } + }; + + + return new IterableConverter<Node,T>(children,converter).iterator(); + } + + @Override + public Either<Error,EditableNodeWrapper<T>> addNewChildAt(int _pos) + { + Either<Error,T> either = children.addNewChildAt(_pos); + if(either.isA()){ + DefaultEither.newA(either.a()); + } + T newWrap = either.b(); + EditableNodeWrapper<T> newWrapper = new EditableNodeWrapper<T>(newWrap); + + return DefaultEither.newB(newWrapper); + } + + @Override + public Either<Error,EditableNodeWrapper<T>> deleteChildAt(int _pos) + { + Either<Error,T> either = children.deleteChildAt(_pos); + if(either.isA()){ + DefaultEither.newA(either.a()); + } + T newWrap = either.b(); + EditableNodeWrapper<T> newWrapper = new EditableNodeWrapper<T>(newWrap); + + return DefaultEither.newB(newWrapper); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/NodeWrapper.java Fri Feb 08 03:50:21 2013 +0900 @@ -0,0 +1,76 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl; + +import java.util.Iterator; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Attributes; +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.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 NodeWrapper<T extends TreeNode<T>> implements Node +{ + private final T wrap; + + public NodeWrapper(T _wrap) + { + wrap = _wrap; + } + + @Override + public Attributes getAttributes() + { + return wrap.getAttributes(); + } + + @Override + public Children<Node> getChildren() + { + return new ChildrenWrapper<T>(wrap); + } + + private static class ChildrenWrapper<T extends TreeNode<T>> implements Children<Node> + { + private final TreeNodeChildren<T> children; + + public ChildrenWrapper(T _wrap) + { + children = _wrap.getChildren(); + } + + @Override + public Iterator<Node> iterator() + { + IterableConverter.Converter<Node,T> converter = new IterableConverter.Converter<Node,T>(){ + @Override + public Node conv(T _b){ + return new NodeWrapper<T>(_b); + } + }; + + + return new IterableConverter<Node,T>(children,converter).iterator(); + } + + @Override + public Either<Error, Node> at(int _pos) + { + Either<Error,T> either = children.at(_pos); + if(either.isA()){ + return DefaultEither.newA(either.a()); + } + T target = either.b(); + Node newWrapper = new NodeWrapper<T>(target); + + return DefaultEither.newB(newWrapper); + } + + @Override + public int size() + { + return children.size(); + } + } +}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/TraversableNodeWrapper.java Fri Feb 08 02:21:00 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/TraversableNodeWrapper.java Fri Feb 08 03:50:21 2013 +0900 @@ -1,10 +1,8 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl; import java.util.Iterator; - import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Children; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Parent; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.TraversableNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/TreeNode.java Fri Feb 08 03:50:21 2013 +0900 @@ -0,0 +1,15 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.AttributesContainer; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Parent; + +public interface TreeNode<T extends TreeNode<T>> extends Parent<T> , AttributesContainer +{ + @Override + public TreeNodeChildren<T> getChildren(); + + @Override + public TreeNodeAttributes<T> getAttributes(); + + public T createNewNode(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/TreeNodeAttributes.java Fri Feb 08 03:50:21 2013 +0900 @@ -0,0 +1,13 @@ +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.Attributes; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; + +public interface TreeNodeAttributes<T extends TreeNode<T>> extends Attributes +{ + public Either<Error,T> delete(String _key); + public Either<Error,T> put(String _key,ByteBuffer _value); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/TreeNodeChildren.java Fri Feb 08 03:50:21 2013 +0900 @@ -0,0 +1,15 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Children; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Parent; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; + +public interface TreeNodeChildren<T extends Parent<T>> extends Children<T> +{ + public Either<Error,T> addNewChildAt(int _pos); + public Either<Error,T> deleteChildAt(int _pos); + public Either<Error,T> addNewChildAt(int _pos,T _newChild); + public Either<Error,T> replaceNode(int _pos,T _replacement); +} \ 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/logger/DefaultTreeOperationLog.java Fri Feb 08 03:50:21 2013 +0900 @@ -0,0 +1,46 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger; + +import java.util.Iterator; + +import fj.data.List; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.DefaultTreeOperation; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation; + +public class DefaultTreeOperationLog implements TreeOperationLog +{ + private final List<TreeOperation> list; + + public DefaultTreeOperationLog() + { + list = List.nil(); + } + + private DefaultTreeOperationLog(List<TreeOperation> _list) + { + list = _list; + } + + @Override + public Iterator<TreeOperation> iterator() + { + return list.iterator(); + } + + @Override + public TreeOperationLog add(NodePath _p, NodeOperation _op) + { + DefaultTreeOperation op = new DefaultTreeOperation(_p,_op); + List<TreeOperation> newList = list.snoc(op); + return new DefaultTreeOperationLog(newList); + } + + @Override + public int length() + { + return list.length(); + } + +}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/logger/LoggingChildren.java Fri Feb 08 02:21:00 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/logger/LoggingChildren.java Fri Feb 08 03:50:21 2013 +0900 @@ -1,6 +1,8 @@ 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.core.Node; 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.NodeOperation; @@ -30,19 +32,10 @@ } @Override - public Iterator<LoggingNode<T>> iterator() + public Iterator<Node> iterator() { EditableChildren<T> children = wrap.getChildren(); - - IterableConverter.Converter<LoggingNode<T>,T> converter = new IterableConverter.Converter<LoggingNode<T>,T>(){ - @Override - public LoggingNode<T> conv(T _b) { - return new LoggingNode<T>(_b,log); - } - }; - - IterableConverter<LoggingNode<T>,T> iterable = new IterableConverter<LoggingNode<T>,T>(children,converter); - return iterable.iterator(); + return children.iterator(); } public Either<Error,LoggingNode<T>> edit(NodeOperation _op) @@ -73,15 +66,15 @@ } @Override - public Either<Error,LoggingNode<T>> at(int _pos) + public Either<Error,Node> at(int _pos) { EditableChildren<T> children = wrap.getChildren(); - Either<Error,T> either = children.at(_pos); + Either<Error,Node> either = children.at(_pos); if(either.isA()){ return DefaultEither.newA(either.a()); } - T newWrap = either.b(); - return DefaultEither.newB(new LoggingNode<T>(newWrap,log)); + Node node = either.b(); + return DefaultEither.newB(node); } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/logger/TreeOperationLog.java Fri Feb 08 03:50:21 2013 +0900 @@ -0,0 +1,11 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation; + +public interface TreeOperationLog extends Iterable<TreeOperation> +{ + public TreeOperationLog add(NodePath _p,NodeOperation _op); + public int length(); +}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/operations/DeleteChildAtOperation.java Fri Feb 08 02:21:00 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/operations/DeleteChildAtOperation.java Fri Feb 08 03:50:21 2013 +0900 @@ -21,7 +21,6 @@ return Command.DELETE_CHILD; } - @Override public <T extends EditableNode<T>> Either<Error, T> invoke(T _target) {
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/trasnformer/EditableAttributes.java Fri Feb 08 02:21:00 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/trasnformer/EditableAttributes.java Fri Feb 08 03:50:21 2013 +0900 @@ -2,12 +2,10 @@ import java.nio.ByteBuffer; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Attributes; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Parent; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultError; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; -public interface EditableAttributes<T extends Parent<T>> extends Attributes +public interface EditableAttributes<T> extends Attributes { public Either<Error,T> delete(String _key); public Either<Error,T> put(String _key,ByteBuffer _value);
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/trasnformer/EditableChildren.java Fri Feb 08 02:21:00 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/trasnformer/EditableChildren.java Fri Feb 08 03:50:21 2013 +0900 @@ -1,12 +1,13 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer; 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.core.Parent; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultError; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; -public interface EditableChildren<T extends Parent<T>> extends Children<T> +public interface EditableChildren<T extends Parent<Node>> extends Children<Node> { public Either<Error,T> addNewChildAt(int _pos); public Either<Error,T> deleteChildAt(int _pos);
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/trasnformer/EditableNode.java Fri Feb 08 02:21:00 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/trasnformer/EditableNode.java Fri Feb 08 03:50:21 2013 +0900 @@ -1,9 +1,10 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.AttributesContainer; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Node; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Parent; -public interface EditableNode<T extends Parent<T>> extends AttributesContainer , Parent<T> +public interface EditableNode<T extends Parent<Node>> extends AttributesContainer , Parent<Node> { public EditableAttributes<T> getAttributes(); public EditableChildren<T> getChildren();
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/ClonableDefaultAttributes.java Fri Feb 08 02:21:00 2013 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +0,0 @@ -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.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; - -public class ClonableDefaultAttributes implements ClonableAttributes<ClonableDefaultNode> -{ - private final DefaultNode wrap; - - public ClonableDefaultAttributes(DefaultNode _wrap) - { - wrap = _wrap; - } - - @Override - public Either<Error,ClonableDefaultNode> delete(String _key) - { - if(_key == null){ - return DefaultEither.newA(NodeEditorError.NULL_VALUE_NOT_ALLOWED); - } - - DefaultAttributes attrs = wrap.getAttributes(); - DefaultChildren children = wrap.getChildren(); - - TreeMap<String,ByteBuffer> raw = attrs.getAttributesAsRawMap(); - if(!raw.contains(_key)){ - return DefaultEither.newA(NodeEditorError.DELETE_KEY_NOT_FOUND); - } - - TreeMap<String,ByteBuffer> newMap = raw.delete(_key); - - DefaultNode newNode = new DefaultNode(children.getChildrenAsRawList(),newMap); - - return DefaultEither.newB(new ClonableDefaultNode(newNode)); - } - - @Override - public Either<Error, ClonableDefaultNode> put(String _key, ByteBuffer _value) - { - if(_key == null || _value == null){ - return DefaultEither.newA(NodeEditorError.NULL_VALUE_NOT_ALLOWED); - } - - DefaultAttributes attrs = wrap.getAttributes(); - DefaultChildren children = wrap.getChildren(); - - TreeMap<String,ByteBuffer> raw = attrs.getAttributesAsRawMap(); - TreeMap<String,ByteBuffer> 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); - } -}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/ClonableDefaultChildren.java Fri Feb 08 02:21:00 2013 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,158 +0,0 @@ -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.core.Node; -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<ClonableDefaultNode> -{ - public static void main(String _args[]) - { - List<Integer> list = List.range(0,5); - P2<List<Integer>, List<Integer>> split = list.splitAt(0); - System.out.println(split._1().length()); - System.out.println(split._2().length()); - - } - - 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<Error,ClonableDefaultNode> addNewChildAt(int _pos) - { - if(!boundaryCheck(_pos) || _pos < 0){ - return DefaultEither.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); - } - - DefaultChildren children = node.getChildren(); - DefaultAttributes attrs = node.getAttributes(); - - List<DefaultNode> raw = children.getChildrenAsRawList(); - - P2<List<DefaultNode>,List<DefaultNode>> split = raw.splitAt(_pos); - List<DefaultNode> 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<Error,ClonableDefaultNode> deleteChildAt(int _pos) - { - if(!boundaryCheck(_pos) || _pos < 0 || size() == 0){ - return DefaultEither.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); - } - - DefaultChildren chs = node.getChildren(); - List<DefaultNode> raw = chs.getChildrenAsRawList(); - - P2<List<DefaultNode>,List<DefaultNode>> split = raw.splitAt(_pos); - //List<DefaultNode> newChildren = split._1().init().append(split._2()); - List<DefaultNode> newChildren = split._1().append(split._2().tail()); - - DefaultAttributes attrs = node.getAttributes(); - TreeMap<String, ByteBuffer> 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<ClonableDefaultNode> iterator() - { - IterableConverter.Converter<ClonableDefaultNode,DefaultNode> converter = new IterableConverter.Converter<ClonableDefaultNode,DefaultNode>(){ - @Override - public ClonableDefaultNode conv(DefaultNode _b) - { - return new ClonableDefaultNode(_b); - } - }; - - List<DefaultNode> raw = node.getChildren().getChildrenAsRawList(); - return new IterableConverter<ClonableDefaultNode,DefaultNode>(raw,converter).iterator(); - } - - @Override - public Either<Error,ClonableDefaultNode> replaceNode(int _pos,ClonableDefaultNode _replacement) - { - int size = node.getChildren().size(); - if(!(0 <= _pos && _pos < size)){ - return DefaultEither.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); - } - DefaultNode replacement = _replacement.getWrapped(); - - List<DefaultNode> rawList = node.getChildren().getChildrenAsRawList(); - P2<List<DefaultNode>,List<DefaultNode>> split = rawList.splitAt(_pos + 1); - List<DefaultNode> init = split._1().init(); - List<DefaultNode> newInit = init.snoc(replacement); - List<DefaultNode> newList = newInit.append(split._2()); - TreeMap<String, ByteBuffer> rawMap = node.getAttributes().getAttributesAsRawMap(); - - return DefaultEither.newB(new ClonableDefaultNode(new DefaultNode(newList,rawMap))); - } - - @Override - public Either<Error,ClonableDefaultNode> at(int _pos) - { - List<DefaultNode> rawList = node.getChildren().getChildrenAsRawList(); - DefaultNode ch = rawList.index(_pos); - if(ch == null){ - return DefaultEither.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); - } - - return DefaultEither.newB(new ClonableDefaultNode(ch)); - } - - @Override - public Either<Error, ClonableDefaultNode> addNewChildAt(int _pos,ClonableDefaultNode _newChild) - { - if(!boundaryCheck(_pos) || _pos < 0){ - return DefaultEither.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); - } - DefaultNode newChild = _newChild.getWrapped(); - - List<DefaultNode> raw = node.getChildren().getChildrenAsRawList(); - TreeMap<String, ByteBuffer> rawMap = node.getAttributes().getAttributesAsRawMap(); - - P2<List<DefaultNode>,List<DefaultNode>> split = raw.splitAt(_pos); - List<DefaultNode> newChildren = split._1().snoc(newChild).append(split._2()); - DefaultNode newNode = new DefaultNode(newChildren,rawMap); - - return DefaultEither.newB(new ClonableDefaultNode(newNode)); - } -}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/ClonableDefaultNode.java Fri Feb 08 02:21:00 2013 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction; - -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<ClonableDefaultNode> -{ - private final DefaultNode wrap; - - public ClonableDefaultNode() - { - this(new DefaultNode()); - } - - public ClonableDefaultNode(DefaultNode _wrap) - { - wrap = _wrap; - } - - @Override - public ClonableDefaultChildren getChildren() - { - return new ClonableDefaultChildren(wrap); - } - - @Override - public ClonableDefaultAttributes getAttributes() - { - return new ClonableDefaultAttributes(wrap); - } - - @Override - public ClonableDefaultNode createNewNode() - { - return new ClonableDefaultNode(new DefaultNode()); - } - - public DefaultNode getWrapped() - { - return wrap; - } -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTreeNode.java Fri Feb 08 03:50:21 2013 +0900 @@ -0,0 +1,42 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; + +public class DefaultTreeNode implements TreeNode<DefaultTreeNode> +{ + private final DefaultNode wrap; + + public DefaultTreeNode() + { + this(new DefaultNode()); + } + + public DefaultTreeNode(DefaultNode _wrap) + { + wrap = _wrap; + } + + @Override + public DefaultTreeNodeChildren getChildren() + { + return new DefaultTreeNodeChildren(wrap); + } + + @Override + public DefaultTreeNodeAttribute getAttributes() + { + return new DefaultTreeNodeAttribute(wrap); + } + + @Override + public DefaultTreeNode createNewNode() + { + return new DefaultTreeNode(new DefaultNode()); + } + + public DefaultNode getWrap() + { + return wrap; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTreeNodeAttribute.java Fri Feb 08 03:50:21 2013 +0900 @@ -0,0 +1,68 @@ +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.DefaultChildren; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNodeAttributes; +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; + +public class DefaultTreeNodeAttribute implements TreeNodeAttributes<DefaultTreeNode> +{ + private final DefaultNode wrap; + + public DefaultTreeNodeAttribute(DefaultNode _wrap) + { + wrap = _wrap; + } + + @Override + public Either<Error,DefaultTreeNode> delete(String _key) + { + if(_key == null){ + return DefaultEither.newA(NodeEditorError.NULL_VALUE_NOT_ALLOWED); + } + + DefaultAttributes attrs = wrap.getAttributes(); + DefaultChildren children = wrap.getChildren(); + + TreeMap<String,ByteBuffer> raw = attrs.getAttributesAsRawMap(); + if(!raw.contains(_key)){ + return DefaultEither.newA(NodeEditorError.DELETE_KEY_NOT_FOUND); + } + + TreeMap<String,ByteBuffer> newMap = raw.delete(_key); + + DefaultNode newNode = new DefaultNode(children.getChildrenAsRawList(),newMap); + + return DefaultEither.newB(new DefaultTreeNode(newNode)); + } + + @Override + public Either<Error,DefaultTreeNode> put(String _key, ByteBuffer _value) + { + if(_key == null || _value == null){ + return DefaultEither.newA(NodeEditorError.NULL_VALUE_NOT_ALLOWED); + } + + DefaultAttributes attrs = wrap.getAttributes(); + DefaultChildren children = wrap.getChildren(); + + TreeMap<String,ByteBuffer> raw = attrs.getAttributesAsRawMap(); + TreeMap<String,ByteBuffer> newMap = raw.set(_key,_value); + + DefaultNode newNode = new DefaultNode(children.getChildrenAsRawList(),newMap); + + return DefaultEither.newB(new DefaultTreeNode(newNode)); + } + + @Override + public ByteBuffer get(String _key) + { + return wrap.getAttributes().get(_key); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTreeNodeChildren.java Fri Feb 08 03:50:21 2013 +0900 @@ -0,0 +1,155 @@ +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.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.impl.TreeNodeChildren; +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 DefaultTreeNodeChildren implements TreeNodeChildren<DefaultTreeNode> +{ + public static void main(String _args[]) + { + List<Integer> list = List.range(0,5); + P2<List<Integer>, List<Integer>> split = list.splitAt(0); + System.out.println(split._1().length()); + System.out.println(split._2().length()); + + } + + private final DefaultNode node; + + public DefaultTreeNodeChildren(DefaultNode _node) + { + node = _node; + } + + private boolean boundaryCheck(int _pos) + { + int size = node.getChildren().size(); + if(size < _pos){ + return false; + } + + return true; + } + + @Override + public Either<Error,DefaultTreeNode> addNewChildAt(int _pos) + { + if(!boundaryCheck(_pos) || _pos < 0){ + return DefaultEither.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); + } + + DefaultChildren children = node.getChildren(); + DefaultAttributes attrs = node.getAttributes(); + + List<DefaultNode> raw = children.getChildrenAsRawList(); + + P2<List<DefaultNode>,List<DefaultNode>> split = raw.splitAt(_pos); + List<DefaultNode> newChildren = split._1().snoc(new DefaultNode()).append(split._2()); + DefaultNode newNode = new DefaultNode(newChildren,attrs.getAttributesAsRawMap()); + + return DefaultEither.newB(new DefaultTreeNode(newNode)); + } + + @Override + public Either<Error,DefaultTreeNode> deleteChildAt(int _pos) + { + if(!boundaryCheck(_pos) || _pos < 0 || size() == 0){ + return DefaultEither.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); + } + + DefaultChildren chs = node.getChildren(); + List<DefaultNode> raw = chs.getChildrenAsRawList(); + + P2<List<DefaultNode>,List<DefaultNode>> split = raw.splitAt(_pos); + List<DefaultNode> newChildren = split._1().append(split._2().tail()); + + DefaultAttributes attrs = node.getAttributes(); + TreeMap<String, ByteBuffer> map = attrs.getAttributesAsRawMap(); + + DefaultNode newNode = new DefaultNode(newChildren,map); + + return DefaultEither.newB(new DefaultTreeNode(newNode)); + } + + @Override + public int size() + { + return node.getChildren().size(); + } + + @Override + public Iterator<DefaultTreeNode> iterator() + { + IterableConverter.Converter<DefaultTreeNode,DefaultNode> converter = new IterableConverter.Converter<DefaultTreeNode,DefaultNode>(){ + @Override + public DefaultTreeNode conv(DefaultNode _b) + { + return new DefaultTreeNode(_b); + } + }; + + List<DefaultNode> raw = node.getChildren().getChildrenAsRawList(); + return new IterableConverter<DefaultTreeNode,DefaultNode>(raw,converter).iterator(); + } + + @Override + public Either<Error,DefaultTreeNode> replaceNode(int _pos,DefaultTreeNode _replacement) + { + int size = node.getChildren().size(); + if(!(0 <= _pos && _pos < size)){ + return DefaultEither.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); + } + DefaultNode replacement = _replacement.getWrap(); + + List<DefaultNode> rawList = node.getChildren().getChildrenAsRawList(); + P2<List<DefaultNode>,List<DefaultNode>> split = rawList.splitAt(_pos + 1); + List<DefaultNode> init = split._1().init(); + List<DefaultNode> newInit = init.snoc(replacement); + List<DefaultNode> newList = newInit.append(split._2()); + TreeMap<String, ByteBuffer> rawMap = node.getAttributes().getAttributesAsRawMap(); + + return DefaultEither.newB(new DefaultTreeNode(new DefaultNode(newList,rawMap))); + } + + @Override + public Either<Error,DefaultTreeNode> at(int _pos) + { + List<DefaultNode> rawList = node.getChildren().getChildrenAsRawList(); + DefaultNode ch = rawList.index(_pos); + if(ch == null){ + return DefaultEither.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); + } + + return DefaultEither.newB(new DefaultTreeNode(ch)); + } + + @Override + public Either<Error,DefaultTreeNode> addNewChildAt(int _pos,DefaultTreeNode _newChild) + { + if(!boundaryCheck(_pos) || _pos < 0){ + return DefaultEither.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); + } + DefaultNode newChild = _newChild.getWrap(); + + List<DefaultNode> raw = node.getChildren().getChildrenAsRawList(); + TreeMap<String, ByteBuffer> rawMap = node.getAttributes().getAttributesAsRawMap(); + + P2<List<DefaultNode>,List<DefaultNode>> split = raw.splitAt(_pos); + List<DefaultNode> newChildren = split._1().snoc(newChild).append(split._2()); + DefaultNode newNode = new DefaultNode(newChildren,rawMap); + + return DefaultEither.newB(new DefaultTreeNode(newNode)); + } +}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/TransactionManager.java Fri Feb 08 02:21:00 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/TransactionManager.java Fri Feb 08 03:50:21 2013 +0900 @@ -2,12 +2,13 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNode; 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.OperationLog; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; public interface TransactionManager { - public Either<Error,TransactionManager> commit(DefaultNode _newRoot,Logger _log); + public Either<Error,TransactionManager> commit(DefaultNode _newRoot,TreeOperationLog _log); public String getUUID(); public long getRevision(); }