comparison src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/DeleteChildIndexEditor.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 6e9a8d26e0cf
children a2c374a2686b
comparison
equal deleted inserted replaced
142:ef183969bf31 143:afbe19c98f53
33 public Either<Error, IndexJungleTreeEditor> edit( 33 public Either<Error, IndexJungleTreeEditor> edit(
34 TreeNode root, 34 TreeNode root,
35 TransactionManager txManager, 35 TransactionManager txManager,
36 TreeEditor editor, 36 TreeEditor editor,
37 TreeOperationLog log, 37 TreeOperationLog log,
38 TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index) { 38 TreeMap<String, TreeMap<String, List<NodePath>>> index) {
39 39
40 TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> newIndex = editIndex(index); 40 TreeMap<String, TreeMap<String, List<NodePath>>> newIndex = editIndex(index);
41 IndexJungleTreeEditor newEditor = new IndexJungleTreeEditor(root, txManager, editor, newIndex); 41 IndexJungleTreeEditor newEditor = new IndexJungleTreeEditor(root, txManager, editor, newIndex);
42 return DefaultEither.newB(newEditor); 42 return DefaultEither.newB(newEditor);
43 } 43 }
44 44
45 public TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> editIndex( 45 public TreeMap<String, TreeMap<String, List<NodePath>>> editIndex(
46 TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index) { 46 TreeMap<String, TreeMap<String, List<NodePath>>> index) {
47 47
48 if (!index.isEmpty()) { 48 if (!index.isEmpty()) {
49 List<String> keyList = index.keys(); 49 List<String> keyList = index.keys();
50 TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> newIndex = TreeMap.empty(Ord.stringOrd); 50 TreeMap<String, TreeMap<String, List<NodePath>>> newIndex = TreeMap.empty(Ord.stringOrd);
51 TreeMap<String, List<Pair<TreeNode, NodePath>>> newInnerIndex = TreeMap.empty(Ord.stringOrd); 51 TreeMap<String, List<NodePath>> newInnerIndex = TreeMap.empty(Ord.stringOrd);
52 52
53 for (String indexKey : keyList) { 53 for (String indexKey : keyList) {
54 TreeMap<String, List<Pair<TreeNode, NodePath>>> innerIndex = index.get(indexKey).some(); 54 TreeMap<String, List<NodePath>> innerIndex = index.get(indexKey).some();
55 List<String> innerIndexKeyList = innerIndex.keys(); 55 List<String> innerIndexKeyList = innerIndex.keys();
56 56
57 for (String innerIndexKey : innerIndexKeyList) { 57 for (String innerIndexKey : innerIndexKeyList) {
58 List<Pair<TreeNode, NodePath>> pairList = innerIndex.get(innerIndexKey).some(); 58 List<NodePath> pairList = innerIndex.get(innerIndexKey).some();
59 List<Pair<TreeNode, NodePath>> list = checkPath(pairList); 59 List<NodePath> list = checkPath(pairList);
60 if (!list.isEmpty()){ 60 if (!list.isEmpty()){
61 System.out.println(new String(list.head().left().getAttributes().get("KEY").array()));
62 newInnerIndex = newInnerIndex.set(innerIndexKey, list); 61 newInnerIndex = newInnerIndex.set(innerIndexKey, list);
63 } 62 }
64 } 63 }
65 newIndex = newIndex.set(indexKey, newInnerIndex); 64 newIndex = newIndex.set(indexKey, newInnerIndex);
66 } 65 }
68 } else { 67 } else {
69 return index; 68 return index;
70 } 69 }
71 } 70 }
72 71
73 public List<Pair<TreeNode, NodePath>> checkPath(List<Pair<TreeNode, NodePath>> pairList){ 72 public List<NodePath> checkPath(List<NodePath> pairList){
74 73
75 List<Pair<TreeNode, NodePath>> list = List.nil(); 74 List<NodePath> list = List.nil();
76 for (Pair<TreeNode, NodePath> pair : pairList) { 75 for (NodePath path : pairList) {
77 76
78 NodePath path = pair.right();
79 System.out.println("oldPath = " + path.toString()); 77 System.out.println("oldPath = " + path.toString());
80 NodePath newPath = new DefaultNodePath(); 78 NodePath newPath = new DefaultNodePath();
81 79
82 if (path.toString().equals(editNodePath.toString())) { 80 if (path.toString().equals(editNodePath.toString())) {
83 continue; 81 continue;
84 } 82 }
85 83
86 if (editNodePath.size() > path.size()) { 84 if (editNodePath.size() > path.size()) {
87 list = list.cons(pair); 85 list = list.cons(path);
88 continue; 86 continue;
89 } 87 }
90 88
91 Pair<Integer, NodePath> editNodePathCopy = editNodePath.pop(); 89 Pair<Integer, NodePath> editNodePathCopy = editNodePath.pop();
92 int loopCount = 0; 90 int loopCount = 0;
113 newPath = newPath.add(pathInt); 111 newPath = newPath.add(pathInt);
114 112
115 } 113 }
116 114
117 System.out.println("newPath = " + newPath.toString()); 115 System.out.println("newPath = " + newPath.toString());
118 Pair<TreeNode, NodePath> newPair = new Pair<TreeNode, NodePath>( 116 list = list.cons(path);
119 pair.left(), newPath);
120 list = list.cons(newPair);
121 } 117 }
122 118
123 return list; 119 return list;
124 } 120 }
125 121