Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: tools/dom/templates/immutable_list_mixin.darttemplate

Issue 11783009: Big merge from experimental to bleeding edge. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // -- start List<$E> mixins. 1 // -- start List<$E> mixins.
2 // $E is the element type. 2 // $E is the element type.
3 3
4 // From Iterable<$E>: 4 // From Iterable<$E>:
5 5
6 Iterator<$E> iterator() { 6 Iterator<$E> get iterator {
7 // Note: NodeLists are not fixed size. And most probably length shouldn't 7 // Note: NodeLists are not fixed size. And most probably length shouldn't
8 // be cached in both iterator _and_ forEach method. For now caching it 8 // be cached in both iterator _and_ forEach method. For now caching it
9 // for consistency. 9 // for consistency.
10 return new FixedSizeListIterator<$E>(this); 10 return new FixedSizeListIterator<$E>(this);
11 } 11 }
12 12
13 // From Collection<$E>:
14 $if DEFINE_LENGTH_AS_NUM_ITEMS 13 $if DEFINE_LENGTH_AS_NUM_ITEMS
15 // SVG Collections expose numberOfItems rather than length. 14 // SVG Collections expose numberOfItems rather than length.
16 int get length => numberOfItems; 15 int get length => numberOfItems;
17 $endif 16 $endif
18
19 void add($E value) {
20 throw new UnsupportedError("Cannot add to immutable List.");
21 }
22
23 void addLast($E value) {
24 throw new UnsupportedError("Cannot add to immutable List.");
25 }
26
27 void addAll(Collection<$E> collection) {
28 throw new UnsupportedError("Cannot add to immutable List.");
29 }
30
31 dynamic reduce(dynamic initialValue, dynamic combine(dynamic, $E)) { 17 dynamic reduce(dynamic initialValue, dynamic combine(dynamic, $E)) {
32 return Collections.reduce(this, initialValue, combine); 18 return Collections.reduce(this, initialValue, combine);
33 } 19 }
34 20
35 $if DEFINE_CONTAINS 21 $if DEFINE_CONTAINS
36 bool contains($E element) => Collections.contains(this, element); 22 bool contains($E element) => Collections.contains(this, element);
37 $else 23 $else
38 // contains() defined by IDL. 24 // contains() defined by IDL.
39 $endif 25 $endif
40 26
41 void forEach(void f($E element)) => Collections.forEach(this, f); 27 void forEach(void f($E element)) => Collections.forEach(this, f);
42 28
43 Collection map(f($E element)) => Collections.map(this, [], f); 29 String join([String separator]) => Collections.joinList(this, separator);
44 30
45 Collection<$E> filter(bool f($E element)) => 31 List mappedBy(f($E element)) => new MappedList<$E, dynamic>(this, f);
46 Collections.filter(this, <$E>[], f); 32
33 Iterable<$E> where(bool f($E element)) => new WhereIterable<$E>(this, f);
47 34
48 bool every(bool f($E element)) => Collections.every(this, f); 35 bool every(bool f($E element)) => Collections.every(this, f);
49 36
50 bool some(bool f($E element)) => Collections.some(this, f); 37 bool any(bool f($E element)) => Collections.any(this, f);
51 38
52 bool get isEmpty => this.length == 0; 39 bool get isEmpty => this.length == 0;
53 40
41 List<$E> take(int n) => new ListView<$E>(this, 0, n);
42
43 Iterable<$E> takeWhile(bool test($E value)) {
44 return new TakeWhileIterable<$E>(this, test);
45 }
46
47 List<$E> skip(int n) => new ListView<$E>(this, n, null);
48
49 Iterable<$E> skipWhile(bool test($E value)) {
50 return new SkipWhileIterable<$E>(this, test);
51 }
52
53 $E firstMatching(bool test($E value), { $E orElse() }) {
54 return Collections.firstMatching(this, test, orElse);
55 }
56
57 $E lastMatching(bool test($E value), {$E orElse()}) {
58 return Collections.lastMatchingInList(this, test, orElse);
59 }
60
61 $E singleMatching(bool test($E value)) {
62 return Collections.singleMatching(this, test);
63 }
64
65 $E elementAt(int index) {
66 return this[index];
67 }
68
69 // From Collection<$E>:
70
71 void add($E value) {
72 throw new UnsupportedError("Cannot add to immutable List.");
73 }
74
75 void addLast($E value) {
76 throw new UnsupportedError("Cannot add to immutable List.");
77 }
78
79 void addAll(Iterable<$E> iterable) {
80 throw new UnsupportedError("Cannot add to immutable List.");
81 }
82
54 // From List<$E>: 83 // From List<$E>:
55 $if DEFINE_LENGTH_SETTER 84 $if DEFINE_LENGTH_SETTER
56 void set length(int value) { 85 void set length(int value) {
57 throw new UnsupportedError("Cannot resize immutable List."); 86 throw new UnsupportedError("Cannot resize immutable List.");
58 } 87 }
59 $endif 88 $endif
60 89
61 $if DEFINE_CLEAR 90 $if DEFINE_CLEAR
62 void clear() { 91 void clear() {
63 throw new UnsupportedError("Cannot clear immutable List."); 92 throw new UnsupportedError("Cannot clear immutable List.");
64 } 93 }
65 $else 94 $else
66 // contains() defined by IDL. 95 // contains() defined by IDL.
67 $endif 96 $endif
68 97
69 void sort([int compare($E a, $E b)]) { 98 void sort([int compare($E a, $E b)]) {
70 throw new UnsupportedError("Cannot sort immutable List."); 99 throw new UnsupportedError("Cannot sort immutable List.");
71 } 100 }
72 101
73 int indexOf($E element, [int start = 0]) => 102 int indexOf($E element, [int start = 0]) =>
74 Lists.indexOf(this, element, start, this.length); 103 Lists.indexOf(this, element, start, this.length);
75 104
76 int lastIndexOf($E element, [int start]) { 105 int lastIndexOf($E element, [int start]) {
77 if (start == null) start = length - 1; 106 if (start == null) start = length - 1;
78 return Lists.lastIndexOf(this, element, start); 107 return Lists.lastIndexOf(this, element, start);
79 } 108 }
80 109
81 $E get first => this[0]; 110 $E get first {
111 if (this.length > 0) return this[0];
112 throw new StateError("No elements");
113 }
82 114
83 $E get last => this[length - 1]; 115 $E get last {
116 if (this.length > 0) return this[this.length - 1];
117 throw new StateError("No elements");
118 }
119
120 $E get single {
121 if (length == 1) return this[0];
122 if (length == 0) throw new StateError("No elements");
123 throw new StateError("More than one element");
124 }
125
126 $E min([int compare($E a, $E b)]) => _Collections.minInList(this, compare);
127
128 $E max([int compare($E a, $E b)]) => _Collections.maxInList(this, compare);
84 129
85 $E removeAt(int pos) { 130 $E removeAt(int pos) {
86 throw new UnsupportedError("Cannot removeAt on immutable List."); 131 throw new UnsupportedError("Cannot removeAt on immutable List.");
87 } 132 }
88 133
89 $E removeLast() { 134 $E removeLast() {
90 throw new UnsupportedError("Cannot removeLast on immutable List."); 135 throw new UnsupportedError("Cannot removeLast on immutable List.");
91 } 136 }
92 137
93 void setRange(int start, int rangeLength, List<$E> from, [int startFrom]) { 138 void setRange(int start, int rangeLength, List<$E> from, [int startFrom]) {
94 throw new UnsupportedError("Cannot setRange on immutable List."); 139 throw new UnsupportedError("Cannot setRange on immutable List.");
95 } 140 }
96 141
97 void removeRange(int start, int rangeLength) { 142 void removeRange(int start, int rangeLength) {
98 throw new UnsupportedError("Cannot removeRange on immutable List."); 143 throw new UnsupportedError("Cannot removeRange on immutable List.");
99 } 144 }
100 145
101 void insertRange(int start, int rangeLength, [$E initialValue]) { 146 void insertRange(int start, int rangeLength, [$E initialValue]) {
102 throw new UnsupportedError("Cannot insertRange on immutable List."); 147 throw new UnsupportedError("Cannot insertRange on immutable List.");
103 } 148 }
104 149
105 List<$E> getRange(int start, int rangeLength) => 150 List<$E> getRange(int start, int rangeLength) =>
106 Lists.getRange(this, start, rangeLength, <$E>[]); 151 Lists.getRange(this, start, rangeLength, <$E>[]);
107 152
108 // -- end List<$E> mixins. 153 // -- end List<$E> mixins.
OLDNEW
« no previous file with comments | « tools/dom/templates/html/impl/impl_Storage.darttemplate ('k') | tools/html_json_doc/lib/json_to_html.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698