diff src/main/csharp/jp.ac.u-ryukyu.ie.cr/jungle-main/transaction/DefaultTreeNodeAttribute.cs @ 17:01a08cf4b2d9

Liq Files
author Kazuma
date Mon, 07 Nov 2016 01:05:24 +0900
parents abe0c247f5a5
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/csharp/jp.ac.u-ryukyu.ie.cr/jungle-main/transaction/DefaultTreeNodeAttribute.cs	Mon Nov 07 01:05:24 2016 +0900
@@ -0,0 +1,72 @@
+using UnityEngine;
+using System.Collections;
+using System.Collections.Generic;
+using System;
+using System.Text;
+
+public class DefaultTreeNodeAttribute : TreeNodeAttributes {
+	public List<TreeNode> children;
+	public TreeMap<string, byte[]> attrs;
+
+	public DefaultTreeNodeAttribute(List<TreeNode> _children, TreeMap<string, byte[]> _attrs){
+		children = _children; // null?
+		attrs = _attrs;
+	}
+
+	public TreeMap<string, byte[]> getAttributesAsRawMap(){
+		return attrs;
+	}
+
+	public Either<Error, TreeNode> delete(string _key) {
+		if (_key == null) {
+			return DefaultEither<Error,TreeNode>.newA (NodeEditorError.NULL_VALUE_NOT_ALLOWED);
+		}
+
+		if (null == attrs.getRoot()) {
+			return DefaultEither<Error,TreeNode>.newA(NodeEditorError.DELETE_KEY_NOT_FOUND);
+		}
+
+		TreeMap<string, byte[]> newMap = attrs.delete(_key);
+		TreeNode newNode = new DefaultTreeNode(children, newMap);
+		return DefaultEither<Error,TreeNode>.newB(newNode);
+	}
+
+	public Either<Error, TreeNode> put(string _key, byte[] _value){
+		if (_key == null || _value == null) {
+			return DefaultEither<Error, TreeNode>.newA (NodeEditorError.NULL_VALUE_NOT_ALLOWED);
+		}
+
+		TreeMap<string, byte[]> newMap = attrs.put (_key, _value);
+
+		TreeNode newNode = new DefaultTreeNode (children, newMap);
+
+		return DefaultEither<Error, TreeNode>.newB (newNode);
+	}
+
+	public byte[] get(string _key) {
+		if (_key == null) {
+			return new byte[1]{0};
+		}
+		byte[] op = attrs.get(_key); //null
+		if (op != null) {
+			return op;
+		}
+		return new byte[1]{0};
+	}
+
+	public string getString(string key, Encoding enc) {
+		char[] attribute = key.ToCharArray();
+		if (attribute != null){
+			return new string(attribute);
+		}
+		return null;
+	}
+
+	public string getString(string key) {
+		return null;
+	}
+	public IEnumerator<string> getKeys(){
+		return attrs.keys ();
+	}
+
+}