Mercurial > hg > Members > tatsuki > bench > jungle-core
comparison 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 |
comparison
equal
deleted
inserted
replaced
86:fb1dc448ac8c | 92:14ce7a0dedca |
---|---|
1 /*package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger; | 1 package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger; |
2 | 2 |
3 import java.util.Iterator; | 3 import java.util.Iterator; |
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; | |
4 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.AppendChildAtOperation; | 7 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.AppendChildAtOperation; |
5 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.DeleteChildAtOperation; | 8 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.DeleteChildAtOperation; |
6 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation; | 9 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation; |
7 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableChildren; | |
8 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableNode; | |
9 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; | 10 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; |
10 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; | 11 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; |
11 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; | 12 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; |
12 | 13 |
13 public class LoggingChildren<T extends EditableNode<T>> implements EditableChildren<LoggingNode<T>> | 14 public class LoggingChildren //implements EditableChildren |
14 { | 15 { |
15 private final T wrap; | 16 private final TreeNode wrap; |
16 private final OperationLog log; | 17 private final OperationLog log; |
17 | 18 |
18 public LoggingChildren(T _wrap,OperationLog _log) | 19 public LoggingChildren(TreeNode _wrap,OperationLog _log) |
19 { | 20 { |
20 wrap = _wrap; | 21 wrap = _wrap; |
21 log = _log; | 22 log = _log; |
22 } | 23 } |
23 | 24 |
24 @Override | |
25 public int size() | 25 public int size() |
26 { | 26 { |
27 EditableChildren<T> children = wrap.getChildren(); | 27 Children children = wrap.getChildren(); |
28 return children.size(); | 28 return children.size(); |
29 } | 29 } |
30 | 30 |
31 /* | |
31 @Override | 32 @Override |
32 public Iterator<LoggingNode<T>> iterator() | 33 public Iterator<LoggingNode> iterator() |
33 { | 34 { |
34 EditableChildren<T> children = wrap.getChildren(); | 35 LoggingChildren children = wrap.getChildren(); |
35 return (Iterator<LoggingNode<T>>) children.iterator(); | 36 return children.iterator(); |
36 } | 37 }*/ |
37 | 38 |
38 public Either<Error,LoggingNode<T>> edit(NodeOperation _op) | 39 public Either<Error,LoggingNode> edit(NodeOperation _op) |
39 { | 40 { |
40 Either<Error,T> either = _op.invoke(wrap); | 41 Either<Error,TreeNode> either = _op.invoke(wrap); |
41 if(either.isA()){ | 42 if(either.isA()){ |
42 return DefaultEither.newA(either.a()); | 43 return DefaultEither.newA(either.a()); |
43 } | 44 } |
44 | 45 |
45 T newWrap = either.b(); | 46 TreeNode newWrap = either.b(); |
46 OperationLog newLog = log.add(_op); | 47 OperationLog newLog = log.add(_op); |
47 LoggingNode<T> newLoggingNode = new LoggingNode<T>(newWrap,newLog); | 48 LoggingNode newLoggingNode = new LoggingNode(newWrap,newLog); |
48 return DefaultEither.newB(newLoggingNode); | 49 return DefaultEither.newB(newLoggingNode); |
49 } | 50 } |
50 | 51 |
51 @Override | 52 public Either<Error,LoggingNode> addNewChildAt(final int _pos) |
52 public Either<Error,LoggingNode<T>> addNewChildAt(final int _pos) | |
53 { | 53 { |
54 NodeOperation addNewChildAt = new AppendChildAtOperation(_pos); | 54 NodeOperation addNewChildAt = new AppendChildAtOperation(_pos); |
55 return edit(addNewChildAt); | 55 return edit(addNewChildAt); |
56 } | 56 } |
57 | 57 |
58 @Override | 58 public Either<Error,LoggingNode> deleteChildAt(final int _pos) |
59 public Either<Error,LoggingNode<T>> deleteChildAt(final int _pos) | |
60 { | 59 { |
61 NodeOperation deleteChildAt = new DeleteChildAtOperation(_pos); | 60 NodeOperation deleteChildAt = new DeleteChildAtOperation(_pos); |
62 return edit(deleteChildAt); | 61 return edit(deleteChildAt); |
63 } | 62 } |
64 | 63 |
65 @Override | 64 public Either<Error,LoggingNode> at(int _pos) |
66 public Either<Error,LoggingNode<T>> at(int _pos) | |
67 { | 65 { |
68 EditableChildren<T> children = wrap.getChildren(); | 66 Children children = wrap.getChildren(); |
69 Either<Error,T> either = children.at(_pos); | 67 Either<Error,TreeNode> either = children.at(_pos); |
70 if(either.isA()){ | 68 if(either.isA()){ |
71 return DefaultEither.newA(either.a()); | 69 return DefaultEither.newA(either.a()); |
72 } | 70 } |
73 | 71 |
74 T node = either.b(); | 72 TreeNode node = either.b(); |
75 return DefaultEither.newB(new LoggingNode<T>(node)); | 73 return DefaultEither.newB(new LoggingNode(node)); |
76 } | 74 } |
77 } | 75 } |
78 */ |