Mercurial > hg > Members > shoshi > jungle > jungle-core
changeset 205:89df000def32
change List but not clear test
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/list/List.java Tue May 19 12:07:24 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/list/List.java Tue May 19 12:59:39 2015 +0900 @@ -8,20 +8,31 @@ * 非破壊であるためこのListは逆順になっています */ public class List<T> implements Iterable<T> { - final Node<T> head; - final int listLength; + final private Node<T> head; + final private int listLength; public List() { this.head = new headNode(null); this.listLength = 0; } + public List(T... attributes) { + List<T> list = new List(); + for (T attribute : attributes) { + list = list.addLast(attribute); + } + this.head = list.getHead(); + this.listLength = head.getNext().getNum(); + } private List(Node<T> head) { this.head = head; this.listLength = head.getNext().getNum(); } + public Node<T> getHead() { + return head; + } public List<T> add(int num, T attribute) { Node<T> newNode = head.getNext().add(num, attribute); @@ -147,4 +158,6 @@ } return newList; } + + }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/DefaultJungle.java Tue May 19 12:07:24 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/DefaultJungle.java Tue May 19 12:59:39 2015 +0900 @@ -1,6 +1,7 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle; -import fj.data.List; + +import jp.ac.u_ryukyu.ie.cr.list.List; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeList; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.Journal; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.NullJournal; @@ -57,7 +58,7 @@ ChangeList list = new ChangeList() { @Override public Iterator<TreeOperation> iterator() { - List<TreeOperation> nil = List.nil(); + List<TreeOperation> nil = new List(); return nil.iterator(); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/DefaultJungleTree.java Tue May 19 12:07:24 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/DefaultJungleTree.java Tue May 19 12:59:39 2015 +0900 @@ -1,7 +1,6 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle; -import fj.data.List; -import jp.ac.u_ryukyu.ie.cr.treemap.TreeMap; +import jp.ac.u_ryukyu.ie.cr.list.List; 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.TreeContext; @@ -15,6 +14,7 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.GetOldTreeError; import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.ParentIndex; +import jp.ac.u_ryukyu.ie.cr.treemap.TreeMap; import java.util.concurrent.atomic.AtomicReference;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/JungleTree.java Tue May 19 12:07:24 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/JungleTree.java Tue May 19 12:59:39 2015 +0900 @@ -1,14 +1,14 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle; -import fj.data.List; -import jp.ac.u_ryukyu.ie.cr.treemap.TreeMap; +import jp.ac.u_ryukyu.ie.cr.list.List; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.InterfaceTraverser; 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.tatsuki.jungle.store.index.ParentIndex; +import jp.ac.u_ryukyu.ie.cr.treemap.TreeMap; public interface JungleTree { public JungleTreeEditor getTreeEditor();
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/TreeContext.java Tue May 19 12:07:24 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/TreeContext.java Tue May 19 12:59:39 2015 +0900 @@ -1,13 +1,13 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store; -import fj.data.List; -import jp.ac.u_ryukyu.ie.cr.treemap.TreeMap; +import jp.ac.u_ryukyu.ie.cr.list.List; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeList; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.InterfaceTraverser; import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.ParentIndex; +import jp.ac.u_ryukyu.ie.cr.treemap.TreeMap; public interface TreeContext { public TreeNode getRoot();
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultTreeEditor.java Tue May 19 12:07:24 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultTreeEditor.java Tue May 19 12:59:39 2015 +0900 @@ -1,6 +1,7 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl; -import fj.data.List; + +import jp.ac.u_ryukyu.ie.cr.list.List; 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.logger.LoggingNode; @@ -41,9 +42,9 @@ { // copying nodes from bottom to root - List<Direction<TreeNode>> path = List.nil(); + List<Direction<TreeNode>> path = new List(); for(Direction<TreeNode> direction : t){ - path = path.cons(direction); + path = path.addLast(direction); } // target @@ -61,7 +62,7 @@ TreeNode child = newWrap.getWrap(); - for(Direction<TreeNode> parentDirection : path.tail()){ + for(Direction<TreeNode> parentDirection : path.deleteLast()){ TreeNodeChildren chs = parentDirection.getTarget().getChildren();
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/IndexTreeEditor.java Tue May 19 12:07:24 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/IndexTreeEditor.java Tue May 19 12:59:39 2015 +0900 @@ -1,9 +1,7 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl; - - -import fj.data.List; +import jp.ac.u_ryukyu.ie.cr.list.List; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; 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; @@ -44,9 +42,9 @@ private Either<Error,LoggingNode> clone(Traversal t,NodeEditor editor) { // copying nodes from bottom to root - List<Direction<TreeNode>> path = List.nil(); + List<Direction<TreeNode>> path = new List(); for (Direction<TreeNode> direction : t) { - path = path.cons(direction); + path = path.addLast(direction); } // target @@ -64,7 +62,7 @@ int pos = targetDirection.getPosition(); TreeNode child = newWrap.getWrap(); - for (Direction<TreeNode> parentDirection : path.tail()) { + for (Direction<TreeNode> parentDirection : path.deleteLast()) { TreeNode updateTargetNode = parentDirection.getTarget(); TreeNodeChildren chs = updateTargetNode.getChildren();
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/TreeNodeChildren.java Tue May 19 12:07:24 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/TreeNodeChildren.java Tue May 19 12:59:39 2015 +0900 @@ -1,6 +1,6 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl; -import fj.data.List; +import jp.ac.u_ryukyu.ie.cr.list.List; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Children; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/logger/DefaultOperationLog.java Tue May 19 12:07:24 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/logger/DefaultOperationLog.java Tue May 19 12:59:39 2015 +0900 @@ -1,6 +1,7 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger; -import fj.data.List; + +import jp.ac.u_ryukyu.ie.cr.list.List; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation; import java.util.Iterator; @@ -9,7 +10,7 @@ { private final List<NodeOperation> log; - private static final List<NodeOperation> EMPTY = List.nil(); + private static final List<NodeOperation> EMPTY =new List<>(); public DefaultOperationLog() { @@ -31,7 +32,7 @@ @Override public DefaultOperationLog add(NodeOperation _op) { - return new DefaultOperationLog(log.snoc(_op)); + return new DefaultOperationLog(log.addLast(_op)); } @Override
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/logger/DefaultTreeOperationLog.java Tue May 19 12:07:24 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/logger/DefaultTreeOperationLog.java Tue May 19 12:59:39 2015 +0900 @@ -1,15 +1,14 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger; -import java.util.Iterator; - import com.google.common.collect.Iterables; -import fj.data.List; - +import jp.ac.u_ryukyu.ie.cr.list.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; +import java.util.Iterator; + public class DefaultTreeOperationLog implements TreeOperationLog { private final Iterable<TreeOperation> list; @@ -17,7 +16,7 @@ public DefaultTreeOperationLog() { - list = List.nil(); + list = new List<>(); size = 0; } @@ -37,7 +36,7 @@ public TreeOperationLog add(NodePath _p, NodeOperation _op) { TreeOperation op = new DefaultTreeOperation(_p,_op); - List<TreeOperation> newList = List.list(op); + List<TreeOperation> newList = new List(op); Iterable<TreeOperation> concat = Iterables.concat(list,newList); return new DefaultTreeOperationLog(concat,size + 1);
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTreeContext.java Tue May 19 12:07:24 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTreeContext.java Tue May 19 12:59:39 2015 +0900 @@ -1,13 +1,14 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction; -import fj.data.List; -import jp.ac.u_ryukyu.ie.cr.treemap.TreeMap; + +import jp.ac.u_ryukyu.ie.cr.list.List; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeList; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TreeContext; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.InterfaceTraverser; import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.ParentIndex; +import jp.ac.u_ryukyu.ie.cr.treemap.TreeMap; public class DefaultTreeContext implements TreeContext { private final TreeNode root;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTreeNode.java Tue May 19 12:07:24 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTreeNode.java Tue May 19 12:59:39 2015 +0900 @@ -1,6 +1,7 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction; -import fj.data.List; + +import jp.ac.u_ryukyu.ie.cr.list.List; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNodeChildren; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; @@ -15,7 +16,7 @@ private TreeMap<String, ByteBuffer> attrs; final String nodeId = new VMID().toString(); - private static final List<TreeNode> NIL_LIST = List.nil(); + private static final List<TreeNode> NIL_LIST = new List(); public DefaultTreeNode() { this(NIL_LIST, new TreeMap());
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTreeNodeAttribute.java Tue May 19 12:07:24 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTreeNodeAttribute.java Tue May 19 12:59:39 2015 +0900 @@ -1,6 +1,6 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction; -import fj.data.List; +import jp.ac.u_ryukyu.ie.cr.list.List; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNodeAttributes; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.NodeEditorError;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTreeNodeChildren.java Tue May 19 12:07:24 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTreeNodeChildren.java Tue May 19 12:59:39 2015 +0900 @@ -1,7 +1,7 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction; -import fj.P2; -import fj.data.List; + +import jp.ac.u_ryukyu.ie.cr.list.List; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNodeChildren; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.NodeEditorError; @@ -13,122 +13,96 @@ import java.nio.ByteBuffer; import java.util.Iterator; -public class DefaultTreeNodeChildren implements TreeNodeChildren -{ - 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()); - - } - - public List<TreeNode> children; - public TreeMap<String,ByteBuffer> attrs; +public class DefaultTreeNodeChildren implements TreeNodeChildren { + + public List<TreeNode> children; + public TreeMap<String, ByteBuffer> attrs; - public DefaultTreeNodeChildren(List<TreeNode> _children,TreeMap<String,ByteBuffer> _attrs) - { - children = _children; - attrs = _attrs; - } - - private boolean boundaryCheck(int _pos) - { - int size = children.length(); - if(size < _pos){ - return false; - } - - return true; - } + public DefaultTreeNodeChildren(List<TreeNode> _children, TreeMap<String, ByteBuffer> _attrs) { + children = _children; + attrs = _attrs; + } - @Override - public List<TreeNode> getChildrenAsRawList(){ - return children; - } - - @Override - public Either<Error,TreeNode> addNewChildAt(int _pos) - { - if(!boundaryCheck(_pos) || _pos < 0){ - return DefaultEither.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); - } - - P2<List<TreeNode>,List<TreeNode>> split = children.splitAt(_pos); - List<TreeNode> newChildren = split._1().snoc(new DefaultTreeNode()).append(split._2()); - TreeNode newNode = new DefaultTreeNode(newChildren,attrs); - return DefaultEither.newB(newNode); - } + private boolean boundaryCheck(int _pos) { + int size = children.length(); + if (size < _pos) { + return false; + } + + return true; + } - @Override - public Either<Error,TreeNode> deleteChildAt(int _pos) - { - if(!boundaryCheck(_pos) || _pos < 0 || size() == 0){ - return DefaultEither.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); - } - - P2<List<TreeNode>,List<TreeNode>> split = children.splitAt(_pos); - List<TreeNode> newChildren = split._1().append(split._2().tail()); - TreeNode newNode = new DefaultTreeNode(newChildren,attrs); - - return DefaultEither.newB(newNode); - } + @Override + public List<TreeNode> getChildrenAsRawList() { + return children; + } - @Override - public int size() - { - return children.length(); - } + @Override + public Either<Error, TreeNode> addNewChildAt(int _pos) { + if (!boundaryCheck(_pos) || _pos < 0) { + return DefaultEither.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); + } - @Override - public Iterator<TreeNode> iterator() - { - return children.iterator(); - } + List<TreeNode> newChildren = children.add(_pos, new DefaultTreeNode()); + TreeNode newNode = new DefaultTreeNode(newChildren, attrs); + return DefaultEither.newB(newNode); + } - @Override - public Either<Error,TreeNode> replaceNode(int _pos,TreeNode _replacement) - { - int size = children.length(); - if(!(0 <= _pos && _pos < size)){ - return DefaultEither.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); - } - TreeNode replacement = _replacement; - - P2<List<TreeNode>,List<TreeNode>> split = children.splitAt(_pos + 1); - List<TreeNode> init = split._1().reverse().tail().reverse(); - List<TreeNode> newInit = init.snoc(replacement); - List<TreeNode> newList = newInit.append(split._2()); - TreeNode node = new DefaultTreeNode(newList,attrs); - return DefaultEither.newB(node); - } + @Override + public Either<Error, TreeNode> deleteChildAt(int _pos) { + if (!boundaryCheck(_pos) || _pos < 0 || size() == 0) { + return DefaultEither.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); + } - @Override - public Either<Error,TreeNode> at(int _pos) - { - if(children.length() < _pos + 1){ - return DefaultEither.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); + List<TreeNode> newChildren = children.delete(_pos); + TreeNode newNode = new DefaultTreeNode(newChildren, attrs); + + return DefaultEither.newB(newNode); } - TreeNode Node = children.index(_pos); - - return DefaultEither.newB(Node); - } + @Override + public int size() { + return children.length(); + } + + @Override + public Iterator<TreeNode> iterator() { + return children.iterator(); + } + + @Override + public Either<Error, TreeNode> replaceNode(int _pos, TreeNode _replacement) { + int size = children.length(); + if (!(0 <= _pos && _pos < size)) { + return DefaultEither.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); + } + TreeNode replacement = _replacement; - @Override - public Either<Error,TreeNode> addNewChildAt(int _pos,TreeNode _newChild) - { - if(!boundaryCheck(_pos) || _pos < 0){ - return DefaultEither.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); - } - - - P2<List<TreeNode>,List<TreeNode>> split = children.splitAt(_pos); - List<TreeNode> newChildren = split._1().snoc(_newChild).append(split._2()); - TreeNode newNode = new DefaultTreeNode(newChildren,attrs); - - return DefaultEither.newB(newNode); - } + List<TreeNode> newChildren = children.replace(_pos, replacement); + TreeNode node = new DefaultTreeNode(newChildren, attrs); + return DefaultEither.newB(node); + } + + @Override + public Either<Error, TreeNode> at(int _pos) { + if (children.length() < _pos + 1) { + return DefaultEither.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); + } + + TreeNode Node = children.index(_pos); + + return DefaultEither.newB(Node); + } + + @Override + public Either<Error, TreeNode> addNewChildAt(int _pos, TreeNode _newChild) { + if (!boundaryCheck(_pos) || _pos < 0) { + return DefaultEither.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); + } + List<TreeNode> newChildren = children.add(_pos, _newChild); + TreeNode newNode = new DefaultTreeNode(newChildren, attrs); + + return DefaultEither.newB(newNode); + } }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/DefaultTraverser.java Tue May 19 12:07:24 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/DefaultTraverser.java Tue May 19 12:59:39 2015 +0900 @@ -1,14 +1,15 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser; -import java.util.Iterator; - +import jp.ac.u_ryukyu.ie.cr.list.List; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Children; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; 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 fj.data.List; + +import java.util.Iterator; + public class DefaultTraverser implements Traverser { @@ -18,8 +19,8 @@ Children wrapper = new Children(){ @Override public Iterator<TreeNode> iterator(){ - List<TreeNode> list = List.nil(); - return list.cons(_root).iterator(); + List<TreeNode> list = new List(); + return list.addLast(_root).iterator(); } @Override @@ -109,8 +110,8 @@ } }; - List<Direction<TreeNode>> list = List.nil(); - List<Direction<TreeNode>> newList = list.cons(d); + List<Direction<TreeNode>> list = new List(); + List<Direction<TreeNode>> newList = list.addLast(d); return newList; } @@ -137,7 +138,7 @@ } }; - List<Direction<TreeNode>> newList = list.cons(d); + List<Direction<TreeNode>> newList = list.addLast(d); return DefaultEither.newB(newList); } }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/InterfaceTraverser.java Tue May 19 12:07:24 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/InterfaceTraverser.java Tue May 19 12:59:39 2015 +0900 @@ -1,16 +1,16 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser; -import java.util.Iterator; -import java.util.Optional; - -import fj.data.List; -import jp.ac.u_ryukyu.ie.cr.treemap.TreeMap; +import jp.ac.u_ryukyu.ie.cr.list.List; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NulIterator; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.query.PathNodeIterator; import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.query.Query; import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.IndexCreater; import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.ParentIndex; +import jp.ac.u_ryukyu.ie.cr.treemap.TreeMap; + +import java.util.Iterator; +import java.util.Optional; public class InterfaceTraverser {
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/IndexCreater.java Tue May 19 12:07:24 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/IndexCreater.java Tue May 19 12:59:39 2015 +0900 @@ -1,6 +1,7 @@ package jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index; -import fj.data.List; + +import jp.ac.u_ryukyu.ie.cr.list.List; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNodeChildren; import jp.ac.u_ryukyu.ie.cr.treemap.TreeMap; @@ -82,8 +83,8 @@ Optional<TreeMap<String, List<TreeNode>>> indexOp = indexList.get(key); if (!indexOp.isPresent()) { TreeMap<String, List<TreeNode>> index = new TreeMap(); - List<TreeNode> nodeList = List.nil(); - nodeList = nodeList.cons(node); + List<TreeNode> nodeList = new List(); + nodeList = nodeList.addLast(node); TreeMap<String, List<TreeNode>> newIndex = index.put(value, nodeList); indexList = indexList.put(key, newIndex); return indexList; @@ -95,11 +96,11 @@ List<TreeNode> newNodeList; if (nodeListOp.isPresent()) { - newNodeList = nodeListOp.get().cons(node); + newNodeList = nodeListOp.get().addLast(node); } else { - List<TreeNode> nodeList = List.nil(); - newNodeList = nodeList.cons(node); + List<TreeNode> nodeList = new List(); + newNodeList = nodeList.addLast(node); } TreeMap<String, List<TreeNode>> newIndex = index.put(value, newNodeList);
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/core/AttributesTest.java Tue May 19 12:07:24 2015 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/core/AttributesTest.java Tue May 19 12:59:39 2015 +0900 @@ -1,35 +1,33 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core; -import org.junit.Ignore; -import java.nio.ByteBuffer; -import fj.P2; -import fj.P; -import fj.data.List; +import jp.ac.u_ryukyu.ie.cr.list.List; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; import junit.framework.Assert; import junit.framework.TestCase; +import org.junit.Ignore; + +import java.nio.ByteBuffer; @Ignore -public abstract class AttributesTest extends TestCase -{ - @SuppressWarnings("unchecked") - public static List<P2<String,ByteBuffer>> ENTRIES = List.list( - P.p("KEY1",ByteBuffer.wrap("VALUE1".getBytes())), - P.p("KEY2",ByteBuffer.wrap("VALUE2".getBytes())), - P.p("KEY3",ByteBuffer.wrap("VALUE3".getBytes())) - ); - - public abstract Attributes instance(); - - public void testGet() - { - Attributes attrs = instance(); - - for(P2<String,ByteBuffer> entry : ENTRIES){ - String key = entry._1(); - ByteBuffer expect = entry._2(); - ByteBuffer actual = attrs.get(key); - Assert.assertNotNull(actual); - Assert.assertEquals(0,actual.compareTo(expect)); - } - } +public abstract class AttributesTest extends TestCase { + @SuppressWarnings("unchecked") + public static List<Pair<String, ByteBuffer>> ENTRIES = new List( + new Pair("KEY1", ByteBuffer.wrap("VALUE1".getBytes())), + new Pair("KEY2", ByteBuffer.wrap("VALUE2".getBytes())), + new Pair("KEY3", ByteBuffer.wrap("VALUE3".getBytes())) + ); + + public abstract Attributes instance(); + + public void testGet() { + Attributes attrs = instance(); + + for (Pair<String, ByteBuffer> entry : ENTRIES) { + String key = entry.left(); + ByteBuffer expect = entry.right(); + ByteBuffer actual = attrs.get(key); + Assert.assertNotNull(actual); + Assert.assertEquals(0, actual.compareTo(expect)); + } + } }
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/impl/clonable/DefaultTreeNodeAttributesTest.java Tue May 19 12:07:24 2015 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/impl/clonable/DefaultTreeNodeAttributesTest.java Tue May 19 12:59:39 2015 +0900 @@ -1,11 +1,12 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.impl.clonable; -import fj.P2; -import fj.data.List; + +import jp.ac.u_ryukyu.ie.cr.list.List; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Attributes; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.AttributesTest; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.DefaultTreeNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; import jp.ac.u_ryukyu.ie.cr.treemap.TreeMap; import junit.framework.TestCase; import junit.framework.TestSuite; @@ -24,11 +25,11 @@ public static DefaultTreeNode instance() { - List<TreeNode> rawList = List.nil(); + List<TreeNode> rawList = new List(); TreeMap<String,ByteBuffer> rawMap = new TreeMap(); - for(P2<String,ByteBuffer> entry : AttributesTest.ENTRIES){ - rawMap = rawMap.put(entry._1(),entry._2()); + for(Pair<String,ByteBuffer> entry : AttributesTest.ENTRIES){ + rawMap = rawMap.put(entry.left(),entry.right()); } return new DefaultTreeNode(rawList,rawMap);
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/impl/node/DefaultAttributesTest.java Tue May 19 12:07:24 2015 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/impl/node/DefaultAttributesTest.java Tue May 19 12:59:39 2015 +0900 @@ -1,11 +1,11 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.impl.node; -import fj.P2; -import fj.data.List; +import jp.ac.u_ryukyu.ie.cr.list.List; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.AttributesTest; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNodeAttributes; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.DefaultTreeNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; import jp.ac.u_ryukyu.ie.cr.treemap.TreeMap; import org.junit.Assert; @@ -16,13 +16,13 @@ { public TreeNodeAttributes instance() { - List<TreeNode> rawList = List.nil(); + List<TreeNode> rawList = new List(); TreeMap<String,ByteBuffer> rawMap = new TreeMap(); // add attributes - for(P2<String, ByteBuffer> entry : ENTRIES){ - rawMap = rawMap.put(entry._1(),entry._2()); + for(Pair<String, ByteBuffer> entry : ENTRIES){ + rawMap = rawMap.put(entry.left(),entry.right()); } TreeNode node = new DefaultTreeNode(rawList,rawMap); @@ -38,9 +38,9 @@ Assert.assertNotNull(rawMap); // testing rawmap has correct key values. - for(P2<String,ByteBuffer> entry : ENTRIES){ - String key = entry._1(); - ByteBuffer value = entry._2(); + for(Pair<String,ByteBuffer> entry : ENTRIES){ + String key = entry.left(); + ByteBuffer value = entry.right(); Optional<ByteBuffer> option = rawMap.get(key); if(!option.isPresent()){
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/impl/node/DefaultChildrenTest.java Tue May 19 12:07:24 2015 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/impl/node/DefaultChildrenTest.java Tue May 19 12:59:39 2015 +0900 @@ -1,6 +1,7 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.impl.node; -import fj.data.List; + +import jp.ac.u_ryukyu.ie.cr.list.List; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.ChildrenTest; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.DefaultTreeNode; @@ -16,9 +17,9 @@ @Override public DefaultTreeNodeChildren instance() { - List<TreeNode> rawList = List.nil(); + List<TreeNode> rawList = new List(); for(int i = 0;i < expectSize();i ++){ - rawList = rawList.cons(new DefaultTreeNode()); + rawList = rawList.addLast(new DefaultTreeNode()); } TreeMap<String,ByteBuffer> rawMap = new TreeMap();
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/impl/node/DefaultNodeTest.java Tue May 19 12:07:24 2015 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/impl/node/DefaultNodeTest.java Tue May 19 12:59:39 2015 +0900 @@ -1,6 +1,7 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.impl.node; -import fj.data.List; + +import jp.ac.u_ryukyu.ie.cr.list.List; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.DefaultTreeNode; import jp.ac.u_ryukyu.ie.cr.treemap.TreeMap; @@ -26,7 +27,7 @@ public static DefaultTreeNode instance() { - List<TreeNode> rawList = List.nil(); + List<TreeNode> rawList = new List(); TreeMap<String,ByteBuffer> rawMap = new TreeMap(); DefaultTreeNode node = new DefaultTreeNode(rawList,rawMap);
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/list/appendTest.java Tue May 19 12:07:24 2015 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/list/appendTest.java Tue May 19 12:59:39 2015 +0900 @@ -17,7 +17,7 @@ for (int count = 1; count <= 10; count++) { list = list.addLast(count); } - + List<Integer> list2 = new List<>(); for (int count = 11; count <= 20; count++) { list2 = list2.addLast(count);