Mercurial > hg > Database > jungle-sharp
view Main/jungle-main/transaction/DefaultTreeNodeAttribute.cs @ 28:9588ad364fdd
Last commit before change.
author | Kazuma Takeda |
---|---|
date | Wed, 18 Jan 2017 19:53:29 +0900 |
parents | 1f99e150f336 |
children | 1466993c104c |
line wrap: on
line source
using UnityEngine; using System.Collections; using System.Collections.Generic; using System; using System.Text; namespace JungleDB { public class DefaultTreeNodeAttribute : TreeNodeAttributes { public List<TreeNode> children; public TreeMap<string, byte[]> attrs; public DefaultTreeNodeAttribute(List<TreeNode> _children, TreeMap<string, byte[]> _attrs){ children = _children; 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); if (op != null) return op; return new byte[1]{0}; } public string getString(string key) { return Encoding.UTF8.GetString (attrs.get (key)); } public IEnumerator<string> getKeys(){ return attrs.keys (); } } }