comparison 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
comparison
equal deleted inserted replaced
16:8f1ce942abfc 17:01a08cf4b2d9
1 using UnityEngine;
2 using System.Collections;
3 using System.Collections.Generic;
4 using System;
5 using System.Text;
6
7 public class DefaultTreeNodeAttribute : TreeNodeAttributes {
8 public List<TreeNode> children;
9 public TreeMap<string, byte[]> attrs;
10
11 public DefaultTreeNodeAttribute(List<TreeNode> _children, TreeMap<string, byte[]> _attrs){
12 children = _children; // null?
13 attrs = _attrs;
14 }
15
16 public TreeMap<string, byte[]> getAttributesAsRawMap(){
17 return attrs;
18 }
19
20 public Either<Error, TreeNode> delete(string _key) {
21 if (_key == null) {
22 return DefaultEither<Error,TreeNode>.newA (NodeEditorError.NULL_VALUE_NOT_ALLOWED);
23 }
24
25 if (null == attrs.getRoot()) {
26 return DefaultEither<Error,TreeNode>.newA(NodeEditorError.DELETE_KEY_NOT_FOUND);
27 }
28
29 TreeMap<string, byte[]> newMap = attrs.delete(_key);
30 TreeNode newNode = new DefaultTreeNode(children, newMap);
31 return DefaultEither<Error,TreeNode>.newB(newNode);
32 }
33
34 public Either<Error, TreeNode> put(string _key, byte[] _value){
35 if (_key == null || _value == null) {
36 return DefaultEither<Error, TreeNode>.newA (NodeEditorError.NULL_VALUE_NOT_ALLOWED);
37 }
38
39 TreeMap<string, byte[]> newMap = attrs.put (_key, _value);
40
41 TreeNode newNode = new DefaultTreeNode (children, newMap);
42
43 return DefaultEither<Error, TreeNode>.newB (newNode);
44 }
45
46 public byte[] get(string _key) {
47 if (_key == null) {
48 return new byte[1]{0};
49 }
50 byte[] op = attrs.get(_key); //null
51 if (op != null) {
52 return op;
53 }
54 return new byte[1]{0};
55 }
56
57 public string getString(string key, Encoding enc) {
58 char[] attribute = key.ToCharArray();
59 if (attribute != null){
60 return new string(attribute);
61 }
62 return null;
63 }
64
65 public string getString(string key) {
66 return null;
67 }
68 public IEnumerator<string> getKeys(){
69 return attrs.keys ();
70 }
71
72 }