Mercurial > hg > Members > tatsuki > bench > jungle-core
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 |
rev | line source |
---|---|
92 | 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 | 4 |
5 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Children; | |
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 | 9 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation; |
23 | 10 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; |
11 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; | |
25 | 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 | 14 public class LoggingChildren //implements EditableChildren |
21
848f73545c4d
add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff
changeset
|
15 { |
92 | 16 private final TreeNode wrap; |
51 | 17 private final OperationLog log; |
21
848f73545c4d
add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff
changeset
|
18 |
92 | 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 | 27 Children children = wrap.getChildren(); |
51 | 28 return children.size(); |
21
848f73545c4d
add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff
changeset
|
29 } |
35 | 30 |
92 | 31 /* |
35 | 32 @Override |
92 | 33 public Iterator<LoggingNode> iterator() |
35 | 34 { |
92 | 35 LoggingChildren children = wrap.getChildren(); |
36 return children.iterator(); | |
37 }*/ | |
36 | 38 |
92 | 39 public Either<Error,LoggingNode> edit(NodeOperation _op) |
51 | 40 { |
92 | 41 Either<Error,TreeNode> either = _op.invoke(wrap); |
51 | 42 if(either.isA()){ |
43 return DefaultEither.newA(either.a()); | |
44 } | |
45 | |
92 | 46 TreeNode newWrap = either.b(); |
51 | 47 OperationLog newLog = log.add(_op); |
92 | 48 LoggingNode newLoggingNode = new LoggingNode(newWrap,newLog); |
51 | 49 return DefaultEither.newB(newLoggingNode); |
50 } | |
51 | |
92 | 52 public Either<Error,LoggingNode> addNewChildAt(final int _pos) |
21
848f73545c4d
add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff
changeset
|
53 { |
51 | 54 NodeOperation addNewChildAt = new AppendChildAtOperation(_pos); |
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 | 58 public Either<Error,LoggingNode> deleteChildAt(final int _pos) |
21
848f73545c4d
add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff
changeset
|
59 { |
51 | 60 NodeOperation deleteChildAt = new DeleteChildAtOperation(_pos); |
61 return edit(deleteChildAt); | |
37 | 62 } |
41 | 63 |
92 | 64 public Either<Error,LoggingNode> at(int _pos) |
41 | 65 { |
92 | 66 Children children = wrap.getChildren(); |
67 Either<Error,TreeNode> either = children.at(_pos); | |
41 | 68 if(either.isA()){ |
69 return DefaultEither.newA(either.a()); | |
70 } | |
71 | |
92 | 72 TreeNode node = either.b(); |
73 return DefaultEither.newB(new LoggingNode(node)); | |
41 | 74 } |
21
848f73545c4d
add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff
changeset
|
75 } |