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 part of html_common; | 5 part of html_common; |
6 | 6 |
7 /** | 7 /** |
8 * An indexable collection of a node's descendants in the document tree, | 8 * An indexable collection of a node's descendants in the document tree, |
9 * filtered so that only elements are in the collection. | 9 * filtered so that only elements are in the collection. |
10 */ | 10 */ |
(...skipping 28 matching lines...) Expand all Loading... |
39 } | 39 } |
40 | 40 |
41 void set length(int newLength) { | 41 void set length(int newLength) { |
42 final len = this.length; | 42 final len = this.length; |
43 if (newLength >= len) { | 43 if (newLength >= len) { |
44 return; | 44 return; |
45 } else if (newLength < 0) { | 45 } else if (newLength < 0) { |
46 throw new ArgumentError("Invalid list length"); | 46 throw new ArgumentError("Invalid list length"); |
47 } | 47 } |
48 | 48 |
49 removeRange(newLength, len - newLength); | 49 removeRange(newLength, len); |
50 } | 50 } |
51 | 51 |
52 String join([String separator = ""]) => _filtered.join(separator); | 52 String join([String separator = ""]) => _filtered.join(separator); |
53 | 53 |
54 void add(Element value) { | 54 void add(Element value) { |
55 _childNodes.add(value); | 55 _childNodes.add(value); |
56 } | 56 } |
57 | 57 |
58 void addAll(Iterable<Element> iterable) { | 58 void addAll(Iterable<Element> iterable) { |
59 for (Element element in iterable) { | 59 for (Element element in iterable) { |
60 add(element); | 60 add(element); |
61 } | 61 } |
62 } | 62 } |
63 | 63 |
64 bool contains(Element element) { | 64 bool contains(Element element) { |
65 return element is Element && _childNodes.contains(element); | 65 return element is Element && _childNodes.contains(element); |
66 } | 66 } |
67 | 67 |
68 Iterable<Element> get reversed => _filtered.reversed; | 68 Iterable<Element> get reversed => _filtered.reversed; |
69 | 69 |
70 void sort([int compare(Element a, Element b)]) { | 70 void sort([int compare(Element a, Element b)]) { |
71 throw new UnsupportedError('TODO(jacobr): should we impl?'); | 71 throw new UnsupportedError('TODO(jacobr): should we impl?'); |
72 } | 72 } |
73 | 73 |
74 void setRange(int start, int end, Iterable<Element> iterable, | 74 void setRange(int start, int end, Iterable<Element> iterable, |
75 [int skipCount = 0]) { | 75 [int skipCount = 0]) { |
76 throw new UnimplementedError(); | 76 throw new UnimplementedError(); |
77 } | 77 } |
78 | 78 |
79 void removeRange(int start, int rangeLength) { | 79 void removeRange(int start, int end) { |
80 _filtered.sublist(start, start + rangeLength).forEach((el) => el.remove()); | 80 _filtered.sublist(start, end).forEach((el) => el.remove()); |
81 } | |
82 | |
83 void insertRange(int start, int rangeLength, [initialValue = null]) { | |
84 throw new UnimplementedError(); | |
85 } | 81 } |
86 | 82 |
87 void clear() { | 83 void clear() { |
88 // Currently, ElementList#clear clears even non-element nodes, so we follow | 84 // Currently, ElementList#clear clears even non-element nodes, so we follow |
89 // that behavior. | 85 // that behavior. |
90 _childNodes.clear(); | 86 _childNodes.clear(); |
91 } | 87 } |
92 | 88 |
93 Element removeLast() { | 89 Element removeLast() { |
94 final result = this.last; | 90 final result = this.last; |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 Element get single => _filtered.single; | 189 Element get single => _filtered.single; |
194 | 190 |
195 Element min([int compare(Element a, Element b)]) => _filtered.min(compare); | 191 Element min([int compare(Element a, Element b)]) => _filtered.min(compare); |
196 | 192 |
197 Element max([int compare(Element a, Element b)]) => _filtered.max(compare); | 193 Element max([int compare(Element a, Element b)]) => _filtered.max(compare); |
198 | 194 |
199 Map<int, Element> asMap() { | 195 Map<int, Element> asMap() { |
200 return IterableMixinWorkaround.asMapList(this); | 196 return IterableMixinWorkaround.asMapList(this); |
201 } | 197 } |
202 } | 198 } |
OLD | NEW |