Mercurial > hg > Members > shoshi > jungle > jungle-core
annotate src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/CreateTreeMethod.java @ 329:2a0cb1f0ba4e
rename Error package
author | kono |
---|---|
date | Sat, 08 Jul 2017 21:05:55 +0900 |
parents | 0767620e6f5f |
children |
rev | line source |
---|---|
282 | 1 package jp.ac.u_ryukyu.ie.cr.jungle; |
2 | |
3 import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.NodePath; | |
4 import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.jungleTreeEditor.JungleTreeEditor; | |
5 import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; | |
329 | 6 import jp.ac.u_ryukyu.ie.cr.jungle.util.jungleError.Error; |
282 | 7 import junit.framework.Assert; |
8 | |
9 import java.nio.ByteBuffer; | |
10 | |
11 /** | |
12 * Created by e115731 on 2016/12/28. | |
13 */ | |
14 public class CreateTreeMethod { | |
15 | |
302
0767620e6f5f
implements DifferentialInterfaceTraverser and this tests
tatsuki
parents:
282
diff
changeset
|
16 /** |
0767620e6f5f
implements DifferentialInterfaceTraverser and this tests
tatsuki
parents:
282
diff
changeset
|
17 * Jungleの木を構築する関数 |
0767620e6f5f
implements DifferentialInterfaceTraverser and this tests
tatsuki
parents:
282
diff
changeset
|
18 * maxHeightで指定した深さまで木を構築する |
0767620e6f5f
implements DifferentialInterfaceTraverser and this tests
tatsuki
parents:
282
diff
changeset
|
19 * ノードは3つの子を持つ |
0767620e6f5f
implements DifferentialInterfaceTraverser and this tests
tatsuki
parents:
282
diff
changeset
|
20 */ |
282 | 21 public static JungleTreeEditor createTree(JungleTreeEditor editor, String key, String indexKey, int _maxHeight, NodePath path) { |
22 JungleTreeEditor newEditor = createTree(editor, key, indexKey, 0, _maxHeight, path); | |
23 Either<Error,JungleTreeEditor> either = newEditor.success(); | |
24 if (either.isA()) | |
25 Assert.fail(); | |
26 return either.b(); | |
27 } | |
28 | |
29 private static JungleTreeEditor createTree(JungleTreeEditor editor, String key, String indexKey, int _curY, int _maxHeight, NodePath path) { | |
30 | |
31 if (_curY == _maxHeight) { | |
32 return editor; | |
33 } | |
34 for (int i = 0; i < 3; i++) { | |
35 | |
36 Either<Error, JungleTreeEditor> either = editor.addNewChildAt(path, i); | |
37 if (either.isA()) | |
38 Assert.fail(); | |
39 editor = either.b(); | |
40 String value = path.add(i).toString(); | |
41 either = editor.putAttribute(path.add(i), key, ByteBuffer.wrap(value.getBytes())); | |
42 if (either.isA()) | |
43 Assert.fail(); | |
44 editor = either.b(); | |
45 either = editor.putAttribute(path.add(i), indexKey, ByteBuffer.wrap(value.getBytes())); | |
46 if (either.isA()) | |
47 Assert.fail(); | |
48 editor = either.b(); | |
49 editor = createTree(editor, key, indexKey, _curY + 1, _maxHeight, path.add(i)); | |
50 } | |
51 return editor; | |
52 } | |
53 } |