0
|
1 package jp.ac.u_ryukyu.ie.cr.jungle.transaction;
|
|
2
|
|
3
|
|
4 import jp.ac.u_ryukyu.ie.cr.jungle.data.list.List;
|
|
5 import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNode;
|
|
6 import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNodeChildren;
|
|
7 import jp.ac.u_ryukyu.ie.cr.jungle.util.Either;
|
|
8 import jp.ac.u_ryukyu.ie.cr.jungle.util.Error;
|
|
9 import jp.ac.u_ryukyu.ie.cr.jungle.data.treemap.TreeMap;
|
|
10
|
|
11 import java.nio.ByteBuffer;
|
|
12 import java.rmi.dgc.VMID;
|
|
13
|
|
14 public class DefaultTreeNode implements TreeNode {
|
|
15 private List<TreeNode> children;
|
|
16 private TreeMap<String, ByteBuffer> attrs;
|
|
17 final String nodeId = new VMID().toString();
|
|
18
|
|
19 private static final List<TreeNode> NIL_LIST = new List<>();
|
|
20
|
|
21 public DefaultTreeNode() {
|
|
22 this(NIL_LIST, new TreeMap<>());
|
|
23 }
|
|
24
|
|
25 public DefaultTreeNode(List<TreeNode> _children, TreeMap<String, ByteBuffer> _attrs) {
|
|
26 attrs = _attrs;
|
|
27 children = _children;
|
|
28 }
|
|
29
|
|
30 @Override
|
|
31 public DefaultTreeNodeChildren getChildren() {
|
|
32 return new DefaultTreeNodeChildren(children, attrs);
|
|
33 }
|
|
34
|
|
35 @Override
|
|
36 public DefaultTreeNodeAttribute getAttributes() {
|
|
37 return new DefaultTreeNodeAttribute(children, attrs);
|
|
38 }
|
|
39
|
|
40 @Override
|
|
41 public DefaultTreeNode createNewNode() {
|
|
42 return new DefaultTreeNode();
|
|
43 }
|
|
44
|
|
45 public DefaultTreeNode clone() {
|
|
46 return new DefaultTreeNode(children, attrs);
|
|
47 }
|
|
48
|
|
49 @Override
|
|
50 public Either<Error, TreeNode> appendRootNode() {
|
|
51 TreeNodeChildren newRootChildren = new DefaultTreeNodeChildren(NIL_LIST, new TreeMap<>());
|
|
52 Either<jp.ac.u_ryukyu.ie.cr.jungle.util.Error, TreeNode> either = newRootChildren.addNewChildAt(0,this);
|
|
53 return either;
|
|
54 }
|
|
55
|
|
56 @Override
|
|
57 public int compareTo(TreeNode o) {
|
|
58 return this.hashCode() - o.hashCode();
|
|
59 }
|
|
60 }
|