| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 _GrowableObjectArray<T> implements List<T> { | 5 class _GrowableObjectArray<T> implements List<T> { |
| 6 static final int _classId = (new _GrowableObjectArray(0))._cid; | 6 static final int _classId = (new _GrowableObjectArray(0))._cid; |
| 7 | 7 |
| 8 void insert(int index, T element) { | 8 void insert(int index, T element) { |
| 9 if (index < 0 || index > length) { | 9 if (index < 0 || index > length) { |
| 10 throw new RangeError.range(index, 0, length); | 10 throw new RangeError.range(index, 0, length); |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 if (length > 0) return this[length - 1]; | 205 if (length > 0) return this[length - 1]; |
| 206 throw new StateError("No elements"); | 206 throw new StateError("No elements"); |
| 207 } | 207 } |
| 208 | 208 |
| 209 T get single { | 209 T get single { |
| 210 if (length == 1) return this[0]; | 210 if (length == 1) return this[0]; |
| 211 if (length == 0) throw new StateError("No elements"); | 211 if (length == 0) throw new StateError("No elements"); |
| 212 throw new StateError("More than one element"); | 212 throw new StateError("More than one element"); |
| 213 } | 213 } |
| 214 | 214 |
| 215 int indexOf(T element, [int start = 0]) { | 215 int indexOf(Object element, [int start = 0]) { |
| 216 return IterableMixinWorkaround.indexOfList(this, element, start); | 216 return IterableMixinWorkaround.indexOfList(this, element, start); |
| 217 } | 217 } |
| 218 | 218 |
| 219 int lastIndexOf(T element, [int start = null]) { | 219 int lastIndexOf(Object element, [int start = null]) { |
| 220 return IterableMixinWorkaround.lastIndexOfList(this, element, start); | 220 return IterableMixinWorkaround.lastIndexOfList(this, element, start); |
| 221 } | 221 } |
| 222 | 222 |
| 223 void _grow(int new_length) { | 223 void _grow(int new_length) { |
| 224 var new_data = new _ObjectArray(new_length); | 224 var new_data = new _ObjectArray(new_length); |
| 225 for (int i = 0; i < length; i++) { | 225 for (int i = 0; i < length; i++) { |
| 226 new_data[i] = this[i]; | 226 new_data[i] = this[i]; |
| 227 } | 227 } |
| 228 _setData(new_data); | 228 _setData(new_data); |
| 229 } | 229 } |
| 230 | 230 |
| 231 // Collection interface. | 231 // Collection interface. |
| 232 | 232 |
| 233 bool contains(T element) { | 233 bool contains(Object element) { |
| 234 return IterableMixinWorkaround.contains(this, element); | 234 return IterableMixinWorkaround.contains(this, element); |
| 235 } | 235 } |
| 236 | 236 |
| 237 void forEach(f(T element)) { | 237 void forEach(f(T element)) { |
| 238 int initialLength = length; | 238 int initialLength = length; |
| 239 for (int i = 0; i < length; i++) { | 239 for (int i = 0; i < length; i++) { |
| 240 f(this[i]); | 240 f(this[i]); |
| 241 if (length != initialLength) throw new ConcurrentModificationError(this); | 241 if (length != initialLength) throw new ConcurrentModificationError(this); |
| 242 } | 242 } |
| 243 } | 243 } |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 } | 349 } |
| 350 | 350 |
| 351 Set<T> toSet() { | 351 Set<T> toSet() { |
| 352 return new Set<T>.from(this); | 352 return new Set<T>.from(this); |
| 353 } | 353 } |
| 354 | 354 |
| 355 Map<int, T> asMap() { | 355 Map<int, T> asMap() { |
| 356 return IterableMixinWorkaround.asMapList(this); | 356 return IterableMixinWorkaround.asMapList(this); |
| 357 } | 357 } |
| 358 } | 358 } |
| OLD | NEW |