Mercurial > hg > Members > tatsuki > bench > jungle-core
changeset 156:c23f70bb791f untilIndex
change Index fj → java.until
author | one |
---|---|
date | Sun, 07 Dec 2014 15:24:30 +0900 |
parents | 54b13df9cd87 |
children | f98f2704b154 |
files | pom.xml src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/Index.java src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/ParentIndex.java |
diffstat | 3 files changed, 40 insertions(+), 60 deletions(-) [+] |
line wrap: on
line diff
--- a/pom.xml Sun Dec 07 14:54:27 2014 +0900 +++ b/pom.xml Sun Dec 07 15:24:30 2014 +0900 @@ -34,7 +34,7 @@ <dependency> <groupId>org.functionaljava</groupId> <artifactId>functionaljava</artifactId> - <version>3.1</version> + <version>4.1</version> </dependency> <dependency> <groupId>org.apache.maven.surefire</groupId>
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/Index.java Sun Dec 07 14:54:27 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/Index.java Sun Dec 07 15:24:30 2014 +0900 @@ -1,21 +1,16 @@ package jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index; import java.util.Iterator; - -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NulIterator; +import java.util.TreeMap; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; -import fj.Ord; -import fj.P2; import fj.data.List; -import fj.data.Option; -import fj.data.TreeMap; public class Index { TreeMap<String, TreeMap<String, List<TreeNode>>> indexList; public Index() { - this.indexList = TreeMap.empty(Ord.stringOrd); + this.indexList = new TreeMap<String, TreeMap<String, List<TreeNode>>>(); } public Index(TreeMap<String, TreeMap<String, List<TreeNode>>> indexList) { @@ -27,33 +22,29 @@ } public Index set(String key, String value, TreeNode node) { - Option<TreeMap<String, List<TreeNode>>> indexOp = indexList.get(key); - if (indexOp.isNone()) { - TreeMap<String, List<TreeNode>> index = TreeMap.empty(Ord.stringOrd); + TreeMap<String, List<TreeNode>> index = indexList.get(key); + if (index == null) { + index = new TreeMap<String, List<TreeNode>>(); List<TreeNode> nodeList = List.nil(); List<TreeNode> newNodeList = nodeList.cons(node); - TreeMap<String, List<TreeNode>> newIndex = index.set(value, newNodeList); - TreeMap<String, TreeMap<String, List<TreeNode>>> newIndexList = indexList.set(key, newIndex); - - - return new Index(newIndexList); + index.put(value, newNodeList); + indexList.put(key,index); + return this; } - TreeMap<String, List<TreeNode>> index = indexOp.some(); - Option<List<TreeNode>> nodeListOp = index.get(value); + List<TreeNode> nodeList = index.get(value); List<TreeNode> newNodeList; - if (nodeListOp.isSome()) { - List<TreeNode> nodeList = nodeListOp.some(); + if (nodeList != null) { newNodeList = nodeList.cons(node); } else { - List<TreeNode> nodeList = List.nil(); + nodeList = List.nil(); newNodeList = nodeList.cons(node); } - TreeMap<String, List<TreeNode>> newIndex = index.set(value, newNodeList); - TreeMap<String, TreeMap<String, List<TreeNode>>> newIndexList = indexList.set(key, newIndex); + index.put(value, newNodeList); + indexList.put(key, index); - return new Index(newIndexList); + return this; } @@ -85,36 +76,29 @@ public List<TreeNode> get(String key, String value) { - Option<TreeMap<String, List<TreeNode>>> indexOp = indexList.get(key); - if (indexOp.isNone()) + TreeMap<String, List<TreeNode>> index = indexList.get(key); + if (index == null) return null; - TreeMap<String, List<TreeNode>> index = indexOp.some(); - Option<List<TreeNode>> nodeListOp = index.get(value); + List<TreeNode> nodeList = index.get(value); - if (nodeListOp.isNone()) + if (nodeList == null) return List.nil(); - return nodeListOp.some(); + return nodeList; } public Iterator<TreeNode> getAll(String key){ - Option<TreeMap<String, List<TreeNode>>> indexOp = indexList.get(key); - if (indexOp.isNone()) + TreeMap<String, List<TreeNode>> index = indexList.get(key); + if (index == null) return null; - TreeMap<String, List<TreeNode>> index = indexOp.some(); - if (!index.isEmpty()) - return new NulIterator<TreeNode>(); - - return new Iterator<TreeNode>(){ - Iterator<P2<String, List<TreeNode>>> treeMapIterator = index.iterator(); + Iterator<String> treeMapKeys = index.keySet().iterator(); List<TreeNode> nodeList = List.nil(); TreeNode node; - @Override public boolean hasNext() { @@ -124,8 +108,9 @@ return true; } - for (;treeMapIterator.hasNext();) { - nodeList = treeMapIterator.next()._2(); + for (;treeMapKeys.hasNext();) { + String key = treeMapKeys.next(); + nodeList = index.get(key); node = nodeList.head(); nodeList = nodeList.tail(); return true;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/ParentIndex.java Sun Dec 07 14:54:27 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/ParentIndex.java Sun Dec 07 15:24:30 2014 +0900 @@ -1,20 +1,18 @@ package jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index; import java.util.Iterator; - +import java.util.TreeMap; 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.TreeMapOrd; -import fj.data.Option; -import fj.data.TreeMap; + public class ParentIndex { private final TreeMap<TreeNode, TreeNode> parentIndex; public ParentIndex() { - parentIndex = TreeMap.empty(TreeMapOrd.treeNodeOrd); + parentIndex = new TreeMap<TreeNode,TreeNode>(); } public ParentIndex(TreeMap<TreeNode, TreeNode> parentIndex) { @@ -33,47 +31,44 @@ } public TreeNode get(TreeNode child) { - Option<TreeNode> parentOp = parentIndex.get(child); - if (parentOp.isSome()) - return parentOp.some(); + TreeNode parent = parentIndex.get(child); + if (parent != null) + return parent; return null; } public ParentIndex set(TreeNode parent) { Iterator<TreeNode> childrenIterator = parent.getChildren().iterator(); - TreeMap<TreeNode, TreeNode> newParentIndex = parentIndex; for (; childrenIterator.hasNext();) { TreeNode child = childrenIterator.next(); - newParentIndex = newParentIndex.set(child, parent); + parentIndex.put(child, parent); } - return new ParentIndex(newParentIndex); + return this; } public ParentIndex delete(TreeNode child) { - TreeMap<TreeNode, TreeNode> newParentIndex = parentIndex.delete(child); - return new ParentIndex(newParentIndex); + parentIndex.remove(child); + return this; } public ParentIndex deleteAllChildren(TreeNode parentNode) { TreeNodeChildren children = parentNode.getChildren(); Iterator<TreeNode> childrenIterator = children.iterator(); - TreeMap<TreeNode, TreeNode> newParentIndex = parentIndex; for (; childrenIterator.hasNext();) { TreeNode child = childrenIterator.next(); - newParentIndex = newParentIndex.delete(child); + parentIndex.remove(child); } - return new ParentIndex(newParentIndex); + return this; } public ParentIndex addAllChildren(TreeNode parentNode) { TreeNodeChildren children = parentNode.getChildren(); Iterator<TreeNode> childrenIterator = children.iterator(); - TreeMap<TreeNode, TreeNode> newParentIndex = parentIndex; for (; childrenIterator.hasNext();) { TreeNode child = childrenIterator.next(); - newParentIndex = newParentIndex.set(child, parentNode); + parentIndex.put(child, parentNode); } - return new ParentIndex(newParentIndex); + return this; } }