Mercurial > hg > Members > tatsuki > bench > jungle-core
changeset 36:3dfa0be90a0d
mark
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/core/Attributes.java Sat Jan 26 00:25:17 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/core/Attributes.java Sat Jan 26 18:41:25 2013 +0900 @@ -1,8 +1,6 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core; -import java.nio.ByteBuffer; - -public interface Attributes +public interface Attributes<K,V> { - public ByteBuffer get(String _key); + public V get(K _key); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/core/AttributesContainer.java Sat Jan 26 18:41:25 2013 +0900 @@ -0,0 +1,6 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core; + +public interface AttributesContainer<K,V> +{ + public Attributes<K,V> getAttributes(); +}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/core/Children.java Sat Jan 26 00:25:17 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/core/Children.java Sat Jan 26 18:41:25 2013 +0900 @@ -1,6 +1,6 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core; -public interface Children extends Iterable<Node> +public interface Children<T> extends Iterable<T> { public int size(); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/core/Jungle.java Sat Jan 26 00:25:17 2013 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core; - -public interface Jungle -{ - public JungleTree getTree(String _name); -}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/core/JungleTree.java Sat Jan 26 00:25:17 2013 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core; - -public interface JungleTree -{ - public JungleNode getRoot(); -}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/core/Node.java Sat Jan 26 00:25:17 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/core/Node.java Sat Jan 26 18:41:25 2013 +0900 @@ -1,7 +1,7 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core; -public interface Node +import java.nio.ByteBuffer; + +public interface Node extends AttributesContainer<String,ByteBuffer> , Parent<Node> { - public Children getChildren(); - public Attributes getAttributes(); } \ No newline at end of file
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultAttributes.java Sat Jan 26 00:25:17 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultAttributes.java Sat Jan 26 18:41:25 2013 +0900 @@ -12,7 +12,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 DefaultAttributes implements EditableAttributes +public class DefaultAttributes implements EditableAttributes<DefaultNode> { private final TreeMap<String,ByteBuffer> attrs; private final List<DefaultNode> children; @@ -24,7 +24,7 @@ } @Override - public Either<Error,EditableNode> put(String _key,ByteBuffer _value) + public Either<Error,DefaultNode> put(String _key,ByteBuffer _value) { TreeMap<String,ByteBuffer> newAttrs = attrs.set(_key,_value); EditableNode newNode = new DefaultNode(children,newAttrs); @@ -45,4 +45,10 @@ return null; } + @Override + public Object get(Object _key) { + // TODO Auto-generated method stub + return null; + } + }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultModifiedTreeEditor.java Sat Jan 26 00:25:17 2013 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ -package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl; - -import fj.data.List; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeListWriter; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.Logger; - -public class DefaultModifiedTreeEditor extends DefaultTreeEditor -{ - private final List<Logger> logs; - - public DefaultModifiedTreeEditor(List<Logger> _logs,DefaultChangeSet _tip,ChangeListWriter _writer, TraverserProvider _tProvider) - { - super(_tip,_writer,_tProvider); - logs = _logs; - } - - @Override - public boolean success() - { - // commit to presistent provider - return false; - } -}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/TraversableChildrenWrapper.java Sat Jan 26 00:25:17 2013 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ -package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl; - -import java.util.Iterator; - -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableNode; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.TraversableChildren; - -public class TraversableChildrenWrapper<T extends EditableNode<T>> - implements TraversableChildren<TraversableNodeWrapper<T>> -{ - private final T node; - - public TraversableChildrenWrapper(T _node) - { - node = _node; - } - - @Override - public Iterator<TraversableNodeWrapper<T>> iterator() - { - return null; - } - - @Override - public int size() - { - return 0; - } -}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/TraversableNodeWrapper.java Sat Jan 26 00:25:17 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/TraversableNodeWrapper.java Sat Jan 26 18:41:25 2013 +0900 @@ -1,9 +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 java.util.Iterator; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Children; 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.util.IterableConverter; public class TraversableNodeWrapper<T extends EditableNode<T>> implements TraversableNode<TraversableNodeWrapper<T>> @@ -16,9 +18,33 @@ } @Override - public TraversableChildren<TraversableNodeWrapper<T>> children() + public Children<TraversableNodeWrapper<T>> getChildren() { - EditableChildren<T> children = wrap.getChildren(); - return new TraversableChildrenWrapper<TraversableNodeWrapper<T>>(children); + final Children<T> ch = wrap.getChildren(); + + return new Children<TraversableNodeWrapper<T>>(){ + + final IterableConverter.Converter<TraversableNodeWrapper<T>,T> converter = new IterableConverter.Converter<TraversableNodeWrapper<T>,T>(){ + @Override + public TraversableNodeWrapper<T> conv(T _b) + { + return new TraversableNodeWrapper<T>(_b); + } + }; + + final IterableConverter<TraversableNodeWrapper<T>,T> iterable = new IterableConverter<TraversableNodeWrapper<T>,T>(ch,converter); + + @Override + public Iterator<TraversableNodeWrapper<T>> iterator() + { + return iterable.iterator(); + } + + @Override + public int size() + { + return ch.size(); + } + }; } }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/logger/LoggingChildren.java Sat Jan 26 00:25:17 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/logger/LoggingChildren.java Sat Jan 26 18:41:25 2013 +0900 @@ -1,8 +1,6 @@ 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.Operation; @@ -12,10 +10,8 @@ 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; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.IterableWrapper; -public class LoggingChildren<T extends EditableNode<T>> - implements EditableChildren<LoggingNode<T>> +public class LoggingChildren<T extends EditableNode<T>> implements EditableChildren<LoggingNode<T>> { private final EditableChildren<T> wrap; private final Logger log; @@ -31,26 +27,21 @@ { return wrap.size(); } - - @Override - public Iterator<Node> iterator() - { - IterableWrapper<Node> wrapper = new IterableWrapper<Node>(wrap); - return wrapper.iterator(); - } @Override - public Iterator<LoggingNode<T>> iteratorWithType() + public Iterator<LoggingNode<T>> iterator() { - IterableConverter.Converter<LoggingNode<T>,EditableChildren<T>> converter - = new IterableConverter.Converter<LoggingNode<T>,EditableChildren<T>>(){ + 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>(wrap,converter); - - return iterable; + return iterable.iterator(); } - + @Override public Either<Error,LoggingNode<T>> addNewChildAt(final int _pos) {
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/util/Commitment.java Sat Jan 26 00:25:17 2013 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,94 +0,0 @@ -package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.util; - -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicReference; - -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; - -public final class Commitment -{ - private Commitment() - { - // - } - - public static <T> Pair<Publisher<T>,Value<T>> newInstance(T _draft,T _sub) - { - ValueWrapper<T> fail = new ValueWrapper<T>(_sub); - ValueWrapper<T> init = new ValueWrapper<T>(_sub); - ValueWrapper<T> draft = new ValueWrapper<T>(_draft); - AtomicReference<ValueWrapper<T>> value = new AtomicReference<ValueWrapper<T>>(init); - - Publisher<T> p = new Publisher<T>(value,draft,fail); - Value<T> v = new Value<T>(value,fail); - - return new Pair<Publisher<T>,Value<T>>(p,v); - } - - public static class Publisher<T> - { - private final AtomicReference<ValueWrapper<T>> value; - private final ValueWrapper<T> draft; - private final AtomicBoolean flag; - private final ValueWrapper<T> fail; - - Publisher(AtomicReference<ValueWrapper<T>> _value,ValueWrapper<T> _draft,ValueWrapper<T> _fail) - { - value = _value; - draft = _draft; - flag = new AtomicBoolean(false); - fail = _fail; - } - - public void commit() - { - if(flag.compareAndSet(true,false)){ - value.set(draft); - } - } - - public void fail() - { - if(flag.compareAndSet(true,false)){ - value.set(fail); - } - } - } - - public static class Value<T> - { - private final AtomicReference<ValueWrapper<T>> value; - private final ValueWrapper<T> fail; - - Value(AtomicReference<ValueWrapper<T>> _value,ValueWrapper<T> _fail) - { - value = _value; - fail = _fail; - } - - public T get() - { - return value.get().get(); - } - - public boolean isFail() - { - return (value.get() == fail); - } - } - - private static class ValueWrapper<T> - { - private final T object; - - public ValueWrapper(T _object) - { - object = _object; - } - - public T get() - { - return object; - } - } -}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/trasnformer/EditableAttributes.java Sat Jan 26 00:25:17 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/trasnformer/EditableAttributes.java Sat Jan 26 18:41:25 2013 +0900 @@ -2,12 +2,13 @@ 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 EditableNode<T>> - extends Attributes +public interface EditableAttributes<T extends Parent<T>> + extends Attributes<String,ByteBuffer> { 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 Sat Jan 26 00:25:17 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/trasnformer/EditableChildren.java Sat Jan 26 18:41:25 2013 +0900 @@ -1,18 +1,15 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer; -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.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 EditableNode<T>> - extends Children +public interface EditableChildren<T extends Parent<T>> extends Children<T> { public Either<Error,T> addNewChildAt(int _pos); public Either<Error,T> deleteChildAt(int _pos); - public Iterator<T> iteratorWithType(); public final Error OUT_OF_RANGE = new DefaultError(); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/trasnformer/EditableNode.java Sat Jan 26 00:25:17 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/trasnformer/EditableNode.java Sat Jan 26 18:41:25 2013 +0900 @@ -1,14 +1,14 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Node; +import java.nio.ByteBuffer; -public interface EditableNode<T extends EditableNode<T>> - extends Node +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.AttributesContainer; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Parent; + +public interface EditableNode<T extends Parent<T>> + extends AttributesContainer<String,ByteBuffer> , Parent<T> { - @Override public EditableAttributes<T> getAttributes(); - - @Override public EditableChildren<T> getChildren(); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/DefaultTraverser.java Sat Jan 26 00:25:17 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/DefaultTraverser.java Sat Jan 26 18:41:25 2013 +0900 @@ -2,6 +2,7 @@ import java.util.Iterator; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Children; 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; @@ -12,7 +13,7 @@ @Override public <T extends TraversableNode<T>> Either<Error,Traversal<T>> traverse(final T _root,Evaluator _evaluator) { - TraversableChildren<T> wrapper = new TraversableChildren<T>(){ + Children<T> wrapper = new Children<T>(){ @Override public Iterator<T> iterator(){ List<T> list = List.nil(); @@ -47,7 +48,7 @@ return DefaultEither.newB(traversal); } - private <T extends TraversableNode<T>> Either<Error,List<Direction<T>>> _traverse(TraversableChildren<T> _chs,Evaluator _evaluator) + private <T extends TraversableNode<T>> Either<Error,List<Direction<T>>> _traverse(Children<T> _chs,Evaluator _evaluator) { int pos = 0; for(T ch : _chs){ @@ -75,7 +76,7 @@ private <T extends TraversableNode<T>> Either<Error,List<Direction<T>>> _accept(final T _current,final int _pos,Evaluator _evaluator) { - TraversableChildren<T> chs = _current.children(); + Children<T> chs = _current.getChildren(); Either<Error,List<Direction<T>>> either = _traverse(chs,_evaluator); if(either.isA()){ return either;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/TraversableNode.java Sat Jan 26 00:25:17 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/TraversableNode.java Sat Jan 26 18:41:25 2013 +0900 @@ -1,6 +1,7 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser; -public interface TraversableNode<T> +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Parent; + +public interface TraversableNode<T> extends Parent<T> { - public TraversableChildren<T> children(); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/util/Parent.java Sat Jan 26 00:25:17 2013 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ -package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util; - -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Node; - -public interface Parent<T extends Parent<T>> -{ - public Children<T> succ(); -} - -interface Children<T extends Parent<T>> extends Iterable<T> -{ - -} - -interface A extends RecursiveType<B> -{ - public B succ(); -} - -interface B extends RecursiveType<A> -{ - public A succ(); -}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/util/TraversableWrapper.java Sat Jan 26 00:25:17 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/util/TraversableWrapper.java Sat Jan 26 18:41:25 2013 +0900 @@ -1,13 +1,13 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.TraversableChildren; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Children; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.TraversableNode; public class TraversableWrapper<T> implements TraversableNode<TraversableWrapper<T>> { @Override - public TraversableChildren<TraversableWrapper<T>> children() + public Children<TraversableWrapper<T>> getChildren() { return null; }