annotate Main/jungle-main/DefaultJungle.cs @ 20:1f99e150f336

fix folder and add Object Mapper.
author Kazuma Takeda
date Thu, 15 Dec 2016 22:52:48 +0900
parents
children 9588ad364fdd
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 using UnityEngine;
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
5
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
6 namespace JungleDB {
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
7 public class DefaultJungle : Jungle {
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
8 private Journal journal;
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
9 private TreeMap <string, JungleTree> trees;
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
10 private string uuid;
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
11 private TreeEditor editor;
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
12
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
13 public void Start(){
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
14 DefaultJungle j = new DefaultJungle(null, "hoge", new DefaultTreeEditor(new DefaultTraverser()));
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
15 JungleTree t = j.createNewTree ("fuga");
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
16
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
17 JungleTreeEditor e1 = t.getTreeEditor ();
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 DefaultNodePath root = new DefaultNodePath ();
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
20 Either<Error, JungleTreeEditor> either = e1.addNewChildAt (root, 0);
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
21 e1 = either.b();
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
22 either = e1.addNewChildAt (root.add (0), 0);
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
23 e1 = either.b ();
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
24 e1.commit ();
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 public DefaultJungle(Journal journal, string uuid, TreeEditor editor){
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
28 this.journal = new NullJournal();
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
29 this.trees = new TreeMap <string, JungleTree>();
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
30 this.uuid = uuid;
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
31 this.editor = editor;
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
32 }
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
33
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
34 public JungleTree getTreeByName(string name) {
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
35
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
36 JungleTree jungle_tree = trees.get(name);
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
37 if (jungle_tree != null) {
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
38 return jungle_tree;
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
39 } else {
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
40 Debug.Log ("そのTreeは無いようですね。");
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
41 return null;
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 }
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
44
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
45 public JungleTree createNewTree(string name) {
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
46 ChangeList list = new InnerChangeList(uuid,name);
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
47 DefaultTreeNode root = new DefaultTreeNode ();
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
48 InterfaceTraverser traverser = new InterfaceTraverser (root, true);
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
49 TreeContext tc = new DefaultTreeContext (root, null, list, uuid, name, 0, traverser);
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
50 JungleTree newTree = new DefaultJungleTree (tc, uuid, journal.getWriter (), editor);
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
51 if (newTree != null) {
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
52 trees = trees.put (name, newTree);
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
53 } else {
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
54 Debug.Log ("こんばんは、nullです。");
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 return newTree;
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
57 }
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
58
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
59 public class InnerChangeList : ChangeList {
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 string uuid;
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
62 string name;
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
63
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
64
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
65 IEnumerator IEnumerable.GetEnumerator()
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 return this.GetEnumerator();
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
68 }
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 public IEnumerator<TreeOperation> GetEnumerator()
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
71 {
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
72 return iterator ();
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 // construct
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
76 public InnerChangeList(string _uuid, string _name) {
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
77 this.uuid = _uuid;
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
78 this.name = _name;
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
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
81 public IEnumerator<TreeOperation> iterator() {
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
82 List<TreeOperation> nil = new List<TreeOperation>();
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
83 return nil.iterator();
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
84 }
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
85
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
86 public string uuids() {
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
87 return uuid;
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
88 }
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
89
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
90 public string getTreeName() {
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
91 return name;
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
92 }
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
93
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
94 public TreeOperationLog getLog() {
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
95 return new DefaultTreeOperationLog();
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
96 }
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
97 }
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
98 }
1f99e150f336 fix folder and add Object Mapper.
Kazuma Takeda
parents:
diff changeset
99 }