Mercurial > hg > Database > jungle-sharp
comparison src/main/csharp/jp.ac.u-ryukyu.ie.cr/jungle-main/transaction/DefaultTreeNodeChildren.cs @ 17:01a08cf4b2d9
Liq Files
author | Kazuma |
---|---|
date | Mon, 07 Nov 2016 01:05:24 +0900 |
parents | abe0c247f5a5 |
children |
comparison
equal
deleted
inserted
replaced
16:8f1ce942abfc | 17:01a08cf4b2d9 |
---|---|
1 using UnityEngine; | |
2 using System.Collections; | |
3 | |
4 public class DefaultTreeNodeChildren : TreeNodeChildren { | |
5 | |
6 public List<TreeNode> children; | |
7 public TreeMap<string, byte[]> attrs; | |
8 | |
9 public DefaultTreeNodeChildren(List<TreeNode> _children, TreeMap<string, byte[]> _attrs){ | |
10 children = _children; | |
11 attrs = _attrs; | |
12 } | |
13 | |
14 private bool boundaryCheck(int _pos) { | |
15 int size = children.length (); | |
16 if (size < _pos) { | |
17 return false; | |
18 } | |
19 return true; | |
20 } | |
21 | |
22 public List<TreeNode> getChildrenAsRawList() { | |
23 return children; | |
24 } | |
25 | |
26 public Either<Error, TreeNode> addNewChildAt(int _pos) { | |
27 if (!boundaryCheck(_pos) || _pos < 0) { | |
28 return DefaultEither<Error, TreeNode>.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); | |
29 } | |
30 | |
31 List<TreeNode> newChildren = children.add(_pos, new DefaultTreeNode()); | |
32 TreeNode newNode = new DefaultTreeNode(newChildren, attrs); | |
33 return DefaultEither<Error, TreeNode>.newB(newNode); | |
34 } | |
35 | |
36 | |
37 public Either<Error, TreeNode> deleteChildAt(int _pos) { | |
38 if (!boundaryCheck(_pos) || _pos < 0 || size() == 0) { | |
39 return DefaultEither<Error, TreeNode>.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); | |
40 } | |
41 | |
42 List<TreeNode> newChildren = children.delete(_pos); | |
43 TreeNode newNode = new DefaultTreeNode(newChildren, attrs); | |
44 | |
45 return DefaultEither<Error, TreeNode>.newB(newNode); | |
46 } | |
47 | |
48 | |
49 public int size() { | |
50 return children.length(); | |
51 } | |
52 | |
53 | |
54 // public Iterator<TreeNode> iterator() { | |
55 // return children.iterator(); | |
56 // } | |
57 | |
58 | |
59 public Either<Error, TreeNode> replaceNode(int _pos, TreeNode _replacement) { | |
60 int size = children.length(); | |
61 if (!(0 <= _pos && _pos < size)) { | |
62 return DefaultEither<Error, TreeNode>.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); | |
63 } | |
64 TreeNode replacement = _replacement; | |
65 | |
66 List<TreeNode> newChildren = children.replace(_pos, replacement); | |
67 TreeNode node = new DefaultTreeNode(newChildren, attrs); | |
68 return DefaultEither<Error, TreeNode>.newB(node); | |
69 } | |
70 | |
71 | |
72 public Either<Error, TreeNode> at(int _pos) { | |
73 if (children.length() < _pos + 1) { | |
74 return DefaultEither<Error, TreeNode>.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); | |
75 } | |
76 | |
77 TreeNode Node = children.index(_pos); | |
78 | |
79 return DefaultEither<Error, TreeNode>.newB(Node); | |
80 } | |
81 | |
82 | |
83 public Either<Error, TreeNode> addNewChildAt(int _pos, TreeNode _newChild) { | |
84 if (!boundaryCheck(_pos) || _pos < 0) { | |
85 return DefaultEither<Error, TreeNode>.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); | |
86 } | |
87 List<TreeNode> newChildren = children.add(_pos, _newChild); | |
88 TreeNode newNode = new DefaultTreeNode(newChildren, attrs); | |
89 | |
90 return DefaultEither<Error, TreeNode>.newB(newNode); | |
91 } | |
92 | |
93 } |