20
|
1 using System.Collections;
|
|
2 using System.Collections.Generic;
|
|
3 using System;
|
|
4
|
|
5 namespace JungleDB {
|
|
6 public class DefaultJungle : Jungle {
|
|
7 private Journal journal;
|
|
8 private TreeMap <string, JungleTree> trees;
|
|
9 private string uuid;
|
|
10 private TreeEditor editor;
|
|
11
|
|
12 public DefaultJungle(Journal journal, string uuid, TreeEditor editor){
|
|
13 this.journal = new NullJournal();
|
28
|
14 this.trees = new TreeMap <string, JungleTree>();
|
|
15 this.uuid = uuid;
|
|
16 this.editor = editor;
|
20
|
17 }
|
|
18
|
|
19 public JungleTree getTreeByName(string name) {
|
|
20 JungleTree jungle_tree = trees.get(name);
|
|
21 if (jungle_tree != null) {
|
|
22 return jungle_tree;
|
|
23 } else {
|
|
24 return null;
|
|
25 }
|
|
26 }
|
|
27
|
|
28 public JungleTree createNewTree(string name) {
|
28
|
29 ChangeList list = new InnerChangeList(uuid, name);
|
|
30 DefaultTreeNode root = new DefaultTreeNode ();
|
20
|
31 InterfaceTraverser traverser = new InterfaceTraverser (root, true);
|
28
|
32 TreeContext tc = new DefaultTreeContext (root, null, list, uuid, name, 0, traverser);
|
|
33 JungleTree newTree = new DefaultJungleTree (tc, uuid, journal.getWriter (), editor);
|
20
|
34 if (newTree != null) {
|
|
35 trees = trees.put (name, newTree);
|
|
36 } else {
|
|
37 }
|
|
38 return newTree;
|
|
39 }
|
|
40
|
|
41 public class InnerChangeList : ChangeList {
|
|
42
|
|
43 string uuid;
|
|
44 string name;
|
|
45
|
|
46 IEnumerator IEnumerable.GetEnumerator()
|
|
47 {
|
|
48 return this.GetEnumerator();
|
|
49 }
|
|
50
|
|
51 public IEnumerator<TreeOperation> GetEnumerator()
|
|
52 {
|
|
53 return iterator ();
|
|
54 }
|
|
55
|
|
56 // construct
|
|
57 public InnerChangeList(string _uuid, string _name) {
|
|
58 this.uuid = _uuid;
|
|
59 this.name = _name;
|
|
60 }
|
|
61
|
|
62 public IEnumerator<TreeOperation> iterator() {
|
|
63 List<TreeOperation> nil = new List<TreeOperation>();
|
|
64 return nil.iterator();
|
|
65 }
|
|
66
|
|
67 public string uuids() {
|
|
68 return uuid;
|
|
69 }
|
|
70
|
|
71 public string getTreeName() {
|
|
72 return name;
|
|
73 }
|
|
74
|
|
75 public TreeOperationLog getLog() {
|
|
76 return new DefaultTreeOperationLog();
|
|
77 }
|
|
78 }
|
|
79 }
|
|
80 } |