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