| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 dart._collection.dev; | 5 part of dart._collection.dev; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Mixin that throws on the length changing operations of [List]. | 8 * Mixin that throws on the length changing operations of [List]. |
| 9 * | 9 * |
| 10 * Intended to mix-in on top of [ListMixin] for fixed-length lists. | 10 * Intended to mix-in on top of [ListMixin] for fixed-length lists. |
| 11 */ | 11 */ |
| 12 abstract class FixedLengthListMixin<E> { | 12 abstract class FixedLengthListMixin<E> { |
| 13 void set length(int newLength) { | 13 void set length(int newLength) { |
| 14 throw new UnsupportedError( | 14 throw new UnsupportedError( |
| 15 "Cannot change the length of a fixed-length list"); | 15 "Cannot change the length of a fixed-length list"); |
| 16 } | 16 } |
| 17 | 17 |
| 18 void add(E value) { | 18 void add(E value) { |
| 19 throw new UnsupportedError( | 19 throw new UnsupportedError( |
| 20 "Cannot add to a fixed-length list"); | 20 "Cannot add to a fixed-length list"); |
| 21 } | 21 } |
| 22 | 22 |
| 23 void insert(int index, E value) { | 23 void insert(int index, E value) { |
| 24 throw new UnsupportedError( | 24 throw new UnsupportedError( |
| 25 "Cannot add to a fixed-length list"); | 25 "Cannot add to a fixed-length list"); |
| 26 } | 26 } |
| 27 | 27 |
| 28 void insertAll(int at, Iterable<E> iterable) { |
| 29 throw new UnsupportedError( |
| 30 "Cannot add to a fixed-length list"); |
| 31 } |
| 32 |
| 28 void addAll(Iterable<E> iterable) { | 33 void addAll(Iterable<E> iterable) { |
| 29 throw new UnsupportedError( | 34 throw new UnsupportedError( |
| 30 "Cannot add to a fixed-length list"); | 35 "Cannot add to a fixed-length list"); |
| 31 } | 36 } |
| 32 | 37 |
| 33 void remove(E element) { | 38 void remove(E element) { |
| 34 throw new UnsupportedError( | 39 throw new UnsupportedError( |
| 35 "Cannot remove from a fixed-length list"); | 40 "Cannot remove from a fixed-length list"); |
| 36 } | 41 } |
| 37 | 42 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 67 | 72 |
| 68 E removeLast() { | 73 E removeLast() { |
| 69 throw new UnsupportedError( | 74 throw new UnsupportedError( |
| 70 "Cannot remove from a fixed-length list"); | 75 "Cannot remove from a fixed-length list"); |
| 71 } | 76 } |
| 72 | 77 |
| 73 void removeRange(int start, int end) { | 78 void removeRange(int start, int end) { |
| 74 throw new UnsupportedError( | 79 throw new UnsupportedError( |
| 75 "Cannot remove from a fixed-length list"); | 80 "Cannot remove from a fixed-length list"); |
| 76 } | 81 } |
| 82 |
| 83 void replaceRange(int start, int end, Iterable<E> iterable) { |
| 84 throw new UnsupportedError( |
| 85 "Cannot remove from a fixed-length list"); |
| 86 } |
| 77 } | 87 } |
| 78 | 88 |
| 79 /** | 89 /** |
| 80 * Mixin for an unmodifiable [List] class. | 90 * Mixin for an unmodifiable [List] class. |
| 81 * | 91 * |
| 82 * This overrides all mutating methods with methods that throw. | 92 * This overrides all mutating methods with methods that throw. |
| 83 * This mixin is intended to be mixed in on top of [ListMixin] on | 93 * This mixin is intended to be mixed in on top of [ListMixin] on |
| 84 * unmodifiable lists. | 94 * unmodifiable lists. |
| 85 */ | 95 */ |
| 86 abstract class UnmodifiableListMixin<E> { | 96 abstract class UnmodifiableListMixin<E> { |
| 87 | 97 |
| 88 void operator []=(int index, E value) { | 98 void operator []=(int index, E value) { |
| 89 throw new UnsupportedError( | 99 throw new UnsupportedError( |
| 90 "Cannot modify an unmodifiable list"); | 100 "Cannot modify an unmodifiable list"); |
| 91 } | 101 } |
| 92 | 102 |
| 93 void set length(int newLength) { | 103 void set length(int newLength) { |
| 94 throw new UnsupportedError( | 104 throw new UnsupportedError( |
| 95 "Cannot change the length of an unmodifiable list"); | 105 "Cannot change the length of an unmodifiable list"); |
| 96 } | 106 } |
| 97 | 107 |
| 108 void setAll(int at, Iterable<E> iterable) { |
| 109 throw new UnsupportedError( |
| 110 "Cannot modify an unmodifiable list"); |
| 111 } |
| 112 |
| 98 void add(E value) { | 113 void add(E value) { |
| 99 throw new UnsupportedError( | 114 throw new UnsupportedError( |
| 100 "Cannot add to an unmodifiable list"); | 115 "Cannot add to an unmodifiable list"); |
| 101 } | 116 } |
| 102 | 117 |
| 103 E insert(int index, E value) { | 118 E insert(int index, E value) { |
| 104 throw new UnsupportedError( | 119 throw new UnsupportedError( |
| 105 "Cannot add to an unmodifiable list"); | 120 "Cannot add to an unmodifiable list"); |
| 106 } | 121 } |
| 107 | 122 |
| 123 void insertAll(int at, Iterable<E> iterable) { |
| 124 throw new UnsupportedError( |
| 125 "Cannot add to an unmodifiable list"); |
| 126 } |
| 127 |
| 108 void addAll(Iterable<E> iterable) { | 128 void addAll(Iterable<E> iterable) { |
| 109 throw new UnsupportedError( | 129 throw new UnsupportedError( |
| 110 "Cannot add to an unmodifiable list"); | 130 "Cannot add to an unmodifiable list"); |
| 111 } | 131 } |
| 112 | 132 |
| 113 void remove(E element) { | 133 void remove(E element) { |
| 114 throw new UnsupportedError( | 134 throw new UnsupportedError( |
| 115 "Cannot remove from an unmodifiable list"); | 135 "Cannot remove from an unmodifiable list"); |
| 116 } | 136 } |
| 117 | 137 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 | 177 |
| 158 void setRange(int start, int end, Iterable<E> iterable, [int skipCount = 0]) { | 178 void setRange(int start, int end, Iterable<E> iterable, [int skipCount = 0]) { |
| 159 throw new UnsupportedError( | 179 throw new UnsupportedError( |
| 160 "Cannot modify an unmodifiable list"); | 180 "Cannot modify an unmodifiable list"); |
| 161 } | 181 } |
| 162 | 182 |
| 163 void removeRange(int start, int end) { | 183 void removeRange(int start, int end) { |
| 164 throw new UnsupportedError( | 184 throw new UnsupportedError( |
| 165 "Cannot remove from an unmodifiable list"); | 185 "Cannot remove from an unmodifiable list"); |
| 166 } | 186 } |
| 187 |
| 188 void replaceRange(int start, int end, Iterable<E> iterable) { |
| 189 throw new UnsupportedError( |
| 190 "Cannot remove from an unmodifiable list"); |
| 191 } |
| 192 |
| 193 void fillRange(int start, int end, [E fillValue]) { |
| 194 throw new UnsupportedError( |
| 195 "Cannot modify an unmodifiable list"); |
| 196 } |
| 167 } | 197 } |
| 168 | 198 |
| 169 /** | 199 /** |
| 170 * Abstract implementation of a fixed-length list. | 200 * Abstract implementation of a fixed-length list. |
| 171 * | 201 * |
| 172 * All operations are defined in terms of `length`, `operator[]` and | 202 * All operations are defined in terms of `length`, `operator[]` and |
| 173 * `operator[]=`, which need to be implemented. | 203 * `operator[]=`, which need to be implemented. |
| 174 */ | 204 */ |
| 175 typedef FixedLengthListBase<E> = ListBase<E> with FixedLengthListMixin<E>; | 205 typedef FixedLengthListBase<E> = ListBase<E> with FixedLengthListMixin<E>; |
| 176 | 206 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 } | 269 } |
| 240 | 270 |
| 241 class ReversedListIterable<E> extends ListIterable<E> { | 271 class ReversedListIterable<E> extends ListIterable<E> { |
| 242 Iterable<E> _source; | 272 Iterable<E> _source; |
| 243 ReversedListIterable(this._source); | 273 ReversedListIterable(this._source); |
| 244 | 274 |
| 245 int get length => _source.length; | 275 int get length => _source.length; |
| 246 | 276 |
| 247 E elementAt(int index) => _source.elementAt(_source.length - 1 - index); | 277 E elementAt(int index) => _source.elementAt(_source.length - 1 - index); |
| 248 } | 278 } |
| OLD | NEW |