view src/main/csharp/jp.ac.u-ryukyu.ie.cr/jungle-network/transaction/NetworkDefaultJungleTree.cs @ 12:b71d9ea6bd8e

Add Network Operation Class. this codes can not test yet.
author Kazuma
date Sun, 23 Oct 2016 12:25:57 +0900
parents abe0c247f5a5
children
line wrap: on
line source

using UnityEngine;
using System.Collections;

public class NetworkDefaultJungleTree : JungleTree {

	private readonly AtomicReference<TreeContext> Repository;
	private readonly string Uuid;
	private readonly string TreeName;
	private readonly ChangeListWriter Writer;
	private readonly TreeEditor Editor;

	public NetworkDefaultJungleTree(string name, TreeContext tc, string uid, ChangeListWriter writer, TreeEditor edit) {
		this.TreeName   = name;
		this.Repository = new AtomicReference<TreeContext>(tc);
		this.Uuid       = uid;
		this.Writer     = writer;
		this.Editor     = edit;
	}

	public JungleTreeEditor getTreeEditor() {
		TreeContext tc = Repository.Get();
		NetworkTransactionManager txManager = new NetworkTransactionManager(this.TreeName, this.Writer, tc, this.Repository, this.Uuid);
		TreeNode root = tc.getRoot();
		return new NetworkDefaultJungleTreeEditor(this.TreeName, root, txManager, this.Editor);
	}

	public JungleTreeEditor getLocalTreeEditor () {
		TreeContext tc = this.Repository.Get();
		NetworkTransactionManager txManager = new NetworkTransactionManager(this.TreeName, this.Writer, tc, this.Repository, this.Uuid);
		TreeNode root = tc.getRoot();
		return NetworkDefaultJungleTreeEditor.NewLocalTreeEditor(this.TreeName, root, txManager, this.Editor);
	}

	public TreeNode getRootNode () {
		TreeContext tc = this.Repository.Get();
		return tc.getRoot();
	}

	public long revision () {
		return 0;
	}

	public Either<Error, JungleTree> getOldTree (long rev) {
		TreeContext tc = this.Repository.Get();
		while(tc.getRevision() != rev) { // If I mistake this code, change this code.
			tc = tc.prev();
			if (tc == null) {
				return DefaultEither<Error, JungleTree>.newA(GetOldTreeError.OLD_TREE_NOT_FOUND);
			}
		}
		string oldTreeUuid = this.Uuid + revision().ToString();
		JungleTree oldTree = new DefaultJungleTree(tc, oldTreeUuid, this.Writer, this.Editor);
		return DefaultEither<Error, JungleTree>.newB(oldTree);
	}

	public TreeMap<string, TreeMap<string, List<TreeNode>>> getIndex () {
		TreeContext tc = this.Repository.Get();
		return tc.getIndex();
	}

	public Either<Error, TreeNode> getNodeOfPath (NodePath path) {
		TreeNode node = this.Repository.Get().getRoot();
		foreach(var num in path) {
			if (num == -1) {
				continue;
			}
			Either<Error, TreeNode> either = node.getChildren().at(num);
			if (either.isA()){
				return either;
			}
			node = either.b();
		}
		return DefaultEither<Error, TreeNode>.newB(node);
	}

	public void setBufferSize (int num) {

	}
}