20
|
1 using System.Collections;
|
|
2
|
|
3 namespace JungleDB {
|
|
4 public class LoggingChildren {
|
|
5 private TreeNode wrap;
|
|
6 private OperationLog log;
|
|
7
|
|
8 public LoggingChildren(TreeNode _wrap,OperationLog _log)
|
|
9 {
|
|
10 wrap = _wrap;
|
|
11 log = _log;
|
|
12 }
|
|
13
|
|
14 public int size()
|
|
15 {
|
|
16 Children children = wrap.getChildren();
|
|
17 return children.size();
|
|
18 }
|
|
19
|
|
20 public Either<Error,LoggingNode> edit(NodeOperation _op)
|
|
21 {
|
|
22 Either<Error,TreeNode> either = _op.invoke(wrap);
|
|
23 if(either.isA()){
|
|
24 return DefaultEither<Error,LoggingNode>.newA(either.a());
|
|
25 }
|
|
26
|
|
27 TreeNode newWrap = either.b();
|
|
28 OperationLog newLog = log.add(_op);
|
|
29 LoggingNode newLoggingNode = new LoggingNode(newWrap,newLog);
|
|
30 return DefaultEither<Error,LoggingNode>.newB(newLoggingNode);
|
|
31 }
|
|
32
|
|
33 public Either<Error,LoggingNode> addNewChildAt(int _pos)
|
|
34 {
|
|
35 NodeOperation addNewChildAt = new AppendChildAtOperation(_pos);
|
|
36 return edit(addNewChildAt);
|
|
37 }
|
|
38
|
|
39 public Either<Error,LoggingNode> deleteChildAt(int _pos)
|
|
40 {
|
|
41 NodeOperation deleteChildAt = new DeleteChildAtOperation(_pos);
|
|
42 return edit(deleteChildAt);
|
|
43 }
|
|
44
|
|
45 public Either<Error,LoggingNode> at(int _pos)
|
|
46 {
|
|
47 Children children = wrap.getChildren();
|
|
48 Either<Error,TreeNode> either = children.at(_pos);
|
|
49 if(either.isA()){
|
|
50 return DefaultEither<Error,LoggingNode>.newA(either.a());
|
|
51 }
|
|
52
|
|
53 TreeNode node = either.b();
|
|
54 LoggingNode logNode = new LoggingNode(node);
|
|
55 return DefaultEither<Error,LoggingNode>.newB(logNode);
|
|
56 }
|
|
57
|
|
58 }
|
|
59 }
|