annotate Main/jungle-main/DefaultJungle.cs @ 41:bd44baa491a9 default tip

add TestJungleCore.cs
author Kazuma Takeda
date Thu, 23 Feb 2017 17:19:55 +0900
parents f2ea780b3e80
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
1 using System.Collections;
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
2 using System.Collections.Generic;
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
3 using System;
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
4
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
5 namespace JungleDB {
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
6 public class DefaultJungle : Jungle {
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
7 private Journal journal;
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
8 private TreeMap <string, JungleTree> trees;
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
9 private string uuid;
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
10 private TreeEditor editor;
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
11
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
12 public DefaultJungle(Journal journal, string uuid, TreeEditor editor){
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
13 this.journal = new NullJournal();
28
9588ad364fdd Last commit before change.
Kazuma Takeda
parents: 20
diff changeset
14 this.trees = new TreeMap <string, JungleTree>();
9588ad364fdd Last commit before change.
Kazuma Takeda
parents: 20
diff changeset
15 this.uuid = uuid;
9588ad364fdd Last commit before change.
Kazuma Takeda
parents: 20
diff changeset
16 this.editor = editor;
20
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
17 }
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
18
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
19 public JungleTree getTreeByName(string name) {
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
20 JungleTree jungle_tree = trees.get(name);
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
21 if (jungle_tree != null) {
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
22 return jungle_tree;
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
23 } else {
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
24 return null;
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
25 }
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
26 }
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
27
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
28 public JungleTree createNewTree(string name) {
28
9588ad364fdd Last commit before change.
Kazuma Takeda
parents: 20
diff changeset
29 ChangeList list = new InnerChangeList(uuid, name);
9588ad364fdd Last commit before change.
Kazuma Takeda
parents: 20
diff changeset
30 DefaultTreeNode root = new DefaultTreeNode ();
20
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
31 InterfaceTraverser traverser = new InterfaceTraverser (root, true);
28
9588ad364fdd Last commit before change.
Kazuma Takeda
parents: 20
diff changeset
32 TreeContext tc = new DefaultTreeContext (root, null, list, uuid, name, 0, traverser);
9588ad364fdd Last commit before change.
Kazuma Takeda
parents: 20
diff changeset
33 JungleTree newTree = new DefaultJungleTree (tc, uuid, journal.getWriter (), editor);
20
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
34 if (newTree != null) {
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
35 trees = trees.put (name, newTree);
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
36 } else {
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
37 }
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
38 return newTree;
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
39 }
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
40
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
41 public class InnerChangeList : ChangeList {
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
42
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
43 string uuid;
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
44 string name;
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
45
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
46 IEnumerator IEnumerable.GetEnumerator()
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
47 {
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
48 return this.GetEnumerator();
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
49 }
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
50
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
51 public IEnumerator<TreeOperation> GetEnumerator()
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
52 {
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
53 return iterator ();
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
54 }
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
55
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
56 // construct
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
57 public InnerChangeList(string _uuid, string _name) {
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
58 this.uuid = _uuid;
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
59 this.name = _name;
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
60 }
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
61
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
62 public IEnumerator<TreeOperation> iterator() {
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
63 List<TreeOperation> nil = new List<TreeOperation>();
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
64 return nil.iterator();
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
65 }
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
66
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
67 public string uuids() {
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
68 return uuid;
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
69 }
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
70
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
71 public string getTreeName() {
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
72 return name;
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
73 }
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
74
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
75 public TreeOperationLog getLog() {
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
76 return new DefaultTreeOperationLog();
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
77 }
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
78 }
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
79 }
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
80 }