Mercurial > hg > Members > shoshi > TreeCMSv2
annotate src/treecms/memory/OnMemoryTreeEditor.java @ 3:5fa718b63cd5
finished treecms.memory basic implementation ( not tested yet. )
author | shoshi |
---|---|
date | Fri, 18 Feb 2011 02:14:10 +0900 |
parents | 4a5ee88f02cf |
children | 12604eb6b615 |
rev | line source |
---|---|
2 | 1 package treecms.memory; |
2 | |
3 import treecms.api.TreeEditor; | |
3
5fa718b63cd5
finished treecms.memory basic implementation ( not tested yet. )
shoshi
parents:
2
diff
changeset
|
4 import treecms.merger.Merger; |
5fa718b63cd5
finished treecms.memory basic implementation ( not tested yet. )
shoshi
parents:
2
diff
changeset
|
5 import treecms.merger.ReplaceMerger; |
2 | 6 |
3
5fa718b63cd5
finished treecms.memory basic implementation ( not tested yet. )
shoshi
parents:
2
diff
changeset
|
7 public class OnMemoryTreeEditor extends OnMemoryTree implements TreeEditor |
2 | 8 { |
3
5fa718b63cd5
finished treecms.memory basic implementation ( not tested yet. )
shoshi
parents:
2
diff
changeset
|
9 OnMemoryTree m_tree; |
5fa718b63cd5
finished treecms.memory basic implementation ( not tested yet. )
shoshi
parents:
2
diff
changeset
|
10 OnMemoryNode m_oldRoot; |
2 | 11 |
3
5fa718b63cd5
finished treecms.memory basic implementation ( not tested yet. )
shoshi
parents:
2
diff
changeset
|
12 public OnMemoryTreeEditor(OnMemoryForest _forest,OnMemoryTree _tree) |
2 | 13 { |
3
5fa718b63cd5
finished treecms.memory basic implementation ( not tested yet. )
shoshi
parents:
2
diff
changeset
|
14 super(_tree.m_root,_forest); |
5fa718b63cd5
finished treecms.memory basic implementation ( not tested yet. )
shoshi
parents:
2
diff
changeset
|
15 m_oldRoot = m_root; |
2 | 16 } |
17 | |
18 @Override | |
19 public boolean commit(boolean _force) | |
20 { | |
3
5fa718b63cd5
finished treecms.memory basic implementation ( not tested yet. )
shoshi
parents:
2
diff
changeset
|
21 if(!check() || _force){ |
5fa718b63cd5
finished treecms.memory basic implementation ( not tested yet. )
shoshi
parents:
2
diff
changeset
|
22 m_tree.m_root = m_root; |
5fa718b63cd5
finished treecms.memory basic implementation ( not tested yet. )
shoshi
parents:
2
diff
changeset
|
23 } |
2 | 24 return false; |
25 } | |
26 | |
27 @Override | |
28 public boolean pull() | |
29 { | |
3
5fa718b63cd5
finished treecms.memory basic implementation ( not tested yet. )
shoshi
parents:
2
diff
changeset
|
30 m_root = m_tree.m_root; |
5fa718b63cd5
finished treecms.memory basic implementation ( not tested yet. )
shoshi
parents:
2
diff
changeset
|
31 return true; |
2 | 32 } |
33 | |
34 @Override | |
35 public boolean check() | |
36 { | |
3
5fa718b63cd5
finished treecms.memory basic implementation ( not tested yet. )
shoshi
parents:
2
diff
changeset
|
37 if(m_tree.m_root.getID().equals(m_oldRoot.getID())){ |
5fa718b63cd5
finished treecms.memory basic implementation ( not tested yet. )
shoshi
parents:
2
diff
changeset
|
38 return false; |
5fa718b63cd5
finished treecms.memory basic implementation ( not tested yet. )
shoshi
parents:
2
diff
changeset
|
39 } |
5fa718b63cd5
finished treecms.memory basic implementation ( not tested yet. )
shoshi
parents:
2
diff
changeset
|
40 return true; |
2 | 41 } |
42 | |
43 @Override | |
44 public void merge() | |
45 { | |
3
5fa718b63cd5
finished treecms.memory basic implementation ( not tested yet. )
shoshi
parents:
2
diff
changeset
|
46 //call merger |
5fa718b63cd5
finished treecms.memory basic implementation ( not tested yet. )
shoshi
parents:
2
diff
changeset
|
47 Merger merger = new ReplaceMerger(); |
5fa718b63cd5
finished treecms.memory basic implementation ( not tested yet. )
shoshi
parents:
2
diff
changeset
|
48 m_root = (OnMemoryNode)merger.merge(m_tree.m_root,m_root); |
2 | 49 } |
50 } |