annotate src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/logger/LoggingChildren.java @ 92:14ce7a0dedca

Logging Node and Editor
author one
date Sat, 06 Sep 2014 05:03:10 +0900
parents 540a27dde42f
children bed3afd5c2e2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
92
14ce7a0dedca Logging Node and Editor
one
parents: 78
diff changeset
1 package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger;
21
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
2
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
3 import java.util.Iterator;
92
14ce7a0dedca Logging Node and Editor
one
parents: 78
diff changeset
4
14ce7a0dedca Logging Node and Editor
one
parents: 78
diff changeset
5 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Children;
14ce7a0dedca Logging Node and Editor
one
parents: 78
diff changeset
6 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode;
21
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
7 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.AppendChildAtOperation;
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
8 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.DeleteChildAtOperation;
51
bc119c52d5cc modified LoggingNode package
Shoshi TAMAKI
parents: 50
diff changeset
9 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation;
23
Shoshi TAMAKI
parents: 21
diff changeset
10 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither;
Shoshi TAMAKI
parents: 21
diff changeset
11 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either;
25
Shoshi TAMAKI
parents: 23
diff changeset
12 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error;
21
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
13
92
14ce7a0dedca Logging Node and Editor
one
parents: 78
diff changeset
14 public class LoggingChildren //implements EditableChildren
21
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
15 {
92
14ce7a0dedca Logging Node and Editor
one
parents: 78
diff changeset
16 private final TreeNode wrap;
51
bc119c52d5cc modified LoggingNode package
Shoshi TAMAKI
parents: 50
diff changeset
17 private final OperationLog log;
21
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
18
92
14ce7a0dedca Logging Node and Editor
one
parents: 78
diff changeset
19 public LoggingChildren(TreeNode _wrap,OperationLog _log)
21
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
20 {
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
21 wrap = _wrap;
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
22 log = _log;
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
23 }
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
24
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
25 public int size()
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
26 {
92
14ce7a0dedca Logging Node and Editor
one
parents: 78
diff changeset
27 Children children = wrap.getChildren();
51
bc119c52d5cc modified LoggingNode package
Shoshi TAMAKI
parents: 50
diff changeset
28 return children.size();
21
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
29 }
35
Shoshi TAMAKI
parents: 31
diff changeset
30
92
14ce7a0dedca Logging Node and Editor
one
parents: 78
diff changeset
31 /*
35
Shoshi TAMAKI
parents: 31
diff changeset
32 @Override
92
14ce7a0dedca Logging Node and Editor
one
parents: 78
diff changeset
33 public Iterator<LoggingNode> iterator()
35
Shoshi TAMAKI
parents: 31
diff changeset
34 {
92
14ce7a0dedca Logging Node and Editor
one
parents: 78
diff changeset
35 LoggingChildren children = wrap.getChildren();
14ce7a0dedca Logging Node and Editor
one
parents: 78
diff changeset
36 return children.iterator();
14ce7a0dedca Logging Node and Editor
one
parents: 78
diff changeset
37 }*/
36
Shoshi TAMAKI
parents: 35
diff changeset
38
92
14ce7a0dedca Logging Node and Editor
one
parents: 78
diff changeset
39 public Either<Error,LoggingNode> edit(NodeOperation _op)
51
bc119c52d5cc modified LoggingNode package
Shoshi TAMAKI
parents: 50
diff changeset
40 {
92
14ce7a0dedca Logging Node and Editor
one
parents: 78
diff changeset
41 Either<Error,TreeNode> either = _op.invoke(wrap);
51
bc119c52d5cc modified LoggingNode package
Shoshi TAMAKI
parents: 50
diff changeset
42 if(either.isA()){
bc119c52d5cc modified LoggingNode package
Shoshi TAMAKI
parents: 50
diff changeset
43 return DefaultEither.newA(either.a());
bc119c52d5cc modified LoggingNode package
Shoshi TAMAKI
parents: 50
diff changeset
44 }
bc119c52d5cc modified LoggingNode package
Shoshi TAMAKI
parents: 50
diff changeset
45
92
14ce7a0dedca Logging Node and Editor
one
parents: 78
diff changeset
46 TreeNode newWrap = either.b();
51
bc119c52d5cc modified LoggingNode package
Shoshi TAMAKI
parents: 50
diff changeset
47 OperationLog newLog = log.add(_op);
92
14ce7a0dedca Logging Node and Editor
one
parents: 78
diff changeset
48 LoggingNode newLoggingNode = new LoggingNode(newWrap,newLog);
51
bc119c52d5cc modified LoggingNode package
Shoshi TAMAKI
parents: 50
diff changeset
49 return DefaultEither.newB(newLoggingNode);
bc119c52d5cc modified LoggingNode package
Shoshi TAMAKI
parents: 50
diff changeset
50 }
bc119c52d5cc modified LoggingNode package
Shoshi TAMAKI
parents: 50
diff changeset
51
92
14ce7a0dedca Logging Node and Editor
one
parents: 78
diff changeset
52 public Either<Error,LoggingNode> addNewChildAt(final int _pos)
21
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
53 {
51
bc119c52d5cc modified LoggingNode package
Shoshi TAMAKI
parents: 50
diff changeset
54 NodeOperation addNewChildAt = new AppendChildAtOperation(_pos);
bc119c52d5cc modified LoggingNode package
Shoshi TAMAKI
parents: 50
diff changeset
55 return edit(addNewChildAt);
21
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
56 }
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
57
92
14ce7a0dedca Logging Node and Editor
one
parents: 78
diff changeset
58 public Either<Error,LoggingNode> deleteChildAt(final int _pos)
21
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
59 {
51
bc119c52d5cc modified LoggingNode package
Shoshi TAMAKI
parents: 50
diff changeset
60 NodeOperation deleteChildAt = new DeleteChildAtOperation(_pos);
bc119c52d5cc modified LoggingNode package
Shoshi TAMAKI
parents: 50
diff changeset
61 return edit(deleteChildAt);
37
35e327577b58 added transaction
Shoshi TAMAKI
parents: 36
diff changeset
62 }
41
ed6737db637a added tests
Shoshi TAMAKI
parents: 37
diff changeset
63
92
14ce7a0dedca Logging Node and Editor
one
parents: 78
diff changeset
64 public Either<Error,LoggingNode> at(int _pos)
41
ed6737db637a added tests
Shoshi TAMAKI
parents: 37
diff changeset
65 {
92
14ce7a0dedca Logging Node and Editor
one
parents: 78
diff changeset
66 Children children = wrap.getChildren();
14ce7a0dedca Logging Node and Editor
one
parents: 78
diff changeset
67 Either<Error,TreeNode> either = children.at(_pos);
41
ed6737db637a added tests
Shoshi TAMAKI
parents: 37
diff changeset
68 if(either.isA()){
ed6737db637a added tests
Shoshi TAMAKI
parents: 37
diff changeset
69 return DefaultEither.newA(either.a());
ed6737db637a added tests
Shoshi TAMAKI
parents: 37
diff changeset
70 }
ed6737db637a added tests
Shoshi TAMAKI
parents: 37
diff changeset
71
92
14ce7a0dedca Logging Node and Editor
one
parents: 78
diff changeset
72 TreeNode node = either.b();
14ce7a0dedca Logging Node and Editor
one
parents: 78
diff changeset
73 return DefaultEither.newB(new LoggingNode(node));
41
ed6737db637a added tests
Shoshi TAMAKI
parents: 37
diff changeset
74 }
21
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
75 }