Mercurial > hg > Database > jungle-network
annotate src/jungle/test/alice/DoubleJungleManager.java @ 58:4851344e120e
fix bug LogUpdateCodeSegment and ChildLogCheckCodeSegment
author | one |
---|---|
date | Mon, 15 Jul 2013 10:13:34 +0900 (2013-07-15) |
parents | src/test/alice/jungle/codesegment/DoubleJungleManager.java@686057add8a4 |
children |
rev | line source |
---|---|
58
4851344e120e
fix bug LogUpdateCodeSegment and ChildLogCheckCodeSegment
one
parents:
47
diff
changeset
|
1 package jungle.test.alice; |
35 | 2 |
3 import java.nio.ByteBuffer; | |
4 | |
5 import alice.jungle.core.NetworkDefaultJungle; | |
6 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.Jungle; | |
7 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; | |
8 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.Command; | |
9 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; | |
10 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath; | |
11 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultTreeEditor; | |
12 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.TreeOperationLog; | |
13 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.DefaultTreeOperation; | |
14 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation; | |
15 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.PutAttributeOperation; | |
16 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation; | |
17 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultTraverser; | |
18 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; | |
19 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; | |
20 | |
21 public class DoubleJungleManager { | |
22 | |
47 | 23 static Jungle jungle1 = new NetworkDefaultJungle(null, "hoge", new DefaultTreeEditor(new DefaultTraverser()), ""); |
24 static Jungle jungle2 = new NetworkDefaultJungle(null, "hoge", new DefaultTreeEditor(new DefaultTraverser()), ""); | |
35 | 25 |
26 | |
27 public DoubleJungleManager() { | |
28 | |
29 } | |
30 | |
31 public Jungle getJungle1() { | |
32 return jungle1; | |
33 } | |
34 | |
35 public Jungle getJungle2() { | |
36 return jungle2; | |
37 } | |
38 | |
39 | |
40 public Either<Error, JungleTreeEditor> edit(JungleTreeEditor _editor ,TreeOperationLog _log) { | |
41 JungleTreeEditor editor = _editor; | |
42 Either<Error, JungleTreeEditor> either = null; | |
43 for (TreeOperation op : _log) { | |
44 either = _edit(editor, op); | |
45 if(either.isA()) { | |
46 return either; | |
47 } | |
48 editor = either.b(); | |
49 } | |
50 return either; | |
51 } | |
52 | |
53 private Either<Error, JungleTreeEditor> _edit(JungleTreeEditor editor, | |
54 TreeOperation op) { | |
55 NodePath path = op.getNodePath(); | |
56 NodeOperation nodeOp = op.getNodeOperation(); | |
57 Command c = nodeOp.getCommand(); | |
58 String key = ""; | |
59 switch (c) { | |
60 case PUT_ATTRIBUTE: | |
61 key = nodeOp.getKey(); | |
62 ByteBuffer value = nodeOp.getValue(); | |
63 return editor.putAttribute(path, key, value); | |
64 case DELETE_ATTRIBUTE: | |
65 key = nodeOp.getKey(); | |
66 return editor.deleteAttribute(path, key); | |
67 case APPEND_CHILD: | |
68 return editor.addNewChildAt(path, 0); | |
69 case DELETE_CHILD: | |
70 return editor.deleteChildAt(path, 0); | |
71 } | |
72 return null; | |
73 } | |
74 } |