Mercurial > hg > Members > shoshi > TreeCMSv2
annotate src/treecms/memory/OnMemoryMonotonicTree.java @ 26:9cb971a68cc5
added CachedForest.java
author | Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 18 Jul 2011 20:22:53 +0900 |
parents | c1e7ec6b3d44 |
children | aecc55e87143 |
rev | line source |
---|---|
11 | 1 package treecms.memory; |
21 | 2 |
11 | 3 import treecms.api.MonotonicTree; |
15 | 4 import treecms.api.MonotonicTreeNode; |
26
9cb971a68cc5
added CachedForest.java
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
25
diff
changeset
|
5 import treecms.api.Node; |
9cb971a68cc5
added CachedForest.java
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
25
diff
changeset
|
6 import treecms.tree.id.NodeIDProvider; |
11 | 7 |
8 public class OnMemoryMonotonicTree implements MonotonicTree | |
9 { | |
22 | 10 private final OnMemoryMonotonicTree m_tree; |
26
9cb971a68cc5
added CachedForest.java
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
25
diff
changeset
|
11 private volatile OnMemoryMonotonicTreeNode m_root; |
21 | 12 |
26
9cb971a68cc5
added CachedForest.java
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
25
diff
changeset
|
13 private OnMemoryMonotonicTree(NodeIDProvider _provider,OnMemoryMonotonicTree _tree) |
11 | 14 { |
22 | 15 m_tree = _tree; |
26
9cb971a68cc5
added CachedForest.java
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
25
diff
changeset
|
16 m_root = new OnMemoryMonotonicTreeNode(new OnMemoryNode(_provider.create(),null),null); |
21 | 17 } |
18 | |
26
9cb971a68cc5
added CachedForest.java
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
25
diff
changeset
|
19 public static OnMemoryMonotonicTree createInstance(NodeIDProvider _provider,OnMemoryMonotonicTree _tree) |
22 | 20 { |
26
9cb971a68cc5
added CachedForest.java
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
25
diff
changeset
|
21 OnMemoryMonotonicTree tree = new OnMemoryMonotonicTree(_provider,_tree); |
22 | 22 return tree; |
23 } | |
24 | |
25 public OnMemoryNode get(String _fid) | |
21 | 26 { |
26
9cb971a68cc5
added CachedForest.java
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
25
diff
changeset
|
27 return (OnMemoryNode)search(_fid,m_root.getNode()); |
9cb971a68cc5
added CachedForest.java
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
25
diff
changeset
|
28 } |
9cb971a68cc5
added CachedForest.java
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
25
diff
changeset
|
29 |
9cb971a68cc5
added CachedForest.java
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
25
diff
changeset
|
30 private Node search(String _fid,Node _node) |
9cb971a68cc5
added CachedForest.java
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
25
diff
changeset
|
31 { |
9cb971a68cc5
added CachedForest.java
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
25
diff
changeset
|
32 if(_node.getID().getFamilyID().equals(_fid)){ |
9cb971a68cc5
added CachedForest.java
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
25
diff
changeset
|
33 return _node; |
9cb971a68cc5
added CachedForest.java
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
25
diff
changeset
|
34 } |
9cb971a68cc5
added CachedForest.java
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
25
diff
changeset
|
35 |
9cb971a68cc5
added CachedForest.java
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
25
diff
changeset
|
36 for(Node child : _node.getList()){ |
9cb971a68cc5
added CachedForest.java
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
25
diff
changeset
|
37 Node ret = search(_fid,child); |
9cb971a68cc5
added CachedForest.java
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
25
diff
changeset
|
38 if(ret != null){ |
9cb971a68cc5
added CachedForest.java
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
25
diff
changeset
|
39 return ret; |
9cb971a68cc5
added CachedForest.java
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
25
diff
changeset
|
40 } |
9cb971a68cc5
added CachedForest.java
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
25
diff
changeset
|
41 } |
9cb971a68cc5
added CachedForest.java
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
25
diff
changeset
|
42 |
9cb971a68cc5
added CachedForest.java
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
25
diff
changeset
|
43 return null; |
22 | 44 } |
45 | |
11 | 46 @Override |
47 public boolean commit(boolean _force) | |
48 { | |
22 | 49 if(m_tree == null){ |
50 return true; | |
51 } | |
52 | |
21 | 53 return true; |
11 | 54 } |
55 | |
56 @Override | |
57 public boolean pull() | |
58 { | |
16 | 59 return true; |
11 | 60 } |
61 | |
62 @Override | |
63 public boolean check() | |
64 { | |
23 | 65 if(m_tree != null){ |
66 | |
67 } | |
22 | 68 return m_tree.getRoot().getNode().equals(m_root.getNode()); |
11 | 69 } |
70 | |
71 @Override | |
15 | 72 public void merge() |
73 { | |
11 | 74 } |
75 | |
76 @Override | |
15 | 77 public MonotonicTreeNode getRoot() |
78 { | |
21 | 79 return m_root; |
11 | 80 } |
81 } |