Mercurial > hg > Members > tatsuki > bench > jungle-core
annotate src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTreeNodeChildren.java @ 143:afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
bag
author | one |
---|---|
date | Sat, 15 Nov 2014 17:48:07 +0900 |
parents | ef183969bf31 |
children | 0854f9a9e81d |
rev | line source |
---|---|
37 | 1 package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction; |
2 | |
3 import java.nio.ByteBuffer; | |
4 import java.util.Iterator; | |
71 | 5 |
37 | 6 import fj.P2; |
7 import fj.data.List; | |
8 import fj.data.TreeMap; | |
81 | 9 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; |
52 | 10 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNodeChildren; |
87 | 11 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.DefaultOperationLog; |
12 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.OperationLog; | |
13 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.AppendChildAtOperation; | |
14 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.DeleteChildAtOperation; | |
15 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation; | |
37 | 16 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.NodeEditorError; |
17 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; | |
18 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; | |
19 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; | |
20 | |
86 | 21 public class DefaultTreeNodeChildren implements TreeNodeChildren |
37 | 22 { |
39 | 23 public static void main(String _args[]) |
24 { | |
25 List<Integer> list = List.range(0,5); | |
41 | 26 P2<List<Integer>, List<Integer>> split = list.splitAt(0); |
39 | 27 System.out.println(split._1().length()); |
28 System.out.println(split._2().length()); | |
29 | |
30 } | |
31 | |
81 | 32 public List<TreeNode> children; |
71 | 33 public TreeMap<String,ByteBuffer> attrs; |
87 | 34 |
81 | 35 public DefaultTreeNodeChildren(List<TreeNode> _children,TreeMap<String,ByteBuffer> _attrs) |
37 | 36 { |
71 | 37 children = _children; |
38 attrs = _attrs; | |
37 | 39 } |
40 | |
41 private boolean boundaryCheck(int _pos) | |
42 { | |
71 | 43 int size = children.length(); |
39 | 44 if(size < _pos){ |
37 | 45 return false; |
46 } | |
47 | |
48 return true; | |
49 } | |
50 | |
51 @Override | |
81 | 52 public List<TreeNode> getChildrenAsRawList(){ |
75
26dfa90016d1
error delete but 2 test program commentout and not action BulletinBoard
one
parents:
74
diff
changeset
|
53 return children; |
26dfa90016d1
error delete but 2 test program commentout and not action BulletinBoard
one
parents:
74
diff
changeset
|
54 } |
143
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
142
diff
changeset
|
55 |
75
26dfa90016d1
error delete but 2 test program commentout and not action BulletinBoard
one
parents:
74
diff
changeset
|
56 @Override |
81 | 57 public Either<Error,TreeNode> addNewChildAt(int _pos) |
37 | 58 { |
39 | 59 if(!boundaryCheck(_pos) || _pos < 0){ |
37 | 60 return DefaultEither.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); |
61 } | |
62 | |
81 | 63 P2<List<TreeNode>,List<TreeNode>> split = children.splitAt(_pos); |
64 List<TreeNode> newChildren = split._1().snoc(new DefaultTreeNode()).append(split._2()); | |
97 | 65 TreeNode newNode = new DefaultTreeNode(newChildren,attrs); |
71 | 66 return DefaultEither.newB(newNode); |
37 | 67 } |
68 | |
69 @Override | |
81 | 70 public Either<Error,TreeNode> deleteChildAt(int _pos) |
37 | 71 { |
39 | 72 if(!boundaryCheck(_pos) || _pos < 0 || size() == 0){ |
37 | 73 return DefaultEither.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); |
74 } | |
71 | 75 |
81 | 76 P2<List<TreeNode>,List<TreeNode>> split = children.splitAt(_pos); |
77 List<TreeNode> newChildren = split._1().append(split._2().tail()); | |
97 | 78 TreeNode newNode = new DefaultTreeNode(newChildren,attrs); |
37 | 79 |
71 | 80 return DefaultEither.newB(newNode); |
37 | 81 } |
82 | |
83 @Override | |
84 public int size() | |
85 { | |
71 | 86 return children.length(); |
37 | 87 } |
88 | |
89 @Override | |
81 | 90 public Iterator<TreeNode> iterator() |
37 | 91 { |
71 | 92 return children.iterator(); |
37 | 93 } |
94 | |
95 @Override | |
81 | 96 public Either<Error,TreeNode> replaceNode(int _pos,TreeNode _replacement) |
37 | 97 { |
71 | 98 int size = children.length(); |
41 | 99 if(!(0 <= _pos && _pos < size)){ |
37 | 100 return DefaultEither.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); |
101 } | |
81 | 102 TreeNode replacement = _replacement; |
37 | 103 |
81 | 104 P2<List<TreeNode>,List<TreeNode>> split = children.splitAt(_pos + 1); |
105 List<TreeNode> init = split._1().reverse().tail().reverse(); | |
106 List<TreeNode> newInit = init.snoc(replacement); | |
107 List<TreeNode> newList = newInit.append(split._2()); | |
108 TreeNode node = new DefaultTreeNode(newList,attrs); | |
109 return DefaultEither.newB(node); | |
37 | 110 } |
41 | 111 |
112 @Override | |
81 | 113 public Either<Error,TreeNode> at(int _pos) |
41 | 114 { |
143
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
142
diff
changeset
|
115 if(!boundaryCheck(_pos)){ |
142 | 116 return DefaultEither.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); |
117 } | |
118 | |
119 TreeNode Node = children.index(_pos); | |
41 | 120 |
71 | 121 return DefaultEither.newB(Node); |
41 | 122 } |
123 | |
124 @Override | |
81 | 125 public Either<Error,TreeNode> addNewChildAt(int _pos,TreeNode _newChild) |
41 | 126 { |
127 if(!boundaryCheck(_pos) || _pos < 0){ | |
128 return DefaultEither.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); | |
129 } | |
130 | |
131 | |
81 | 132 P2<List<TreeNode>,List<TreeNode>> split = children.splitAt(_pos); |
133 List<TreeNode> newChildren = split._1().snoc(_newChild).append(split._2()); | |
134 TreeNode newNode = new DefaultTreeNode(newChildren,attrs); | |
41 | 135 |
71 | 136 return DefaultEither.newB(newNode); |
41 | 137 } |
37 | 138 } |