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