Mercurial > hg > Members > tatsuki > bench > jungle-core
changeset 11:5f763f32940e
added traverser api
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/NodePath.java Mon Dec 10 18:50:53 2012 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/NodePath.java Fri Dec 14 20:10:48 2012 +0900 @@ -1,6 +1,8 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store; -public interface NodePath extends Iterable<Integer> +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.TraverseEvaluator; + +public interface NodePath extends Iterable<Integer> , TraverseEvaluator { - + public NodePath appendPath(int _pos); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/Result.java Mon Dec 10 18:50:53 2012 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/Result.java Fri Dec 14 20:10:48 2012 +0900 @@ -1,12 +1,6 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Node; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.NodePath; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Tree; - public interface Result { - public Tree getNewTree(); - public NodePath getClonedPath(); - public Node getEffect(); + public TreeEditor getNewEditor(); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/TreeEditor.java Mon Dec 10 18:50:53 2012 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/TreeEditor.java Fri Dec 14 20:10:48 2012 +0900 @@ -2,6 +2,7 @@ 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.trasnformer.NodeTransformer; public interface TreeEditor { @@ -13,5 +14,7 @@ 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 boolean success(); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/trasnformer/EditableAttributes.java Fri Dec 14 20:10:48 2012 +0900 @@ -0,0 +1,11 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer; + +import java.nio.ByteBuffer; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Attributes; + +public interface EditableAttributes extends Attributes +{ + public EditableNode delete(String _key); + public EditableNode 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/trasnformer/EditableChildren.java Fri Dec 14 20:10:48 2012 +0900 @@ -0,0 +1,9 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Children; + +public interface EditableChildren extends Children +{ + public EditableNode addNewChildAt(int _pos); + public EditableNode deleteChildAt(int _pos); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/trasnformer/EditableNode.java Fri Dec 14 20:10:48 2012 +0900 @@ -0,0 +1,12 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Node; + +public interface EditableNode extends Node +{ + @Override + public EditableAttributes getAttributes(); + + @Override + public EditableChildren getChildren(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/trasnformer/NodeTransformer.java Fri Dec 14 20:10:48 2012 +0900 @@ -0,0 +1,6 @@ +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/TransformResult.java Fri Dec 14 20:10:48 2012 +0900 @@ -0,0 +1,6 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer; + +public enum TransformResult +{ + 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/Transformation.java Fri Dec 14 20:10:48 2012 +0900 @@ -0,0 +1,7 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer; + +public interface Transformation +{ + EditableNode getEditableNode(); + TransformResult getResult(); +}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/DefaultEvaluation.java Mon Dec 10 18:50:53 2012 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/DefaultEvaluation.java Fri Dec 14 20:10:48 2012 +0900 @@ -2,20 +2,24 @@ public class DefaultEvaluation implements Evaluation { - public DefaultEvaluation(long _result,TraverseEvaluator _evaluator) + private final Evaluation.Result result; + private final TraverseEvaluator evaluator; + + public DefaultEvaluation(Evaluation.Result _result,TraverseEvaluator _evaluator) { - + result = _result; + evaluator = _evaluator; } @Override - public long result() { - // TODO Auto-generated method stub - return 0; + public Evaluation.Result result() + { + return result; } @Override - public TraverseEvaluator evaluator() { - // TODO Auto-generated method stub - return null; + public TraverseEvaluator evaluator() + { + return evaluator; } }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/DefaultTraverseEvaluator.java Mon Dec 10 18:50:53 2012 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/DefaultTraverseEvaluator.java Fri Dec 14 20:10:48 2012 +0900 @@ -22,13 +22,22 @@ public DefaultTraverseEvaluator add(Integer _next) { - + List<Integer> newPath = path.snoc(_next); + return new DefaultTraverseEvaluator(newPath); } @Override public Evaluation eval(Iterable<Node> _currentPosition,Node _child,int _pos) { - return ; + int head = path.head(); + DefaultTraverseEvaluator nextEvaluator = new DefaultTraverseEvaluator(path.tail()); + + Evaluation.Result result = Evaluation.Result.DENY_CONTINUE; + if(head == _pos){ + result = Evaluation.Result.ACCEPT_BREAK; + } + + return new DefaultEvaluation(result,nextEvaluator); } @Override
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/DefaultTraverser.java Mon Dec 10 18:50:53 2012 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/DefaultTraverser.java Fri Dec 14 20:10:48 2012 +0900 @@ -33,15 +33,15 @@ for(Node child : _current.getChildren()){ Evaluation e = _evaluator.eval(currentPath,child,pos); - long result = e.result(); + Evaluation.Result result = e.result(); - if(result == TraverseEvaluator.ACCEPT_AND_CONTINUE || - result == TraverseEvaluator.ACCEPT_AND_BREAK){ + if(result == Evaluation.Result.ACCEPT_CONTINUE || + result == Evaluation.Result.ACCEPT_BREAK){ accepted = accepted.snoc(P.p(child,e)); } - if(result == TraverseEvaluator.DENY_AND_BREAK || - result == TraverseEvaluator.ACCEPT_AND_BREAK){ + if(result == Evaluation.Result.DENY_BREAK || + result == Evaluation.Result.ACCEPT_BREAK){ break; } }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/Evaluation.java Mon Dec 10 18:50:53 2012 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/Evaluation.java Fri Dec 14 20:10:48 2012 +0900 @@ -2,11 +2,11 @@ public interface Evaluation { - public static final long ACCEPT_CONTINUE = 0; - public static final long DENY_CONTINUE = 1; - public static final long ACCEPT_BREAK = 2; - public static final long DENY_BREAK = 3; + public Evaluation.Result result(); + public TraverseEvaluator evaluator(); - public long result(); - public TraverseEvaluator evaluator(); + public static enum Result + { + ACCEPT_CONTINUE,DENY_CONTINUE,ACCEPT_BREAK,DENY_BREAK; + } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/Traversable.java Fri Dec 14 20:10:48 2012 +0900 @@ -0,0 +1,6 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser; + +public interface Traversable +{ + public Iterable<TraverseResult> traverse(TraverseEvaluator _e); +}