# HG changeset patch # User Kazuma Takeda # Date 1484863683 -32400 # Node ID 1466993c104caf0398869d81630ac0c14213d128 # Parent 236a58985e22e8fdd356288f4b5269b53147d28c byte[] to object Rewrite. diff -r 236a58985e22 -r 1466993c104c .hgignore --- a/.hgignore Wed Jan 18 21:54:26 2017 +0900 +++ b/.hgignore Fri Jan 20 07:08:03 2017 +0900 @@ -1,1 +1,2 @@ .DS_Store +.git diff -r 236a58985e22 -r 1466993c104c Main/jungle-main/DefaultJungleTree.cs --- a/Main/jungle-main/DefaultJungleTree.cs Wed Jan 18 21:54:26 2017 +0900 +++ b/Main/jungle-main/DefaultJungleTree.cs Fri Jan 20 07:08:03 2017 +0900 @@ -43,7 +43,7 @@ } public long revision() { - TreeContext tc = repository.Get(); // 確かにnull どこから来てる? repositoryのインスタンスを生成してないからかも + TreeContext tc = repository.Get(); return tc.getRevision(); } diff -r 236a58985e22 -r 1466993c104c Main/jungle-main/JungleTreeEditor.cs --- a/Main/jungle-main/JungleTreeEditor.cs Wed Jan 18 21:54:26 2017 +0900 +++ b/Main/jungle-main/JungleTreeEditor.cs Fri Jan 20 07:08:03 2017 +0900 @@ -4,10 +4,11 @@ void SetPrevPath (NodePath path); Either addNewChildAt(NodePath path,int pos); Either deleteChildAt(NodePath path,int pos); - Either putAttribute(NodePath path,string key, byte[] value); - Either putAttribute(string key, byte[] value); + Either putAttribute(NodePath path, string key, object value); + Either putAttribute(string key, object value); + Either putAttribute(object value); // add Method put Attribute (path, T?); - // Either putAttribute(NodePath path, string Key, MultiAttributes value); + // Either putAttribute(NodePath path, string Key, T value); Either deleteAttribute(NodePath path,string key); Either replaceNewRootNode(); Either edit(NodePath path, NodeEditor editor); diff -r 236a58985e22 -r 1466993c104c Main/jungle-main/core/Attributes.cs --- a/Main/jungle-main/core/Attributes.cs Wed Jan 18 21:54:26 2017 +0900 +++ b/Main/jungle-main/core/Attributes.cs Fri Jan 20 07:08:03 2017 +0900 @@ -1,5 +1,6 @@ using UnityEngine; public interface Attributes{ - byte[] get (string key); + object get (string key); + T get (string key); string getString (string key); } diff -r 236a58985e22 -r 1466993c104c Main/jungle-main/store/impl/TreeNodeAttributes.cs --- a/Main/jungle-main/store/impl/TreeNodeAttributes.cs Wed Jan 18 21:54:26 2017 +0900 +++ b/Main/jungle-main/store/impl/TreeNodeAttributes.cs Fri Jan 20 07:08:03 2017 +0900 @@ -2,9 +2,9 @@ namespace JungleDB { public interface TreeNodeAttributes : Attributes { Either delete(string key); - Either put(string key, byte[] value); + Either put(string key, object value); // Either put (string key, MultiAttributes value); - TreeMap getAttributesAsRawMap(); + TreeMap getAttributesAsRawMap(); IEnumerator getKeys(); } } diff -r 236a58985e22 -r 1466993c104c Main/jungle-main/store/impl/logger/LoggingAttributes.cs --- a/Main/jungle-main/store/impl/logger/LoggingAttributes.cs Wed Jan 18 21:54:26 2017 +0900 +++ b/Main/jungle-main/store/impl/logger/LoggingAttributes.cs Fri Jan 20 07:08:03 2017 +0900 @@ -11,7 +11,7 @@ log = _log; } - public byte[] get(string _key) + public object get(string _key) { TreeNodeAttributes attributes = wrap.getAttributes(); return attributes.get(_key); @@ -30,7 +30,7 @@ return DefaultEither.newB(newLogNode); } - + public Either delete(string _key) { @@ -38,10 +38,11 @@ return edit(deleteAttribute); } - public Either put(string _key, byte[] _value) + public Either put(string _key, object _value) { PutAttributeOperation putAttribute = new PutAttributeOperation(_key,_value); return edit(putAttribute); } + } } diff -r 236a58985e22 -r 1466993c104c Main/jungle-main/store/impl/logger/LoggingAttributes.cs.meta --- a/Main/jungle-main/store/impl/logger/LoggingAttributes.cs.meta Wed Jan 18 21:54:26 2017 +0900 +++ b/Main/jungle-main/store/impl/logger/LoggingAttributes.cs.meta Fri Jan 20 07:08:03 2017 +0900 @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: ffdd92c38e6228540835ba42bf3f22f5 -timeCreated: 1477164413 +guid: d186e0c089e634b018ea0762ef4769bd +timeCreated: 1484772179 licenseType: Free MonoImporter: serializedVersion: 2 diff -r 236a58985e22 -r 1466993c104c Main/jungle-main/store/operations/AppendChildAtOperation.cs --- a/Main/jungle-main/store/operations/AppendChildAtOperation.cs Wed Jan 18 21:54:26 2017 +0900 +++ b/Main/jungle-main/store/operations/AppendChildAtOperation.cs Fri Jan 20 07:08:03 2017 +0900 @@ -31,9 +31,9 @@ return null; } - public byte[] getValue() + public object getValue() { - return new byte[1]{0}; + return null; } } diff -r 236a58985e22 -r 1466993c104c Main/jungle-main/store/operations/DeleteAttributeOperation.cs --- a/Main/jungle-main/store/operations/DeleteAttributeOperation.cs Wed Jan 18 21:54:26 2017 +0900 +++ b/Main/jungle-main/store/operations/DeleteAttributeOperation.cs Fri Jan 20 07:08:03 2017 +0900 @@ -26,8 +26,8 @@ return key; } - public byte[] getValue() { - return new byte[1]{0}; + public object getValue() { + return null; } } } diff -r 236a58985e22 -r 1466993c104c Main/jungle-main/store/operations/DeleteChildAtOperation.cs --- a/Main/jungle-main/store/operations/DeleteChildAtOperation.cs Wed Jan 18 21:54:26 2017 +0900 +++ b/Main/jungle-main/store/operations/DeleteChildAtOperation.cs Fri Jan 20 07:08:03 2017 +0900 @@ -32,9 +32,9 @@ return null; } - public byte[] getValue() + public object getValue() { - return new byte[1]{0}; + return null; } } diff -r 236a58985e22 -r 1466993c104c Main/jungle-main/store/operations/NodeOperation.cs --- a/Main/jungle-main/store/operations/NodeOperation.cs Wed Jan 18 21:54:26 2017 +0900 +++ b/Main/jungle-main/store/operations/NodeOperation.cs Fri Jan 20 07:08:03 2017 +0900 @@ -4,7 +4,7 @@ Either invoke (TreeNode _target); int getPosition(); string getKey(); - byte[] getValue(); + object getValue(); } public interface NodeOperation { diff -r 236a58985e22 -r 1466993c104c Main/jungle-main/store/operations/PutAttributeOperation.cs --- a/Main/jungle-main/store/operations/PutAttributeOperation.cs Wed Jan 18 21:54:26 2017 +0900 +++ b/Main/jungle-main/store/operations/PutAttributeOperation.cs Fri Jan 20 07:08:03 2017 +0900 @@ -1,9 +1,9 @@ namespace JungleDB { public class PutAttributeOperation : NodeOperation { private string key; - private byte[] value; + private object value; - public PutAttributeOperation(string _key, byte[] _value) + public PutAttributeOperation(string _key, object _value) { key = _key; value = _value; @@ -29,7 +29,7 @@ return key; } - public byte[] getValue() + public object getValue() { return value; } diff -r 236a58985e22 -r 1466993c104c Main/jungle-main/store/operations/ReplaceRootNodeOperation.cs --- a/Main/jungle-main/store/operations/ReplaceRootNodeOperation.cs Wed Jan 18 21:54:26 2017 +0900 +++ b/Main/jungle-main/store/operations/ReplaceRootNodeOperation.cs Fri Jan 20 07:08:03 2017 +0900 @@ -21,8 +21,8 @@ return null; } - public byte[] getValue() { - return new byte[1]{0}; + public object getValue() { + return null; } } } diff -r 236a58985e22 -r 1466993c104c Main/jungle-main/store/transformer/PutAttribute.cs --- a/Main/jungle-main/store/transformer/PutAttribute.cs Wed Jan 18 21:54:26 2017 +0900 +++ b/Main/jungle-main/store/transformer/PutAttribute.cs Fri Jan 20 07:08:03 2017 +0900 @@ -4,14 +4,21 @@ namespace JungleDB { public class PutAttribute : NodeEditor { private string key; - private byte[] value; + private object value; - public PutAttribute(string _key, byte[] _value) + public PutAttribute(string _key, object _value) { key = _key; value = _value; } + public PutAttribute(object _value) + { + key = _value.ToString(); + Debug.Log (key); + value = _value; + } + public Either _edit(LoggingNode _e) { Either either = _e.getAttributes().put(key,value); diff -r 236a58985e22 -r 1466993c104c Main/jungle-main/transaction/DefaultJungleTreeEditor.cs --- a/Main/jungle-main/transaction/DefaultJungleTreeEditor.cs Wed Jan 18 21:54:26 2017 +0900 +++ b/Main/jungle-main/transaction/DefaultJungleTreeEditor.cs Fri Jan 20 07:08:03 2017 +0900 @@ -70,24 +70,23 @@ DeleteChildAt deleteChildAt = new DeleteChildAt(_pos); return _edit(_path,deleteChildAt); } - - public Either putAttribute(NodePath _path, string _key, byte[] _value) { + + + public Either putAttribute(NodePath _path, string _key, object _value) { PutAttribute putAttribute = new PutAttribute (_key, _value); return _edit (_path, putAttribute); } - /// - /// When use path, before create path. - /// * Problem -> copy to path from root everytime. - /// - /// The attribute. - /// Key. - /// Value. - public Either putAttribute(string _key, byte[] _value) { + public Either putAttribute(string _key, object _value) { PutAttribute putAttribute = new PutAttribute (_key, _value); return _edit (prevPath, putAttribute); } + public Either putAttribute(object _value) { + PutAttribute putAttribute = new PutAttribute (_value); + return _edit (prevPath, putAttribute); + } + public Either deleteAttribute(NodePath _path, string _key) { DeleteAttribute deleteAttribute = new DeleteAttribute (_key); return _edit (_path, deleteAttribute); @@ -99,7 +98,6 @@ public Either commit() { Either either = this.txManager.commit(this.root, this.log); - // このlogをサーバにpushする? if(either.isA()){ return DefaultEither.newA(either.a()); } diff -r 236a58985e22 -r 1466993c104c Main/jungle-main/transaction/DefaultTreeNode.cs --- a/Main/jungle-main/transaction/DefaultTreeNode.cs Wed Jan 18 21:54:26 2017 +0900 +++ b/Main/jungle-main/transaction/DefaultTreeNode.cs Fri Jan 20 07:08:03 2017 +0900 @@ -4,15 +4,15 @@ public class DefaultTreeNode : TreeNode { private List children; - private TreeMap attrs; + private TreeMap attrs; private static readonly List NIL_LIST = new List(); public DefaultTreeNode() - : this (NIL_LIST, new TreeMap ()) + : this (NIL_LIST, new TreeMap ()) { } - public DefaultTreeNode(List _children, TreeMap _attrs) { + public DefaultTreeNode(List _children, TreeMap _attrs) { attrs = _attrs; children = _children; } @@ -34,7 +34,7 @@ } public Either appendRootNode() { - TreeNodeChildren newRootChildren = new DefaultTreeNodeChildren(NIL_LIST, new TreeMap()); + TreeNodeChildren newRootChildren = new DefaultTreeNodeChildren(NIL_LIST, new TreeMap()); Either either = newRootChildren.addNewChildAt(0,this); return either; } diff -r 236a58985e22 -r 1466993c104c Main/jungle-main/transaction/DefaultTreeNodeAttribute.cs --- a/Main/jungle-main/transaction/DefaultTreeNodeAttribute.cs Wed Jan 18 21:54:26 2017 +0900 +++ b/Main/jungle-main/transaction/DefaultTreeNodeAttribute.cs Fri Jan 20 07:08:03 2017 +0900 @@ -7,14 +7,14 @@ namespace JungleDB { public class DefaultTreeNodeAttribute : TreeNodeAttributes { public List children; - public TreeMap attrs; + public TreeMap attrs; - public DefaultTreeNodeAttribute(List _children, TreeMap _attrs){ + public DefaultTreeNodeAttribute(List _children, TreeMap _attrs){ children = _children; attrs = _attrs; } - public TreeMap getAttributesAsRawMap(){ + public TreeMap getAttributesAsRawMap(){ return attrs; } @@ -27,35 +27,45 @@ return DefaultEither.newA(NodeEditorError.DELETE_KEY_NOT_FOUND); } - TreeMap newMap = attrs.delete(_key); + TreeMap newMap = attrs.delete(_key); TreeNode newNode = new DefaultTreeNode(children, newMap); return DefaultEither.newB(newNode); } - public Either put(string _key, byte[] _value){ + public Either put(string _key, object _value){ if (_key == null || _value == null) { return DefaultEither.newA (NodeEditorError.NULL_VALUE_NOT_ALLOWED); } - TreeMap newMap = attrs.put (_key, _value); + TreeMap newMap = attrs.put (_key, _value); TreeNode newNode = new DefaultTreeNode (children, newMap); return DefaultEither.newB (newNode); } - public byte[] get(string _key) { + public object get(string _key) { if (_key == null) - return new byte[1]{0}; + return null; - byte[] op = attrs.get(_key); + object op = attrs.get(_key); if (op != null) return op; - return new byte[1]{0}; + return null; + } + + public T get (string _key) { + if (_key == null) + return default(T); + + T op = (T)attrs.get (_key); + if (op != null) + return op; + return default(T); } public string getString(string key) { - return Encoding.UTF8.GetString (attrs.get (key)); + return attrs.get(key).ToString(); } public IEnumerator getKeys(){ diff -r 236a58985e22 -r 1466993c104c Main/jungle-main/transaction/DefaultTreeNodeChildren.cs --- a/Main/jungle-main/transaction/DefaultTreeNodeChildren.cs Wed Jan 18 21:54:26 2017 +0900 +++ b/Main/jungle-main/transaction/DefaultTreeNodeChildren.cs Fri Jan 20 07:08:03 2017 +0900 @@ -5,9 +5,9 @@ public class DefaultTreeNodeChildren : TreeNodeChildren { private List children; - private TreeMap attrs; + private TreeMap attrs; - public DefaultTreeNodeChildren(List _children, TreeMap _attrs){ + public DefaultTreeNodeChildren(List _children, TreeMap _attrs){ children = _children; attrs = _attrs; } diff -r 236a58985e22 -r 1466993c104c Main/jungle-network/operations/NetworkAppendChildAtOperation.cs --- a/Main/jungle-network/operations/NetworkAppendChildAtOperation.cs Wed Jan 18 21:54:26 2017 +0900 +++ b/Main/jungle-network/operations/NetworkAppendChildAtOperation.cs Fri Jan 20 07:08:03 2017 +0900 @@ -30,7 +30,7 @@ return null; } - public byte[] getValue() { + public object getValue() { return null; } } diff -r 236a58985e22 -r 1466993c104c Main/jungle-network/operations/NetworkDeleteAttributeOperation.cs --- a/Main/jungle-network/operations/NetworkDeleteAttributeOperation.cs Wed Jan 18 21:54:26 2017 +0900 +++ b/Main/jungle-network/operations/NetworkDeleteAttributeOperation.cs Fri Jan 20 07:08:03 2017 +0900 @@ -30,7 +30,7 @@ return this.Key; } - public byte[] getValue() { + public object getValue() { return null; } } diff -r 236a58985e22 -r 1466993c104c Main/jungle-network/operations/NetworkDeleteChildAtOperation.cs --- a/Main/jungle-network/operations/NetworkDeleteChildAtOperation.cs Wed Jan 18 21:54:26 2017 +0900 +++ b/Main/jungle-network/operations/NetworkDeleteChildAtOperation.cs Fri Jan 20 07:08:03 2017 +0900 @@ -30,7 +30,7 @@ return null; } - public byte[] getValue () { + public object getValue () { return null; } } diff -r 236a58985e22 -r 1466993c104c Main/jungle-network/operations/NetworkNodeOperation.cs --- a/Main/jungle-network/operations/NetworkNodeOperation.cs Wed Jan 18 21:54:26 2017 +0900 +++ b/Main/jungle-network/operations/NetworkNodeOperation.cs Fri Jan 20 07:08:03 2017 +0900 @@ -6,7 +6,7 @@ public int Position; public string Key; - public byte[] Value; + public object Value; public int commandType; // when switch use static readonly so, use const. @@ -75,7 +75,7 @@ return this.Key; } - public byte[] getValue() { + public object getValue() { return this.Value; } diff -r 236a58985e22 -r 1466993c104c Main/jungle-network/operations/NetworkPutAttributeOperation.cs --- a/Main/jungle-network/operations/NetworkPutAttributeOperation.cs Wed Jan 18 21:54:26 2017 +0900 +++ b/Main/jungle-network/operations/NetworkPutAttributeOperation.cs Fri Jan 20 07:08:03 2017 +0900 @@ -5,7 +5,7 @@ public class NetworkPutAttributeOperation : NodeOperation { public string Key; - public byte[] Value; + public object Value; public NetworkPutAttributeOperation() { this.Key = null; @@ -33,7 +33,7 @@ return -1; } - public byte[] getValue () { + public object getValue () { return this.Value; } } diff -r 236a58985e22 -r 1466993c104c Main/jungle-network/transaction/NetworkDefaultJungleTreeEditor.cs --- a/Main/jungle-network/transaction/NetworkDefaultJungleTreeEditor.cs Wed Jan 18 21:54:26 2017 +0900 +++ b/Main/jungle-network/transaction/NetworkDefaultJungleTreeEditor.cs Fri Jan 20 07:08:03 2017 +0900 @@ -97,15 +97,21 @@ return this.TreeEditor(_path,deleteChildAt); } - public Either putAttribute(NodePath _path, string _key, byte[] _value) + public Either putAttribute(NodePath _path, string _key, object _value) { PutAttribute putAttribute = new PutAttribute(_key,_value); - return this.TreeEditor(_path,putAttribute); + return this.TreeEditor(_path, putAttribute); } - public Either putAttribute(string _key, byte[] _value) + public Either putAttribute(string _key, object _value) { - PutAttribute putAttribute = new PutAttribute(_key,_value); + PutAttribute putAttribute = new PutAttribute(_key, _value); + return this.TreeEditor(prevPath, putAttribute); + } + + public Either putAttribute(object _value) + { + PutAttribute putAttribute = new PutAttribute(_value.ToString() ,_value); return this.TreeEditor(prevPath, putAttribute); } diff -r 236a58985e22 -r 1466993c104c Test/junge-main/jungle/core/nodeeditor/PutAttributeTest.cs --- a/Test/junge-main/jungle/core/nodeeditor/PutAttributeTest.cs Wed Jan 18 21:54:26 2017 +0900 +++ b/Test/junge-main/jungle/core/nodeeditor/PutAttributeTest.cs Fri Jan 20 07:08:03 2017 +0900 @@ -18,7 +18,7 @@ } LoggingNode newnode = either.b (); Debug.Log (newnode); - byte[] ret = newnode.getAttributes ().get (key); + object ret = newnode.getAttributes ().get (key); Debug.Log ("insertしたものは" + ret); } diff -r 236a58985e22 -r 1466993c104c Test/jungle-network/operations/NetworkPutAttributeOperationTest.cs --- a/Test/jungle-network/operations/NetworkPutAttributeOperationTest.cs Wed Jan 18 21:54:26 2017 +0900 +++ b/Test/jungle-network/operations/NetworkPutAttributeOperationTest.cs Fri Jan 20 07:08:03 2017 +0900 @@ -17,7 +17,6 @@ ObjectPacker unpack = new ObjectPacker(); NetworkPutAttributeOperation nOp = unpack.Unpack(packValue); - print(System.Text.ASCIIEncoding.UTF8.GetString(nOp.getValue())); print (nOp.getCommand()); } }