Mercurial > hg > Members > tatsuki > bench > jungle-core
view src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/PutIndexEditor.java @ 143:afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
bag
author | one |
---|---|
date | Sat, 15 Nov 2014 17:48:07 +0900 |
parents | 99bda30ea72c |
children |
line wrap: on
line source
package jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index; import fj.Ord; import fj.data.List; import fj.data.Option; import fj.data.TreeMap; 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.TreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.TreeOperationLog; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.IndexJungleTreeEditor; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.TransactionManager; 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 java.nio.ByteBuffer; public class PutIndexEditor implements IndexEditor { String key; String attribute; NodePath path; TransactionManager txManager; TreeNode root; TreeEditor editor; TreeOperationLog log; public PutIndexEditor(String key, ByteBuffer attribute,NodePath path) { this.key = key; this.attribute = new String(attribute.array()); this.path = path; } @Override public Either<Error, IndexJungleTreeEditor> edit(TreeNode root,TransactionManager txManager,TreeEditor editor,TreeOperationLog log,TreeMap<String, TreeMap<String, List<NodePath>>> index) { TreeMap<String, TreeMap<String, List<NodePath>>> newIndex = editIndex(path, key, attribute,index); IndexJungleTreeEditor newEditor = new IndexJungleTreeEditor(root,txManager,editor,log, newIndex); Either<Error, IndexJungleTreeEditor> either = DefaultEither.newB(newEditor); return either; } public TreeMap<String, TreeMap<String, List<NodePath>>> editIndex(NodePath path, String key, String attribute,TreeMap<String, TreeMap<String, List<NodePath>>> index){ Option<TreeMap<String, List<NodePath>>> innerIndexOp = index.get(key); if (attribute != null) { if (innerIndexOp.isNone()) { TreeMap<String, List<NodePath>> innerIndex = TreeMap.empty(Ord.stringOrd); List<NodePath> list = List.nil(); list = list.cons(path); innerIndex = innerIndex.set(attribute, list); TreeMap<String, TreeMap<String, List<NodePath>>> newIndex = index.set(key, innerIndex); return newIndex; } else { TreeMap<String, List<NodePath>> innerIndex = innerIndexOp.some(); Option<List<NodePath>> opList = innerIndex.get(attribute); if (opList.isNone()) { List<NodePath> list = List.nil(); list = list.cons(path); innerIndex = innerIndex.set(attribute, list); } else { List<NodePath> list = opList.some(); list = list.cons(path); innerIndex = innerIndex.set(attribute, list); } TreeMap<String, TreeMap<String, List<NodePath>>> newIndex = index.set(key, innerIndex); return newIndex; } } return index; } // public TreeNode getTarget(TreeNode node , NodePath path){ // Pair<Integer, NodePath> path = path.pop(); // Either<Error, TreeNode> either = node.getChildren().at(path.left()); // if (either.isA()) // return node; // // TreeNode child = either.b(); // if (path.right().size() == 0) // return child; // // TreeNode target = getTarget(child,path.right()); // return target; // } }