OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 class _ChildrenNodeList implements NodeList { | 5 class _ChildrenNodeList implements NodeList { |
6 // Raw node. | 6 // Raw node. |
7 final _node; | 7 final _node; |
8 final _childNodes; | 8 final _childNodes; |
9 | 9 |
10 _ChildrenNodeList._wrap(var node) | 10 _ChildrenNodeList._wrap(var node) |
11 : _childNodes = node.childNodes, | 11 : _childNodes = node.childNodes, |
12 _node = node; | 12 _node = node; |
13 | 13 |
14 List<Node> _toList() { | 14 List<Node> _toList() { |
15 final output = new List(_childNodes.length); | 15 final output = new List(_childNodes.length); |
16 for (int i = 0, len = _childNodes.length; i < len; i++) { | 16 for (int i = 0, len = _childNodes.length; i < len; i++) { |
17 output[i] = LevelDom.wrapNode(_childNodes[i]); | 17 output[i] = LevelDom.wrapNode(_childNodes[i]); |
18 } | 18 } |
19 return output; | 19 return output; |
20 } | 20 } |
21 | 21 |
22 Node get first() { | 22 Node get first() { |
23 return LevelDom.wrapNode(_node.firstChild); | 23 return LevelDom.wrapNode(_node.firstChild); |
24 } | 24 } |
25 | 25 |
26 void forEach(void f(Node element)) => _toList().forEach(f); | 26 void forEach(void f(Node element)) => _toList().forEach(f); |
27 | 27 |
28 Collection map(f(Node element)) => _toList().map(f); | 28 Collection map(f(Node element)) { |
| 29 List output = new List(); |
| 30 forEach((Node element) { |
| 31 output.add(f(element)); |
| 32 }); |
| 33 return output; |
| 34 } |
29 | 35 |
30 Collection<Node> filter(bool f(Node element)) => _toList().filter(f); | 36 Collection<Node> filter(bool f(Node element)) { |
| 37 List<Node> output = new List<Node>(); |
| 38 forEach((Node element) { |
| 39 if (f(element)) { |
| 40 output.add(element); |
| 41 } |
| 42 }); |
| 43 return output; |
| 44 } |
31 | 45 |
32 bool every(bool f(Node element)) { | 46 bool every(bool f(Node element)) { |
33 for(Node element in this) { | 47 for(Node element in this) { |
34 if (!f(element)) { | 48 if (!f(element)) { |
35 return false; | 49 return false; |
36 } | 50 } |
37 }; | 51 }; |
38 return true; | 52 return true; |
39 } | 53 } |
40 | 54 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 } | 104 } |
91 | 105 |
92 void sort(int compare(Node a, Node b)) { | 106 void sort(int compare(Node a, Node b)) { |
93 throw const UnsupportedOperationException('TODO(jacobr): should we impl?'); | 107 throw const UnsupportedOperationException('TODO(jacobr): should we impl?'); |
94 } | 108 } |
95 | 109 |
96 void copyFrom(List<Object> src, int srcStart, int dstStart, int count) { | 110 void copyFrom(List<Object> src, int srcStart, int dstStart, int count) { |
97 throw 'Not impl yet. todo(jacobr)'; | 111 throw 'Not impl yet. todo(jacobr)'; |
98 } | 112 } |
99 | 113 |
100 void setRange(int start, int length, List from, [int startFrom = 0]) => | 114 void setRange(int start, int length, List from, [int startFrom = 0]) { |
101 Lists.setRange(this, start, length, from, startFrom); | 115 // TODO(nweiz): remove these IndexOutOfRange checks once Frog has bounds |
| 116 // checking for List indexing |
| 117 if (start < 0) { |
| 118 throw new IndexOutOfRangeException(start); |
| 119 } else if (startFrom < 0) { |
| 120 throw new IndexOutOfRangeException(startFrom); |
| 121 } else if (length < 0) { |
| 122 throw new IllegalArgumentException("negative length $length"); |
| 123 } else if (start + length > this.length) { |
| 124 throw new IndexOutOfRangeException(Math.min(this.length, start)); |
| 125 } else if (startFrom + length > from.length) { |
| 126 throw new IndexOutOfRangeException(Math.min(from.length, startFrom)); |
| 127 } |
102 | 128 |
103 void removeRange(int start, int length) => | 129 for (var i = 0; i < length; i++) { |
104 Lists.removeRange(this, start, length, (i) => this[i].remove()); | 130 this[start + i] = from[startFrom + i]; |
| 131 } |
| 132 } |
| 133 |
| 134 void removeRange(int start, int length) { |
| 135 // TODO(nweiz): remove these IndexOutOfRange checks once Frog has bounds |
| 136 // checking for List indexing |
| 137 if (start < 0) { |
| 138 throw new IndexOutOfRangeException(start); |
| 139 } else if (length < 0) { |
| 140 throw new IllegalArgumentException("negative length $length"); |
| 141 } else if (start + length > this.length) { |
| 142 throw new IndexOutOfRangeException(Math.min(this.length, start)); |
| 143 } |
| 144 |
| 145 for (var i = 0; i < length; i++) { |
| 146 this[start].remove(); |
| 147 } |
| 148 } |
105 | 149 |
106 void insertRange(int start, int length, [initialValue = null]) { | 150 void insertRange(int start, int length, [initialValue = null]) { |
107 throw const NotImplementedException(); | 151 throw const NotImplementedException(); |
108 } | 152 } |
109 | 153 |
110 List getRange(int start, int length) => Lists.getRange(this, start, length); | 154 List getRange(int start, int length) { |
| 155 // TODO(nweiz): remove these IndexOutOfRange checks once Frog has bounds |
| 156 // checking for List indexing |
| 157 if (start < 0) { |
| 158 throw new IndexOutOfRangeException(start); |
| 159 } else if (length < 0) { |
| 160 throw new IllegalArgumentException("negative length $length"); |
| 161 } else if (start + length > this.length) { |
| 162 throw new IndexOutOfRangeException(Math.min(this.length, start)); |
| 163 } |
| 164 |
| 165 var nodes = <Node>[]; |
| 166 for (var i = 0; i < length; i++) { |
| 167 nodes.add(this[start + i]); |
| 168 } |
| 169 return nodes; |
| 170 } |
111 | 171 |
112 int indexOf(Node element, [int start = 0]) { | 172 int indexOf(Node element, [int start = 0]) { |
113 return Lists.indexOf(this, element, start, this.length); | 173 return _Lists.indexOf(this, element, start, this.length); |
114 } | 174 } |
115 | 175 |
116 int lastIndexOf(Node element, [int start = null]) { | 176 int lastIndexOf(Node element, [int start = null]) { |
117 if (start === null) start = length - 1; | 177 if (start === null) start = length - 1; |
118 return Lists.lastIndexOf(this, element, start); | 178 return _Lists.lastIndexOf(this, element, start); |
119 } | 179 } |
120 | 180 |
121 void clear() { | 181 void clear() { |
122 _node.textContent = ''; | 182 _node.textContent = ''; |
123 } | 183 } |
124 | 184 |
125 Node removeLast() { | 185 Node removeLast() { |
126 final last = this.last(); | 186 final last = this.last(); |
127 if (last != null) { | 187 if (last != null) { |
128 _node.removeChild(LevelDom.unwrap(last)); | 188 _node.removeChild(LevelDom.unwrap(last)); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 // array. | 258 // array. |
199 Node insertBefore(Node newChild, Node refChild) { | 259 Node insertBefore(Node newChild, Node refChild) { |
200 return LevelDom.wrapNode(_ptr.insertBefore( | 260 return LevelDom.wrapNode(_ptr.insertBefore( |
201 LevelDom.unwrap(newChild), LevelDom.unwrap(refChild))); | 261 LevelDom.unwrap(newChild), LevelDom.unwrap(refChild))); |
202 } | 262 } |
203 | 263 |
204 Node clone(bool deep) { | 264 Node clone(bool deep) { |
205 return LevelDom.wrapNode(_ptr.cloneNode(deep)); | 265 return LevelDom.wrapNode(_ptr.cloneNode(deep)); |
206 } | 266 } |
207 } | 267 } |
OLD | NEW |