0
|
1 package jp.ac.u_ryukyu.ie.cr.jungle.store.impl.logger;
|
|
2
|
|
3 import com.google.common.collect.Iterables;
|
|
4 import jp.ac.u_ryukyu.ie.cr.jungle.store.NodePath;
|
|
5 import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.DefaultTreeOperation;
|
|
6 import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.NodeOperation;
|
|
7 import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.TreeOperation;
|
|
8 import jp.ac.u_ryukyu.ie.cr.jungle.data.list.List;
|
|
9
|
|
10 import java.util.Iterator;
|
|
11
|
|
12 public class DefaultTreeOperationLog implements TreeOperationLog
|
|
13 {
|
|
14 private final Iterable<TreeOperation> list;
|
|
15 private final int size;
|
|
16
|
|
17 public DefaultTreeOperationLog()
|
|
18 {
|
|
19 list = new List<>();
|
|
20 size = 0;
|
|
21 }
|
|
22
|
|
23 public DefaultTreeOperationLog(Iterable<TreeOperation> _list,int _size)
|
|
24 {
|
|
25 list = _list;
|
|
26 size = _size;
|
|
27 }
|
|
28
|
|
29 @Override
|
|
30 public Iterator<TreeOperation> iterator()
|
|
31 {
|
|
32 return list.iterator();
|
|
33 }
|
|
34
|
|
35 @Override
|
|
36 public TreeOperationLog add(NodePath _p, NodeOperation _op)
|
|
37 {
|
|
38 TreeOperation op = new DefaultTreeOperation(_p,_op);
|
|
39 List<TreeOperation> newList = new List<>(op);
|
|
40 Iterable<TreeOperation> concat = Iterables.concat(list,newList);
|
|
41
|
|
42 return new DefaultTreeOperationLog(concat,size + 1);
|
|
43 }
|
|
44
|
|
45 @Override
|
|
46 public TreeOperationLog append(TreeOperationLog _log)
|
|
47 {
|
|
48 int argumentLogSize = _log.length();
|
|
49 Iterable<TreeOperation> concat = Iterables.concat(list,_log);
|
|
50
|
|
51 return new DefaultTreeOperationLog(concat,argumentLogSize + size);
|
|
52 }
|
|
53
|
|
54 @Override
|
|
55 public int length()
|
|
56 {
|
|
57 return size;
|
|
58 }
|
|
59
|
|
60 }
|