comparison src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/AddNewChildrenIndexEditor.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 ec166c8ff079
children
comparison
equal deleted inserted replaced
142:ef183969bf31 143:afbe19c98f53
1 package jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index; 1 package jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index;
2 2
3 import java.util.Iterator;
4 3
5 import fj.F;
6 import fj.Ord; 4 import fj.Ord;
7 import fj.P2;
8 import fj.data.List; 5 import fj.data.List;
9 import fj.data.Option;
10 import fj.data.TreeMap; 6 import fj.data.TreeMap;
11 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor;
12 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; 7 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath;
13 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TreeEditor; 8 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TreeEditor;
14 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath; 9 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath;
15 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; 10 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode;
16 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.TreeOperationLog; 11 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.TreeOperationLog;
33 public Either<Error, IndexJungleTreeEditor> edit( 28 public Either<Error, IndexJungleTreeEditor> edit(
34 TreeNode root, 29 TreeNode root,
35 TransactionManager txManager, 30 TransactionManager txManager,
36 TreeEditor editor, 31 TreeEditor editor,
37 TreeOperationLog log, 32 TreeOperationLog log,
38 TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index) { 33 TreeMap<String, TreeMap<String, List<NodePath>>> index) {
39 34
40 TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> newIndex = editIndex(index); 35 TreeMap<String, TreeMap<String, List<NodePath>>> newIndex = editIndex(index);
41 IndexJungleTreeEditor newEditor = new IndexJungleTreeEditor(root, txManager, editor, newIndex); 36 IndexJungleTreeEditor newEditor = new IndexJungleTreeEditor(root, txManager, editor, newIndex);
42 return DefaultEither.newB(newEditor); 37 return DefaultEither.newB(newEditor);
43 } 38 }
44 39
45 public TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> editIndex( 40 public TreeMap<String, TreeMap<String, List<NodePath>>> editIndex(
46 TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index) { 41 TreeMap<String, TreeMap<String, List<NodePath>>> index) {
47 42
48 if (!index.isEmpty()) { 43 if (!index.isEmpty()) {
49 List<String> keyList = index.keys(); 44 List<String> keyList = index.keys();
50 TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> newIndex = TreeMap.empty(Ord.stringOrd); 45 TreeMap<String, TreeMap<String, List<NodePath>>> newIndex = TreeMap.empty(Ord.stringOrd);
51 TreeMap<String, List<Pair<TreeNode, NodePath>>> newInnerIndex = TreeMap.empty(Ord.stringOrd); 46 TreeMap<String, List<NodePath>> newInnerIndex = TreeMap.empty(Ord.stringOrd);
52 47
53 for (String indexKey : keyList) { 48 for (String indexKey : keyList) {
54 TreeMap<String, List<Pair<TreeNode, NodePath>>> innerIndex = index.get(indexKey).some(); 49 TreeMap<String, List<NodePath>> innerIndex = index.get(indexKey).some();
55 List<String> innerIndexKeyList = innerIndex.keys(); 50 List<String> innerIndexKeyList = innerIndex.keys();
56 51
57 for (String innerIndexKey : innerIndexKeyList) { 52 for (String innerIndexKey : innerIndexKeyList) {
58 List<Pair<TreeNode, NodePath>> pairList = innerIndex.get(innerIndexKey).some(); 53 List<NodePath> pairList = innerIndex.get(innerIndexKey).some();
59 List<Pair<TreeNode, NodePath>> list = checkPath(pairList); 54 List<NodePath> list = checkPath(pairList);
60 if (!list.isEmpty()){ 55 if (!list.isEmpty()){
61 //System.out.println(new String(list.head().left().getAttributes().get("KEY").array())); 56 //System.out.println(new String(list.head().left().getAttributes().get("KEY").array()));
62 newInnerIndex = newInnerIndex.set(innerIndexKey, list); 57 newInnerIndex = newInnerIndex.set(innerIndexKey, list);
63 } 58 }
64 } 59 }
68 } else { 63 } else {
69 return index; 64 return index;
70 } 65 }
71 } 66 }
72 67
73 public List<Pair<TreeNode, NodePath>> checkPath(List<Pair<TreeNode, NodePath>> pairList){ 68 public List<NodePath> checkPath(List<NodePath> pairList){
74 69
75 List<Pair<TreeNode, NodePath>> list = List.nil(); 70 List<NodePath> list = List.nil();
76 for (Pair<TreeNode, NodePath> pair : pairList) { 71 for (NodePath path : pairList) {
77 72
78 NodePath path = pair.right(); 73
79 //System.out.println("oldPath = " + path.toString()); 74 //System.out.println("oldPath = " + path.toString());
80 NodePath newPath = new DefaultNodePath(); 75 NodePath newPath = new DefaultNodePath();
81 76
82 77
83 if (editNodePath.size() > path.size()) { 78 if (editNodePath.size() > path.size()) {
84 list = list.cons(pair); 79 list = list.cons(path);
85 continue; 80 continue;
86 } 81 }
87 82
88 Pair<Integer, NodePath> editNodePathCopy = editNodePath.pop(); 83 Pair<Integer, NodePath> editNodePathCopy = editNodePath.pop();
89 int loopCount = 0; 84 int loopCount = 0;
111 newPath = newPath.add(pathInt); 106 newPath = newPath.add(pathInt);
112 107
113 } 108 }
114 109
115 //System.out.println("newPath = " + newPath.toString()); 110 //System.out.println("newPath = " + newPath.toString());
116 Pair<TreeNode, NodePath> newPair = new Pair<TreeNode, NodePath>(pair.left(), newPath); 111 list = list.cons(path);
117 list = list.cons(newPair);
118 } 112 }
119 113
120 return list; 114 return list;
121 } 115 }
122 116