Chromium Code Reviews| 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._internal; | 5 part of dart._internal; |
| 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. |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 241 RangeError.checkValidIndex(index, this); | 241 RangeError.checkValidIndex(index, this); |
| 242 return index; | 242 return index; |
| 243 } | 243 } |
| 244 } | 244 } |
| 245 | 245 |
| 246 class ListMapView<E> implements Map<int, E> { | 246 class ListMapView<E> implements Map<int, E> { |
| 247 List<E> _values; | 247 List<E> _values; |
| 248 | 248 |
| 249 ListMapView(this._values); | 249 ListMapView(this._values); |
| 250 | 250 |
| 251 E operator[] (int key) => containsKey(key) ? _values[key] : null; | 251 E operator[] (Object key) => containsKey(key) ? _values[key] : null; |
|
vsm
2015/05/04 21:09:21
This is consistent with the Map.[] - but perhaps t
Leaf
2015/05/04 21:50:42
Yes, I'd probably prefer that as well. I was tryi
| |
| 252 int get length => _values.length; | 252 int get length => _values.length; |
| 253 | 253 |
| 254 Iterable<E> get values => new SubListIterable<E>(_values, 0, null); | 254 Iterable<E> get values => new SubListIterable<E>(_values, 0, null); |
| 255 Iterable<int> get keys => new _ListIndicesIterable(_values); | 255 Iterable<int> get keys => new _ListIndicesIterable(_values); |
| 256 | 256 |
| 257 bool get isEmpty => _values.isEmpty; | 257 bool get isEmpty => _values.isEmpty; |
| 258 bool get isNotEmpty => _values.isNotEmpty; | 258 bool get isNotEmpty => _values.isNotEmpty; |
| 259 bool containsValue(Object value) => _values.contains(value); | 259 bool containsValue(Object value) => _values.contains(value); |
| 260 bool containsKey(int key) => key is int && key >= 0 && key < length; | 260 bool containsKey(Object key) => key is int && key >= 0 && key < length; |
| 261 | 261 |
| 262 void forEach(void f(int key, E value)) { | 262 void forEach(void f(int key, E value)) { |
| 263 int length = _values.length; | 263 int length = _values.length; |
| 264 for (int i = 0; i < length; i++) { | 264 for (int i = 0; i < length; i++) { |
| 265 f(i, _values[i]); | 265 f(i, _values[i]); |
| 266 if (length != _values.length) { | 266 if (length != _values.length) { |
| 267 throw new ConcurrentModificationError(_values); | 267 throw new ConcurrentModificationError(_values); |
| 268 } | 268 } |
| 269 } | 269 } |
| 270 } | 270 } |
| 271 | 271 |
| 272 /** This operation is not supported by an unmodifiable map. */ | 272 /** This operation is not supported by an unmodifiable map. */ |
| 273 void operator[]= (int key, E value) { | 273 void operator[]= (int key, E value) { |
| 274 throw new UnsupportedError("Cannot modify an unmodifiable map"); | 274 throw new UnsupportedError("Cannot modify an unmodifiable map"); |
| 275 } | 275 } |
| 276 | 276 |
| 277 /** This operation is not supported by an unmodifiable map. */ | 277 /** This operation is not supported by an unmodifiable map. */ |
| 278 E putIfAbsent(int key, E ifAbsent()) { | 278 E putIfAbsent(int key, E ifAbsent()) { |
| 279 throw new UnsupportedError("Cannot modify an unmodifiable map"); | 279 throw new UnsupportedError("Cannot modify an unmodifiable map"); |
| 280 } | 280 } |
| 281 | 281 |
| 282 /** This operation is not supported by an unmodifiable map. */ | 282 /** This operation is not supported by an unmodifiable map. */ |
| 283 E remove(int key) { | 283 E remove(Object key) { |
| 284 throw new UnsupportedError("Cannot modify an unmodifiable map"); | 284 throw new UnsupportedError("Cannot modify an unmodifiable map"); |
| 285 } | 285 } |
| 286 | 286 |
| 287 /** This operation is not supported by an unmodifiable map. */ | 287 /** This operation is not supported by an unmodifiable map. */ |
| 288 void clear() { | 288 void clear() { |
| 289 throw new UnsupportedError("Cannot modify an unmodifiable map"); | 289 throw new UnsupportedError("Cannot modify an unmodifiable map"); |
| 290 } | 290 } |
| 291 | 291 |
| 292 /** This operation is not supported by an unmodifiable map. */ | 292 /** This operation is not supported by an unmodifiable map. */ |
| 293 void addAll(Map<int, E> other) { | 293 void addAll(Map<int, E> other) { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 367 * or become empty or been otherwise modified. | 367 * or become empty or been otherwise modified. |
| 368 * It will still be a valid object, so references to it will not, e.g., crash | 368 * It will still be a valid object, so references to it will not, e.g., crash |
| 369 * the runtime if accessed, but no promises are made wrt. its contents. | 369 * the runtime if accessed, but no promises are made wrt. its contents. |
| 370 * | 370 * |
| 371 * This unspecified behavior is the reason the function is not exposed to | 371 * This unspecified behavior is the reason the function is not exposed to |
| 372 * users. We allow the underlying implementation to make the most efficient | 372 * users. We allow the underlying implementation to make the most efficient |
| 373 * conversion, at the cost of leaving the original list in an unspecified | 373 * conversion, at the cost of leaving the original list in an unspecified |
| 374 * state. | 374 * state. |
| 375 */ | 375 */ |
| 376 external List makeListFixedLength(List growableList); | 376 external List makeListFixedLength(List growableList); |
| OLD | NEW |