Mercurial > hg > Members > nobuyasu > jungle-network
comparison src/jungle/test/operations/NetworkTreeOperationLog.java @ 1:8ee02d1a2b12
add jungle.test.operations
author | one |
---|---|
date | Fri, 07 Jun 2013 19:26:08 +0900 |
parents | |
children | 20498c88a70d |
comparison
equal
deleted
inserted
replaced
0:3991a751ed00 | 1:8ee02d1a2b12 |
---|---|
1 package jungle.test.operations; | |
2 | |
3 import java.util.Iterator; | |
4 import java.util.LinkedList; | |
5 | |
6 import org.msgpack.annotation.Message; | |
7 | |
8 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; | |
9 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.TreeOperationLog; | |
10 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation; | |
11 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation; | |
12 | |
13 @Message | |
14 public class NetworkTreeOperationLog implements TreeOperationLog | |
15 { | |
16 private Iterable<TreeOperation> list; | |
17 private int size; | |
18 | |
19 public NetworkTreeOperationLog() { | |
20 list = new LinkedList<TreeOperation>(); | |
21 size = 0; | |
22 } | |
23 | |
24 public NetworkTreeOperationLog(Iterable<TreeOperation> _list, int _size) | |
25 { | |
26 list = _list; | |
27 size = _size; | |
28 } | |
29 | |
30 public Iterable<TreeOperation> getOperationLogList() { | |
31 return list; | |
32 } | |
33 | |
34 @Override | |
35 public Iterator<TreeOperation> iterator() { | |
36 return list.iterator(); | |
37 } | |
38 | |
39 @Override | |
40 public NetworkTreeOperationLog add(NodePath _p, NodeOperation _op) | |
41 { | |
42 TreeOperation op = new NetworkTreeOperation(_p, _op); | |
43 LinkedList<TreeOperation> newList = new LinkedList<TreeOperation>(); | |
44 for(TreeOperation o : this) { | |
45 newList.add(o); | |
46 } | |
47 newList.add(op); | |
48 return new NetworkTreeOperationLog(newList, size+1); | |
49 } | |
50 | |
51 @Override | |
52 public NetworkTreeOperationLog append(TreeOperationLog _log) | |
53 { | |
54 LinkedList<TreeOperation> l = new LinkedList<TreeOperation>(); | |
55 for (TreeOperation t : _log) { | |
56 l.add(t); | |
57 } | |
58 return new NetworkTreeOperationLog(l, size+_log.length()); | |
59 } | |
60 | |
61 @Override | |
62 public int length() | |
63 { | |
64 return size; | |
65 } | |
66 | |
67 } |