view Main/jungle-main/DefaultJungle.cs @ 35:f2ea780b3e80

fix
author Kazuma Takeda
date Wed, 22 Feb 2017 16:30:19 +0900
parents 9588ad364fdd
children
line wrap: on
line source

using System.Collections;
using System.Collections.Generic;
using System;

namespace JungleDB {
	public class DefaultJungle : Jungle {
		private Journal journal;
		private TreeMap <string, JungleTree> trees;
		private string uuid;
		private TreeEditor editor;

		public DefaultJungle(Journal journal, string uuid, TreeEditor editor){
			this.journal = new NullJournal();
			this.trees   = new TreeMap <string, JungleTree>();
			this.uuid    = uuid;
			this.editor  = editor;
		}

		public JungleTree getTreeByName(string name) {
			JungleTree jungle_tree = trees.get(name);
			if (jungle_tree != null) {
				return jungle_tree;
			} else {
				return null;
			}
		}

		public JungleTree createNewTree(string name) {
			ChangeList list              = new InnerChangeList(uuid, name);
			DefaultTreeNode root         = new DefaultTreeNode ();
			InterfaceTraverser traverser = new InterfaceTraverser (root, true);
			TreeContext tc               = new DefaultTreeContext (root, null, list, uuid, name, 0, traverser);
			JungleTree newTree           = new DefaultJungleTree (tc, uuid, journal.getWriter (), editor);
			if (newTree != null) {
				trees = trees.put (name, newTree);
			} else {
			}
			return newTree;
		} 

		public class InnerChangeList : ChangeList {

			string uuid;
			string name;

			IEnumerator IEnumerable.GetEnumerator()
			{
				return this.GetEnumerator();
			}
				
			public IEnumerator<TreeOperation> GetEnumerator()
			{
				return iterator ();
			}

			// construct
			public InnerChangeList(string _uuid, string _name) {
				this.uuid = _uuid;
				this.name = _name;
			}

			public IEnumerator<TreeOperation> iterator() {
				List<TreeOperation> nil = new List<TreeOperation>();
				return nil.iterator();
			}

			public string uuids() {
				return uuid;
			}

			public string getTreeName() {
				return name;
			}

			public TreeOperationLog getLog() {
				return new DefaultTreeOperationLog();
			}
		}
	}
}