134
|
1 package jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.index;
|
|
2
|
|
3 import java.nio.ByteBuffer;
|
|
4
|
|
5 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath;
|
|
6 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath;
|
|
7 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode;
|
|
8 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.DefaultTreeNode;
|
|
9 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either;
|
|
10 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error;
|
|
11 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair;
|
|
12
|
|
13 import org.junit.Assert;
|
|
14 import org.junit.Test;
|
|
15
|
|
16 import fj.Ord;
|
|
17 import fj.data.List;
|
|
18 import fj.data.Option;
|
|
19 import fj.data.TreeMap;
|
|
20
|
|
21 public class IndexFormTest {
|
|
22
|
|
23 TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index = TreeMap
|
|
24 .empty(Ord.stringOrd);
|
|
25
|
|
26 @Test
|
|
27 public void IndexFormTest() {
|
|
28
|
|
29 NodePath path = new DefaultNodePath();
|
|
30 TreeNode node = createTree(3, 0, 3, path);
|
|
31 TreeMap<String, List<Pair<TreeNode, NodePath>>> map = index.get(key).some();
|
|
32 Option<List<Pair<TreeNode, NodePath>>> opList = map.get("<-1,0,0,2>");
|
|
33 List<Pair<TreeNode, NodePath>> list = opList.some();
|
|
34 Pair<TreeNode, NodePath> Pair = list.head();
|
|
35 NodePath newPath = Pair.right();
|
|
36 String pathStr = newPath.toString();
|
|
37 Assert.assertEquals(pathStr,"<-1,0,0,2>");
|
|
38 System.out.println("aaa");
|
|
39 }
|
|
40
|
|
41 public static String key = "KEY";
|
|
42 public static ByteBuffer value = ByteBuffer.wrap(key.getBytes());
|
|
43 public static DefaultTreeNode factory = new DefaultTreeNode();
|
|
44
|
|
45 public TreeNode createTree(int _curX, int _curY, int _maxHeight,
|
|
46 NodePath _address) {
|
|
47 TreeNode parent = factory.createNewNode();
|
|
48 Either<Error, TreeNode> either = parent.getAttributes().put(key,ByteBuffer.wrap(_address.toString().getBytes()));
|
|
49 if (either.isA()) {
|
|
50 Assert.fail();
|
|
51 }
|
|
52 editIndex(parent, _address, _address.toString(), key);
|
|
53 parent = either.b();
|
|
54
|
|
55 if (_curY == _maxHeight) {
|
|
56 return parent;
|
|
57 }
|
|
58
|
|
59 for (int i = 0; i < _curY + 1; i++) {
|
|
60 TreeNode ch = createTree(i, _curY + 1, _maxHeight, _address.add(i));
|
|
61 either = parent.getChildren().addNewChildAt(i, ch);
|
|
62 if (either.isA()) {
|
|
63 Assert.fail();
|
|
64 }
|
|
65
|
|
66 parent = either.b();
|
|
67 }
|
|
68
|
|
69 return parent;
|
|
70 }
|
|
71
|
|
72
|
|
73 public void editIndex(TreeNode node, NodePath path, String attribute,String key) {
|
|
74
|
|
75 Pair<TreeNode, NodePath> pair = new Pair<TreeNode, NodePath>(node, path);
|
|
76 Option<TreeMap<String, List<Pair<TreeNode, NodePath>>>> opAttributeList = index.get(key);
|
|
77
|
|
78 if (opAttributeList.isNone()) {
|
|
79 TreeMap<String, List<Pair<TreeNode, NodePath>>> nodeIndex = TreeMap.empty(Ord.stringOrd);
|
|
80 List<Pair<TreeNode, NodePath>> list = List.nil();
|
|
81 list = list.cons(pair);
|
|
82 nodeIndex = nodeIndex.set(attribute, list);
|
|
83 index = index.set(key, nodeIndex);
|
|
84 } else {
|
|
85 TreeMap<String, List<Pair<TreeNode, NodePath>>> indexMap = opAttributeList.some();
|
|
86 Option<List<Pair<TreeNode, NodePath>>> opNodeIndex = indexMap.get(attribute);
|
|
87
|
|
88 if (opNodeIndex.isNone()) {
|
|
89 List<Pair<TreeNode, NodePath>> pairList = List.nil();
|
|
90 pairList = pairList.cons(pair);
|
|
91 indexMap = indexMap.set(attribute, pairList);
|
|
92
|
|
93 } else {
|
|
94 List<Pair<TreeNode, NodePath>> pairList = opNodeIndex.some();
|
|
95 pairList = pairList.cons(pair);
|
|
96 indexMap = indexMap.set(attribute, pairList);
|
|
97 }
|
|
98 index = index.set(key, indexMap);
|
|
99 }
|
|
100 System.out.println(attribute);
|
|
101
|
|
102 }
|
|
103
|
|
104 }
|