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

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


namespace JungleDB {
	public class DefaultTreeNode : TreeNode {
		
		private List<TreeNode> children;
		private TreeMap<string, object> attrs;
		private static readonly List<TreeNode> NIL_LIST = new List<TreeNode>();

		public DefaultTreeNode() 
			: this (NIL_LIST, new TreeMap<string, object> ())
		{
		}

		public DefaultTreeNode(List<TreeNode> _children, TreeMap<string, object> _attrs) {
			attrs = _attrs;
			children = _children;
		}

		public TreeNodeChildren getChildren() {
			return new DefaultTreeNodeChildren(children, attrs);
		}

		public TreeNodeAttributes getAttributes() {
			return new DefaultTreeNodeAttribute(children, attrs); // count = null.
		}

		public TreeNode createNewNode() {
			return new DefaultTreeNode();
		}

		public DefaultTreeNode clone() {
			return new DefaultTreeNode(children, attrs);
		}

		public Either<Error, TreeNode> appendRootNode() {
			TreeNodeChildren newRootChildren = new DefaultTreeNodeChildren(NIL_LIST, new TreeMap<string, object>());
			Either<Error, TreeNode> either = newRootChildren.addNewChildAt(0,this);
			return either;
		}

		public int compareTo(TreeNode o) {
			return this.GetHashCode() - o.GetHashCode();
		}
	}
}