| OLD | NEW |
| (Empty) |
| 1 part of dart._internal; | |
| 2 abstract class EfficientLength {int get length; | |
| 3 } | |
| 4 abstract class ListIterable<E> extends IterableBase<E> implements EfficientLeng
th {int get length; | |
| 5 E elementAt(int i); | |
| 6 const ListIterable(); | |
| 7 Iterator<E> get iterator => new ListIterator<E>(this); | |
| 8 void forEach(void action(E element)) { | |
| 9 int length = this.length; | |
| 10 for (int i = 0; i < length; i++) { | |
| 11 action(elementAt(i)); | |
| 12 if (length != this.length) { | |
| 13 throw new ConcurrentModificationError(this); | |
| 14 } | |
| 15 } | |
| 16 } | |
| 17 bool get isEmpty => length == 0; | |
| 18 E get first { | |
| 19 if (length == 0) throw IterableElementError.noElement(); | |
| 20 return elementAt(0); | |
| 21 } | |
| 22 E get last { | |
| 23 if (length == 0) throw IterableElementError.noElement(); | |
| 24 return elementAt(length - 1); | |
| 25 } | |
| 26 E get single { | |
| 27 if (length == 0) throw IterableElementError.noElement(); | |
| 28 if (length > 1) throw IterableElementError.tooMany(); | |
| 29 return elementAt(0); | |
| 30 } | |
| 31 bool contains(Object element) { | |
| 32 int length = this.length; | |
| 33 for (int i = 0; i < length; i++) { | |
| 34 if (elementAt(i) == element) return true; | |
| 35 if (length != this.length) { | |
| 36 throw new ConcurrentModificationError(this); | |
| 37 } | |
| 38 } | |
| 39 return false; | |
| 40 } | |
| 41 bool every(bool test(E element)) { | |
| 42 int length = this.length; | |
| 43 for (int i = 0; i < length; i++) { | |
| 44 if (!test(elementAt(i))) return false; | |
| 45 if (length != this.length) { | |
| 46 throw new ConcurrentModificationError(this); | |
| 47 } | |
| 48 } | |
| 49 return true; | |
| 50 } | |
| 51 bool any(bool test(E element)) { | |
| 52 int length = this.length; | |
| 53 for (int i = 0; i < length; i++) { | |
| 54 if (test(elementAt(i))) return true; | |
| 55 if (length != this.length) { | |
| 56 throw new ConcurrentModificationError(this); | |
| 57 } | |
| 58 } | |
| 59 return false; | |
| 60 } | |
| 61 E firstWhere(bool test(E element), { | |
| 62 E orElse()} | |
| 63 ) { | |
| 64 int length = this.length; | |
| 65 for (int i = 0; i < length; i++) { | |
| 66 E element = elementAt(i); | |
| 67 if (test(element)) return element; | |
| 68 if (length != this.length) { | |
| 69 throw new ConcurrentModificationError(this); | |
| 70 } | |
| 71 } | |
| 72 if (orElse != null) return orElse(); | |
| 73 throw IterableElementError.noElement(); | |
| 74 } | |
| 75 E lastWhere(bool test(E element), { | |
| 76 E orElse()} | |
| 77 ) { | |
| 78 int length = this.length; | |
| 79 for (int i = length - 1; i >= 0; i--) { | |
| 80 E element = elementAt(i); | |
| 81 if (test(element)) return element; | |
| 82 if (length != this.length) { | |
| 83 throw new ConcurrentModificationError(this); | |
| 84 } | |
| 85 } | |
| 86 if (orElse != null) return orElse(); | |
| 87 throw IterableElementError.noElement(); | |
| 88 } | |
| 89 E singleWhere(bool test(E element)) { | |
| 90 int length = this.length; | |
| 91 E match = null; | |
| 92 bool matchFound = false; | |
| 93 for (int i = 0; i < length; i++) { | |
| 94 E element = elementAt(i); | |
| 95 if (test(element)) { | |
| 96 if (matchFound) { | |
| 97 throw IterableElementError.tooMany(); | |
| 98 } | |
| 99 matchFound = true; | |
| 100 match = element; | |
| 101 } | |
| 102 if (length != this.length) { | |
| 103 throw new ConcurrentModificationError(this); | |
| 104 } | |
| 105 } | |
| 106 if (matchFound) return match; | |
| 107 throw IterableElementError.noElement(); | |
| 108 } | |
| 109 String join([String separator = ""]) { | |
| 110 int length = this.length; | |
| 111 if (!separator.isEmpty) { | |
| 112 if (length == 0) return ""; | |
| 113 String first = "${elementAt(0)}"; | |
| 114 if (length != this.length) { | |
| 115 throw new ConcurrentModificationError(this); | |
| 116 } | |
| 117 StringBuffer buffer = new StringBuffer(first); | |
| 118 for (int i = 1; i < length; i++) { | |
| 119 buffer.write(separator); | |
| 120 buffer.write(elementAt(i)); | |
| 121 if (length != this.length) { | |
| 122 throw new ConcurrentModificationError(this); | |
| 123 } | |
| 124 } | |
| 125 return buffer.toString(); | |
| 126 } | |
| 127 else { | |
| 128 StringBuffer buffer = new StringBuffer(); | |
| 129 for (int i = 0; i < length; i++) { | |
| 130 buffer.write(elementAt(i)); | |
| 131 if (length != this.length) { | |
| 132 throw new ConcurrentModificationError(this); | |
| 133 } | |
| 134 } | |
| 135 return buffer.toString(); | |
| 136 } | |
| 137 } | |
| 138 Iterable<E> where(bool test(E element)) => super.where(test); | |
| 139 Iterable map(f(E element)) => new MappedListIterable(this, f); | |
| 140 E reduce(E combine(var value, E element)) { | |
| 141 int length = this.length; | |
| 142 if (length == 0) throw IterableElementError.noElement(); | |
| 143 E value = elementAt(0); | |
| 144 for (int i = 1; i < length; i++) { | |
| 145 value = combine(value, elementAt(i)); | |
| 146 if (length != this.length) { | |
| 147 throw new ConcurrentModificationError(this); | |
| 148 } | |
| 149 } | |
| 150 return value; | |
| 151 } | |
| 152 fold(var initialValue, combine(var previousValue, E element)) { | |
| 153 var value = initialValue; | |
| 154 int length = this.length; | |
| 155 for (int i = 0; i < length; i++) { | |
| 156 value = combine(value, elementAt(i)); | |
| 157 if (length != this.length) { | |
| 158 throw new ConcurrentModificationError(this); | |
| 159 } | |
| 160 } | |
| 161 return value; | |
| 162 } | |
| 163 Iterable<E> skip(int count) => new SubListIterable<E>(this, count, null); | |
| 164 Iterable<E> skipWhile(bool test(E element)) => super.skipWhile(test); | |
| 165 Iterable<E> take(int count) => new SubListIterable<E>(this, 0, count); | |
| 166 Iterable<E> takeWhile(bool test(E element)) => super.takeWhile(test); | |
| 167 List<E> toList({ | |
| 168 bool growable : true} | |
| 169 ) { | |
| 170 List<E> result; | |
| 171 if (growable) { | |
| 172 result = new List<E>()..length = length; | |
| 173 } | |
| 174 else { | |
| 175 result = new List<E>(length); | |
| 176 } | |
| 177 for (int i = 0; i < length; i++) { | |
| 178 result[i] = elementAt(i); | |
| 179 } | |
| 180 return result; | |
| 181 } | |
| 182 Set<E> toSet() { | |
| 183 Set<E> result = new Set<E>(); | |
| 184 for (int i = 0; i < length; i++) { | |
| 185 result.add(elementAt(i)); | |
| 186 } | |
| 187 return result; | |
| 188 } | |
| 189 } | |
| 190 class SubListIterable<E> extends ListIterable<E> {final Iterable<E> _iterable; | |
| 191 final int _start; | |
| 192 final int _endOrLength; | |
| 193 SubListIterable(this._iterable, this._start, this._endOrLength) { | |
| 194 RangeError.checkNotNegative(_start, "start"); | |
| 195 if (_endOrLength != null) { | |
| 196 RangeError.checkNotNegative(_endOrLength, "end"); | |
| 197 if (_start > _endOrLength) { | |
| 198 throw new RangeError.range(_start, 0, _endOrLength, "start"); | |
| 199 } | |
| 200 } | |
| 201 } | |
| 202 int get _endIndex { | |
| 203 int length = _iterable.length; | |
| 204 if (_endOrLength == null || _endOrLength > length) return length; | |
| 205 return _endOrLength; | |
| 206 } | |
| 207 int get _startIndex { | |
| 208 int length = _iterable.length; | |
| 209 if (_start > length) return length; | |
| 210 return _start; | |
| 211 } | |
| 212 int get length { | |
| 213 int length = _iterable.length; | |
| 214 if (_start >= length) return 0; | |
| 215 if (_endOrLength == null || _endOrLength >= length) { | |
| 216 return length - _start; | |
| 217 } | |
| 218 return _endOrLength - _start; | |
| 219 } | |
| 220 E elementAt(int index) { | |
| 221 int realIndex = _startIndex + index; | |
| 222 if (index < 0 || realIndex >= _endIndex) { | |
| 223 throw new RangeError.index(index, this, "index"); | |
| 224 } | |
| 225 return _iterable.elementAt(realIndex); | |
| 226 } | |
| 227 Iterable<E> skip(int count) { | |
| 228 RangeError.checkNotNegative(count, "count"); | |
| 229 int newStart = _start + count; | |
| 230 if (_endOrLength != null && newStart >= _endOrLength) { | |
| 231 return new EmptyIterable<E>(); | |
| 232 } | |
| 233 return new SubListIterable<E>(_iterable, newStart, _endOrLength); | |
| 234 } | |
| 235 Iterable<E> take(int count) { | |
| 236 RangeError.checkNotNegative(count, "count"); | |
| 237 if (_endOrLength == null) { | |
| 238 return new SubListIterable<E>(_iterable, _start, _start + count); | |
| 239 } | |
| 240 else { | |
| 241 int newEnd = _start + count; | |
| 242 if (_endOrLength < newEnd) return this; | |
| 243 return new SubListIterable<E>(_iterable, _start, newEnd); | |
| 244 } | |
| 245 } | |
| 246 List<E> toList({ | |
| 247 bool growable : true} | |
| 248 ) { | |
| 249 int start = _start; | |
| 250 int end = _iterable.length; | |
| 251 if (_endOrLength != null && _endOrLength < end) end = _endOrLength; | |
| 252 int length = end - start; | |
| 253 if (length < 0) length = 0; | |
| 254 List result = growable ? (new List<E>()..length = length) : new List<E>(length)
; | |
| 255 for (int i = 0; i < length; i++) { | |
| 256 result[i] = _iterable.elementAt(start + i); | |
| 257 if (_iterable.length < end) throw new ConcurrentModificationError(this); | |
| 258 } | |
| 259 return DEVC$RT.cast(result, DEVC$RT.type((List<dynamic> _) { | |
| 260 } | |
| 261 ), DEVC$RT.type((List<E> _) { | |
| 262 } | |
| 263 ), "CompositeCast", """line 310, column 12 of dart:_internal/iterable.dart: """,
result is List<E>, false); | |
| 264 } | |
| 265 } | |
| 266 class ListIterator<E> implements Iterator<E> {final Iterable<E> _iterable; | |
| 267 final int _length; | |
| 268 int _index; | |
| 269 E _current; | |
| 270 ListIterator(Iterable<E> iterable) : _iterable = iterable, _length = iterable.l
ength, _index = 0; | |
| 271 E get current => _current; | |
| 272 bool moveNext() { | |
| 273 int length = _iterable.length; | |
| 274 if (_length != length) { | |
| 275 throw new ConcurrentModificationError(_iterable); | |
| 276 } | |
| 277 if (_index >= length) { | |
| 278 _current = null; | |
| 279 return false; | |
| 280 } | |
| 281 _current = _iterable.elementAt(_index); | |
| 282 _index++; | |
| 283 return true; | |
| 284 } | |
| 285 } | |
| 286 typedef T _Transformation<S, T>(S value); | |
| 287 class MappedIterable<S, T> extends IterableBase<T> {final Iterable<S> _iterable
; | |
| 288 final _Transformation<S, T> _f; | |
| 289 factory MappedIterable(Iterable iterable, T function(S value)) { | |
| 290 if (iterable is EfficientLength) { | |
| 291 return new EfficientLengthMappedIterable<S, T>(iterable, function); | |
| 292 } | |
| 293 return new MappedIterable<S, T>._(DEVC$RT.cast(iterable, DEVC$RT.type((Iterable
<dynamic> _) { | |
| 294 } | |
| 295 ), DEVC$RT.type((Iterable<S> _) { | |
| 296 } | |
| 297 ), "CompositeCast", """line 357, column 39 of dart:_internal/iterable.dart: """,
iterable is Iterable<S>, false), function); | |
| 298 } | |
| 299 MappedIterable._(this._iterable, T this._f(S element)); | |
| 300 Iterator<T> get iterator => new MappedIterator<S, T>(_iterable.iterator, _f); | |
| 301 int get length => _iterable.length; | |
| 302 bool get isEmpty => _iterable.isEmpty; | |
| 303 T get first => _f(_iterable.first); | |
| 304 T get last => _f(_iterable.last); | |
| 305 T get single => _f(_iterable.single); | |
| 306 T elementAt(int index) => _f(_iterable.elementAt(index)); | |
| 307 } | |
| 308 class EfficientLengthMappedIterable<S, T> extends MappedIterable<S, T> implemen
ts EfficientLength {EfficientLengthMappedIterable(Iterable iterable, T function(
S value)) : super._(DEVC$RT.cast(iterable, DEVC$RT.type((Iterable<dynamic> _) { | |
| 309 } | |
| 310 ), DEVC$RT.type((Iterable<S> _) { | |
| 311 } | |
| 312 ), "CompositeCast", """line 378, column 17 of dart:_internal/iterable.dart: """,
iterable is Iterable<S>, false), function); | |
| 313 } | |
| 314 class MappedIterator<S, T> extends Iterator<T> {T _current; | |
| 315 final Iterator<S> _iterator; | |
| 316 final _Transformation<S, T> _f; | |
| 317 MappedIterator(this._iterator, T this._f(S element)); | |
| 318 bool moveNext() { | |
| 319 if (_iterator.moveNext()) { | |
| 320 _current = _f(_iterator.current); | |
| 321 return true; | |
| 322 } | |
| 323 _current = null; | |
| 324 return false; | |
| 325 } | |
| 326 T get current => _current; | |
| 327 } | |
| 328 class MappedListIterable<S, T> extends ListIterable<T> implements EfficientLeng
th {final Iterable<S> _source; | |
| 329 final _Transformation<S, T> _f; | |
| 330 MappedListIterable(this._source, T this._f(S value)); | |
| 331 int get length => _source.length; | |
| 332 T elementAt(int index) => _f(_source.elementAt(index)); | |
| 333 } | |
| 334 typedef bool _ElementPredicate<E>(E element); | |
| 335 class WhereIterable<E> extends IterableBase<E> {final Iterable<E> _iterable; | |
| 336 final _ElementPredicate<E> _f; | |
| 337 WhereIterable(this._iterable, bool this._f(E element)); | |
| 338 Iterator<E> get iterator => new WhereIterator<E>(_iterable.iterator, _f); | |
| 339 } | |
| 340 class WhereIterator<E> extends Iterator<E> {final Iterator<E> _iterator; | |
| 341 final _ElementPredicate<E> _f; | |
| 342 WhereIterator(this._iterator, bool this._f(E element)); | |
| 343 bool moveNext() { | |
| 344 while (_iterator.moveNext()) { | |
| 345 if (_f(_iterator.current)) { | |
| 346 return true; | |
| 347 } | |
| 348 } | |
| 349 return false; | |
| 350 } | |
| 351 E get current => _iterator.current; | |
| 352 } | |
| 353 typedef Iterable<T> _ExpandFunction<S, T>(S sourceElement); | |
| 354 class ExpandIterable<S, T> extends IterableBase<T> {final Iterable<S> _iterable
; | |
| 355 final _ExpandFunction _f; | |
| 356 ExpandIterable(this._iterable, Iterable<T> this._f(S element)); | |
| 357 Iterator<T> get iterator => new ExpandIterator<S, T>(_iterable.iterator, DEVC$R
T.cast(_f, null, DEVC$RT.type((__CastType0<S, T> _) { | |
| 358 } | |
| 359 ), "CompositeCast", """line 454, column 76 of dart:_internal/iterable.dart: """,
_f is __CastType0<S, T>, false)); | |
| 360 } | |
| 361 class ExpandIterator<S, T> implements Iterator<T> {final Iterator<S> _iterator; | |
| 362 final _ExpandFunction _f; | |
| 363 Iterator<T> _currentExpansion = const EmptyIterator<T>(); | |
| 364 T _current; | |
| 365 ExpandIterator(this._iterator, Iterable<T> this._f(S element)); | |
| 366 void _nextExpansion() { | |
| 367 } | |
| 368 T get current => _current; | |
| 369 bool moveNext() { | |
| 370 if (_currentExpansion == null) return false; | |
| 371 while (!_currentExpansion.moveNext()) { | |
| 372 _current = null; | |
| 373 if (_iterator.moveNext()) { | |
| 374 _currentExpansion = null; | |
| 375 _currentExpansion = ((__x2) => DEVC$RT.cast(__x2, DEVC$RT.type((Iterator<dynami
c> _) { | |
| 376 } | |
| 377 ), DEVC$RT.type((Iterator<T> _) { | |
| 378 } | |
| 379 ), "CompositeCast", """line 481, column 29 of dart:_internal/iterable.dart: """,
__x2 is Iterator<T>, false))(_f(_iterator.current).iterator); | |
| 380 } | |
| 381 else { | |
| 382 return false; | |
| 383 } | |
| 384 } | |
| 385 _current = _currentExpansion.current; | |
| 386 return true; | |
| 387 } | |
| 388 } | |
| 389 class TakeIterable<E> extends IterableBase<E> {final Iterable<E> _iterable; | |
| 390 final int _takeCount; | |
| 391 factory TakeIterable(Iterable<E> iterable, int takeCount) { | |
| 392 if (takeCount is! int || takeCount < 0) { | |
| 393 throw new ArgumentError(takeCount); | |
| 394 } | |
| 395 if (iterable is EfficientLength) { | |
| 396 return new EfficientLengthTakeIterable<E>(iterable, takeCount); | |
| 397 } | |
| 398 return new TakeIterable<E>._(iterable, takeCount); | |
| 399 } | |
| 400 TakeIterable._(this._iterable, this._takeCount); | |
| 401 Iterator<E> get iterator { | |
| 402 return new TakeIterator<E>(_iterable.iterator, _takeCount); | |
| 403 } | |
| 404 } | |
| 405 class EfficientLengthTakeIterable<E> extends TakeIterable<E> implements Efficie
ntLength {EfficientLengthTakeIterable(Iterable<E> iterable, int takeCount) : sup
er._(iterable, takeCount); | |
| 406 int get length { | |
| 407 int iterableLength = _iterable.length; | |
| 408 if (iterableLength > _takeCount) return _takeCount; | |
| 409 return iterableLength; | |
| 410 } | |
| 411 } | |
| 412 class TakeIterator<E> extends Iterator<E> {final Iterator<E> _iterator; | |
| 413 int _remaining; | |
| 414 TakeIterator(this._iterator, this._remaining) { | |
| 415 assert (_remaining is int && _remaining >= 0);} | |
| 416 bool moveNext() { | |
| 417 _remaining--; | |
| 418 if (_remaining >= 0) { | |
| 419 return _iterator.moveNext(); | |
| 420 } | |
| 421 _remaining = -1; | |
| 422 return false; | |
| 423 } | |
| 424 E get current { | |
| 425 if (_remaining < 0) return null; | |
| 426 return _iterator.current; | |
| 427 } | |
| 428 } | |
| 429 class TakeWhileIterable<E> extends IterableBase<E> {final Iterable<E> _iterable
; | |
| 430 final _ElementPredicate _f; | |
| 431 TakeWhileIterable(this._iterable, bool this._f(E element)); | |
| 432 Iterator<E> get iterator { | |
| 433 return new TakeWhileIterator<E>(_iterable.iterator, DEVC$RT.cast(_f, null, DEVC$
RT.type((__CastType3<E> _) { | |
| 434 } | |
| 435 ), "CompositeCast", """line 555, column 57 of dart:_internal/iterable.dart: """,
_f is __CastType3<E>, false)); | |
| 436 } | |
| 437 } | |
| 438 class TakeWhileIterator<E> extends Iterator<E> {final Iterator<E> _iterator; | |
| 439 final _ElementPredicate _f; | |
| 440 bool _isFinished = false; | |
| 441 TakeWhileIterator(this._iterator, bool this._f(E element)); | |
| 442 bool moveNext() { | |
| 443 if (_isFinished) return false; | |
| 444 if (!_iterator.moveNext() || !_f(_iterator.current)) { | |
| 445 _isFinished = true; | |
| 446 return false; | |
| 447 } | |
| 448 return true; | |
| 449 } | |
| 450 E get current { | |
| 451 if (_isFinished) return null; | |
| 452 return _iterator.current; | |
| 453 } | |
| 454 } | |
| 455 class SkipIterable<E> extends IterableBase<E> {final Iterable<E> _iterable; | |
| 456 final int _skipCount; | |
| 457 factory SkipIterable(Iterable<E> iterable, int count) { | |
| 458 if (iterable is EfficientLength) { | |
| 459 return new EfficientLengthSkipIterable<E>(iterable, count); | |
| 460 } | |
| 461 return new SkipIterable<E>._(iterable, count); | |
| 462 } | |
| 463 SkipIterable._(this._iterable, this._skipCount) { | |
| 464 if (_skipCount is! int) { | |
| 465 throw new ArgumentError.value(_skipCount, "count is not an integer"); | |
| 466 } | |
| 467 RangeError.checkNotNegative(_skipCount, "count"); | |
| 468 } | |
| 469 Iterable<E> skip(int count) { | |
| 470 if (_skipCount is! int) { | |
| 471 throw new ArgumentError.value(_skipCount, "count is not an integer"); | |
| 472 } | |
| 473 RangeError.checkNotNegative(_skipCount, "count"); | |
| 474 return new SkipIterable<E>._(_iterable, _skipCount + count); | |
| 475 } | |
| 476 Iterator<E> get iterator { | |
| 477 return new SkipIterator<E>(_iterable.iterator, _skipCount); | |
| 478 } | |
| 479 } | |
| 480 class EfficientLengthSkipIterable<E> extends SkipIterable<E> implements Efficie
ntLength {EfficientLengthSkipIterable(Iterable<E> iterable, int skipCount) : sup
er._(iterable, skipCount); | |
| 481 int get length { | |
| 482 int length = _iterable.length - _skipCount; | |
| 483 if (length >= 0) return length; | |
| 484 return 0; | |
| 485 } | |
| 486 } | |
| 487 class SkipIterator<E> extends Iterator<E> {final Iterator<E> _iterator; | |
| 488 int _skipCount; | |
| 489 SkipIterator(this._iterator, this._skipCount) { | |
| 490 assert (_skipCount is int && _skipCount >= 0);} | |
| 491 bool moveNext() { | |
| 492 for (int i = 0; i < _skipCount; i++) _iterator.moveNext(); | |
| 493 _skipCount = 0; | |
| 494 return _iterator.moveNext(); | |
| 495 } | |
| 496 E get current => _iterator.current; | |
| 497 } | |
| 498 class SkipWhileIterable<E> extends IterableBase<E> {final Iterable<E> _iterable
; | |
| 499 final _ElementPredicate _f; | |
| 500 SkipWhileIterable(this._iterable, bool this._f(E element)); | |
| 501 Iterator<E> get iterator { | |
| 502 return new SkipWhileIterator<E>(_iterable.iterator, DEVC$RT.cast(_f, null, DEVC$
RT.type((__CastType5<E> _) { | |
| 503 } | |
| 504 ), "CompositeCast", """line 648, column 57 of dart:_internal/iterable.dart: """,
_f is __CastType5<E>, false)); | |
| 505 } | |
| 506 } | |
| 507 class SkipWhileIterator<E> extends Iterator<E> {final Iterator<E> _iterator; | |
| 508 final _ElementPredicate _f; | |
| 509 bool _hasSkipped = false; | |
| 510 SkipWhileIterator(this._iterator, bool this._f(E element)); | |
| 511 bool moveNext() { | |
| 512 if (!_hasSkipped) { | |
| 513 _hasSkipped = true; | |
| 514 while (_iterator.moveNext()) { | |
| 515 if (!_f(_iterator.current)) return true; | |
| 516 } | |
| 517 } | |
| 518 return _iterator.moveNext(); | |
| 519 } | |
| 520 E get current => _iterator.current; | |
| 521 } | |
| 522 class EmptyIterable<E> extends IterableBase<E> implements EfficientLength {cons
t EmptyIterable(); | |
| 523 Iterator<E> get iterator => const EmptyIterator<E>(); | |
| 524 void forEach(void action(E element)) { | |
| 525 } | |
| 526 bool get isEmpty => true; | |
| 527 int get length => 0; | |
| 528 E get first { | |
| 529 throw IterableElementError.noElement(); | |
| 530 } | |
| 531 E get last { | |
| 532 throw IterableElementError.noElement(); | |
| 533 } | |
| 534 E get single { | |
| 535 throw IterableElementError.noElement(); | |
| 536 } | |
| 537 E elementAt(int index) { | |
| 538 throw new RangeError.range(index, 0, 0, "index"); | |
| 539 } | |
| 540 bool contains(Object element) => false; | |
| 541 bool every(bool test(E element)) => true; | |
| 542 bool any(bool test(E element)) => false; | |
| 543 E firstWhere(bool test(E element), { | |
| 544 E orElse()} | |
| 545 ) { | |
| 546 if (orElse != null) return orElse(); | |
| 547 throw IterableElementError.noElement(); | |
| 548 } | |
| 549 E lastWhere(bool test(E element), { | |
| 550 E orElse()} | |
| 551 ) { | |
| 552 if (orElse != null) return orElse(); | |
| 553 throw IterableElementError.noElement(); | |
| 554 } | |
| 555 E singleWhere(bool test(E element), { | |
| 556 E orElse()} | |
| 557 ) { | |
| 558 if (orElse != null) return orElse(); | |
| 559 throw IterableElementError.noElement(); | |
| 560 } | |
| 561 String join([String separator = ""]) => ""; | |
| 562 Iterable<E> where(bool test(E element)) => this; | |
| 563 Iterable map(f(E element)) => const EmptyIterable(); | |
| 564 E reduce(E combine(E value, E element)) { | |
| 565 throw IterableElementError.noElement(); | |
| 566 } | |
| 567 fold(var initialValue, combine(var previousValue, E element)) { | |
| 568 return initialValue; | |
| 569 } | |
| 570 Iterable<E> skip(int count) { | |
| 571 RangeError.checkNotNegative(count, "count"); | |
| 572 return this; | |
| 573 } | |
| 574 Iterable<E> skipWhile(bool test(E element)) => this; | |
| 575 Iterable<E> take(int count) { | |
| 576 RangeError.checkNotNegative(count, "count"); | |
| 577 return this; | |
| 578 } | |
| 579 Iterable<E> takeWhile(bool test(E element)) => this; | |
| 580 List<E> toList({ | |
| 581 bool growable : true} | |
| 582 ) => growable ? <E> [] : new List<E>(0); | |
| 583 Set<E> toSet() => new Set<E>(); | |
| 584 } | |
| 585 class EmptyIterator<E> implements Iterator<E> {const EmptyIterator(); | |
| 586 bool moveNext() => false; | |
| 587 E get current => null; | |
| 588 } | |
| 589 abstract class BidirectionalIterator<T> implements Iterator<T> {bool movePrevio
us(); | |
| 590 } | |
| 591 class IterableMixinWorkaround<T> {static bool contains(Iterable iterable, var e
lement) { | |
| 592 for (final e in iterable) { | |
| 593 if (e == element) return true; | |
| 594 } | |
| 595 return false; | |
| 596 } | |
| 597 static void forEach(Iterable iterable, void f(o)) { | |
| 598 for (final e in iterable) { | |
| 599 f(e); | |
| 600 } | |
| 601 } | |
| 602 static bool any(Iterable iterable, bool f(o)) { | |
| 603 for (final e in iterable) { | |
| 604 if (f(e)) return true; | |
| 605 } | |
| 606 return false; | |
| 607 } | |
| 608 static bool every(Iterable iterable, bool f(o)) { | |
| 609 for (final e in iterable) { | |
| 610 if (!f(e)) return false; | |
| 611 } | |
| 612 return true; | |
| 613 } | |
| 614 static dynamic reduce(Iterable iterable, dynamic combine(previousValue, element
)) { | |
| 615 Iterator iterator = iterable.iterator; | |
| 616 if (!iterator.moveNext()) throw IterableElementError.noElement(); | |
| 617 var value = iterator.current; | |
| 618 while (iterator.moveNext()) { | |
| 619 value = combine(value, iterator.current); | |
| 620 } | |
| 621 return value; | |
| 622 } | |
| 623 static dynamic fold(Iterable iterable, dynamic initialValue, dynamic combine(dy
namic previousValue, element)) { | |
| 624 for (final element in iterable) { | |
| 625 initialValue = combine(initialValue, element); | |
| 626 } | |
| 627 return initialValue; | |
| 628 } | |
| 629 static void removeWhereList(List list, bool test(var element)) { | |
| 630 List retained = []; | |
| 631 int length = list.length; | |
| 632 for (int i = 0; i < length; i++) { | |
| 633 var element = list[i]; | |
| 634 if (!test(element)) { | |
| 635 retained.add(element); | |
| 636 } | |
| 637 if (length != list.length) { | |
| 638 throw new ConcurrentModificationError(list); | |
| 639 } | |
| 640 } | |
| 641 if (retained.length == length) return; list.length = retained.length; | |
| 642 for (int i = 0; i < retained.length; i++) { | |
| 643 list[i] = retained[i]; | |
| 644 } | |
| 645 } | |
| 646 static bool isEmpty(Iterable iterable) { | |
| 647 return !iterable.iterator.moveNext(); | |
| 648 } | |
| 649 static dynamic first(Iterable iterable) { | |
| 650 Iterator it = iterable.iterator; | |
| 651 if (!it.moveNext()) { | |
| 652 throw IterableElementError.noElement(); | |
| 653 } | |
| 654 return it.current; | |
| 655 } | |
| 656 static dynamic last(Iterable iterable) { | |
| 657 Iterator it = iterable.iterator; | |
| 658 if (!it.moveNext()) { | |
| 659 throw IterableElementError.noElement(); | |
| 660 } | |
| 661 dynamic result; | |
| 662 do { | |
| 663 result = it.current; | |
| 664 } | |
| 665 while (it.moveNext()); return result; | |
| 666 } | |
| 667 static dynamic single(Iterable iterable) { | |
| 668 Iterator it = iterable.iterator; | |
| 669 if (!it.moveNext()) throw IterableElementError.noElement(); | |
| 670 dynamic result = it.current; | |
| 671 if (it.moveNext()) throw IterableElementError.tooMany(); | |
| 672 return result; | |
| 673 } | |
| 674 static dynamic firstWhere(Iterable iterable, bool test(dynamic value), dynamic
orElse()) { | |
| 675 for (dynamic element in iterable) { | |
| 676 if (test(element)) return element; | |
| 677 } | |
| 678 if (orElse != null) return orElse(); | |
| 679 throw IterableElementError.noElement(); | |
| 680 } | |
| 681 static dynamic lastWhere(Iterable iterable, bool test(dynamic value), dynamic o
rElse()) { | |
| 682 dynamic result = null; | |
| 683 bool foundMatching = false; | |
| 684 for (dynamic element in iterable) { | |
| 685 if (test(element)) { | |
| 686 result = element; | |
| 687 foundMatching = true; | |
| 688 } | |
| 689 } | |
| 690 if (foundMatching) return result; | |
| 691 if (orElse != null) return orElse(); | |
| 692 throw IterableElementError.noElement(); | |
| 693 } | |
| 694 static dynamic lastWhereList(List list, bool test(dynamic value), dynamic orEls
e()) { | |
| 695 for (int i = list.length - 1; i >= 0; i--) { | |
| 696 dynamic element = list[i]; | |
| 697 if (test(element)) return element; | |
| 698 } | |
| 699 if (orElse != null) return orElse(); | |
| 700 throw IterableElementError.noElement(); | |
| 701 } | |
| 702 static dynamic singleWhere(Iterable iterable, bool test(dynamic value)) { | |
| 703 dynamic result = null; | |
| 704 bool foundMatching = false; | |
| 705 for (dynamic element in iterable) { | |
| 706 if (test(element)) { | |
| 707 if (foundMatching) { | |
| 708 throw IterableElementError.tooMany(); | |
| 709 } | |
| 710 result = element; | |
| 711 foundMatching = true; | |
| 712 } | |
| 713 } | |
| 714 if (foundMatching) return result; | |
| 715 throw IterableElementError.noElement(); | |
| 716 } | |
| 717 static elementAt(Iterable iterable, int index) { | |
| 718 if (index is! int) throw new ArgumentError.notNull("index"); | |
| 719 RangeError.checkNotNegative(index, "index"); | |
| 720 int elementIndex = 0; | |
| 721 for (var element in iterable) { | |
| 722 if (index == elementIndex) return element; | |
| 723 elementIndex++; | |
| 724 } | |
| 725 throw new RangeError.index(index, iterable, "index", null, elementIndex); | |
| 726 } | |
| 727 static String join(Iterable iterable, [String separator]) { | |
| 728 StringBuffer buffer = new StringBuffer(); | |
| 729 buffer.writeAll(iterable, separator); | |
| 730 return buffer.toString(); | |
| 731 } | |
| 732 static String joinList(List list, [String separator]) { | |
| 733 if (list.isEmpty) return ""; | |
| 734 if (list.length == 1) return "${list[0]}"; | |
| 735 StringBuffer buffer = new StringBuffer(); | |
| 736 if (separator.isEmpty) { | |
| 737 for (int i = 0; i < list.length; i++) { | |
| 738 buffer.write(list[i]); | |
| 739 } | |
| 740 } | |
| 741 else { | |
| 742 buffer.write(list[0]); | |
| 743 for (int i = 1; i < list.length; i++) { | |
| 744 buffer.write(separator); | |
| 745 buffer.write(list[i]); | |
| 746 } | |
| 747 } | |
| 748 return buffer.toString(); | |
| 749 } | |
| 750 Iterable<T> where(Iterable iterable, bool f(var element)) { | |
| 751 return new WhereIterable<T>(DEVC$RT.cast(iterable, DEVC$RT.type((Iterable<dynami
c> _) { | |
| 752 } | |
| 753 ), DEVC$RT.type((Iterable<T> _) { | |
| 754 } | |
| 755 ), "CompositeCast", """line 961, column 33 of dart:_internal/iterable.dart: """,
iterable is Iterable<T>, false), DEVC$RT.cast(f, null, DEVC$RT.type((__CastType
7<T> _) { | |
| 756 } | |
| 757 ), "CompositeCast", """line 961, column 43 of dart:_internal/iterable.dart: """,
f is __CastType7<T>, false)); | |
| 758 } | |
| 759 static Iterable map(Iterable iterable, f(var element)) { | |
| 760 return new MappedIterable(iterable, f); | |
| 761 } | |
| 762 static Iterable mapList(List list, f(var element)) { | |
| 763 return new MappedListIterable(list, f); | |
| 764 } | |
| 765 static Iterable expand(Iterable iterable, Iterable f(var element)) { | |
| 766 return new ExpandIterable(iterable, f); | |
| 767 } | |
| 768 Iterable<T> takeList(List list, int n) { | |
| 769 return new SubListIterable<T>(DEVC$RT.cast(list, DEVC$RT.type((List<dynamic> _)
{ | |
| 770 } | |
| 771 ), DEVC$RT.type((Iterable<T> _) { | |
| 772 } | |
| 773 ), "CompositeCast", """line 978, column 35 of dart:_internal/iterable.dart: """,
list is Iterable<T>, false), 0, n); | |
| 774 } | |
| 775 Iterable<T> takeWhile(Iterable iterable, bool test(var value)) { | |
| 776 return new TakeWhileIterable<T>(DEVC$RT.cast(iterable, DEVC$RT.type((Iterable<dy
namic> _) { | |
| 777 } | |
| 778 ), DEVC$RT.type((Iterable<T> _) { | |
| 779 } | |
| 780 ), "CompositeCast", """line 983, column 37 of dart:_internal/iterable.dart: """,
iterable is Iterable<T>, false), DEVC$RT.cast(test, null, DEVC$RT.type((__CastT
ype7<T> _) { | |
| 781 } | |
| 782 ), "CompositeCast", """line 983, column 47 of dart:_internal/iterable.dart: """,
test is __CastType7<T>, false)); | |
| 783 } | |
| 784 Iterable<T> skipList(List list, int n) { | |
| 785 return new SubListIterable<T>(DEVC$RT.cast(list, DEVC$RT.type((List<dynamic> _)
{ | |
| 786 } | |
| 787 ), DEVC$RT.type((Iterable<T> _) { | |
| 788 } | |
| 789 ), "CompositeCast", """line 988, column 35 of dart:_internal/iterable.dart: """,
list is Iterable<T>, false), n, null); | |
| 790 } | |
| 791 Iterable<T> skipWhile(Iterable iterable, bool test(var value)) { | |
| 792 return new SkipWhileIterable<T>(DEVC$RT.cast(iterable, DEVC$RT.type((Iterable<dy
namic> _) { | |
| 793 } | |
| 794 ), DEVC$RT.type((Iterable<T> _) { | |
| 795 } | |
| 796 ), "CompositeCast", """line 993, column 37 of dart:_internal/iterable.dart: """,
iterable is Iterable<T>, false), DEVC$RT.cast(test, null, DEVC$RT.type((__CastT
ype7<T> _) { | |
| 797 } | |
| 798 ), "CompositeCast", """line 993, column 47 of dart:_internal/iterable.dart: """,
test is __CastType7<T>, false)); | |
| 799 } | |
| 800 Iterable<T> reversedList(List list) { | |
| 801 return new ReversedListIterable<T>(DEVC$RT.cast(list, DEVC$RT.type((List<dynamic
> _) { | |
| 802 } | |
| 803 ), DEVC$RT.type((Iterable<T> _) { | |
| 804 } | |
| 805 ), "CompositeCast", """line 997, column 40 of dart:_internal/iterable.dart: """,
list is Iterable<T>, false)); | |
| 806 } | |
| 807 static void sortList(List list, int compare(a, b)) { | |
| 808 if (compare == null) compare = Comparable.compare; | |
| 809 Sort.sort(list, compare); | |
| 810 } | |
| 811 static void shuffleList(List list, Random random) { | |
| 812 if (random == null) random = new Random(); | |
| 813 int length = list.length; | |
| 814 while (length > 1) { | |
| 815 int pos = random.nextInt(length); | |
| 816 length -= 1; | |
| 817 var tmp = list[length]; | |
| 818 list[length] = list[pos]; | |
| 819 list[pos] = tmp; | |
| 820 } | |
| 821 } | |
| 822 static int indexOfList(List list, var element, int start) { | |
| 823 return Lists.indexOf(list, element, start, list.length); | |
| 824 } | |
| 825 static int lastIndexOfList(List list, var element, int start) { | |
| 826 if (start == null) start = list.length - 1; | |
| 827 return Lists.lastIndexOf(list, element, start); | |
| 828 } | |
| 829 static void _rangeCheck(List list, int start, int end) { | |
| 830 RangeError.checkValidRange(start, end, list.length); | |
| 831 } | |
| 832 Iterable<T> getRangeList(List list, int start, int end) { | |
| 833 _rangeCheck(list, start, end); | |
| 834 return new SubListIterable<T>(DEVC$RT.cast(list, DEVC$RT.type((List<dynamic> _)
{ | |
| 835 } | |
| 836 ), DEVC$RT.type((Iterable<T> _) { | |
| 837 } | |
| 838 ), "CompositeCast", """line 1033, column 35 of dart:_internal/iterable.dart: """
, list is Iterable<T>, false), start, end); | |
| 839 } | |
| 840 static void setRangeList(List list, int start, int end, Iterable from, int skip
Count) { | |
| 841 _rangeCheck(list, start, end); | |
| 842 int length = end - start; | |
| 843 if (length == 0) return; if (skipCount < 0) throw new ArgumentError(skipCount); | |
| 844 List otherList; | |
| 845 int otherStart; | |
| 846 if (from is List) { | |
| 847 otherList = from; | |
| 848 otherStart = skipCount; | |
| 849 } | |
| 850 else { | |
| 851 otherList = from.skip(skipCount).toList(growable: false); | |
| 852 otherStart = 0; | |
| 853 } | |
| 854 if (otherStart + length > otherList.length) { | |
| 855 throw IterableElementError.tooFew(); | |
| 856 } | |
| 857 Lists.copy(otherList, otherStart, list, start, length); | |
| 858 } | |
| 859 static void replaceRangeList(List list, int start, int end, Iterable iterable)
{ | |
| 860 _rangeCheck(list, start, end); | |
| 861 if (iterable is! EfficientLength) { | |
| 862 iterable = iterable.toList(); | |
| 863 } | |
| 864 int removeLength = end - start; | |
| 865 int insertLength = iterable.length; | |
| 866 if (removeLength >= insertLength) { | |
| 867 int delta = removeLength - insertLength; | |
| 868 int insertEnd = start + insertLength; | |
| 869 int newEnd = list.length - delta; | |
| 870 list.setRange(start, insertEnd, iterable); | |
| 871 if (delta != 0) { | |
| 872 list.setRange(insertEnd, newEnd, list, end); | |
| 873 list.length = newEnd; | |
| 874 } | |
| 875 } | |
| 876 else { | |
| 877 int delta = insertLength - removeLength; | |
| 878 int newLength = list.length + delta; | |
| 879 int insertEnd = start + insertLength; | |
| 880 list.length = newLength; | |
| 881 list.setRange(insertEnd, newLength, list, end); | |
| 882 list.setRange(start, insertEnd, iterable); | |
| 883 } | |
| 884 } | |
| 885 static void fillRangeList(List list, int start, int end, fillValue) { | |
| 886 _rangeCheck(list, start, end); | |
| 887 for (int i = start; i < end; i++) { | |
| 888 list[i] = fillValue; | |
| 889 } | |
| 890 } | |
| 891 static void insertAllList(List list, int index, Iterable iterable) { | |
| 892 RangeError.checkValueInInterval(index, 0, list.length, "index"); | |
| 893 if (iterable is! EfficientLength) { | |
| 894 iterable = iterable.toList(growable: false); | |
| 895 } | |
| 896 int insertionLength = iterable.length; | |
| 897 list.length += insertionLength; | |
| 898 list.setRange(index + insertionLength, list.length, list, index); | |
| 899 for (var element in iterable) { | |
| 900 list[index++] = element; | |
| 901 } | |
| 902 } | |
| 903 static void setAllList(List list, int index, Iterable iterable) { | |
| 904 RangeError.checkValueInInterval(index, 0, list.length, "index"); | |
| 905 for (var element in iterable) { | |
| 906 list[index++] = element; | |
| 907 } | |
| 908 } | |
| 909 Map<int, T> asMapList(List l) { | |
| 910 return new ListMapView<T>(DEVC$RT.cast(l, DEVC$RT.type((List<dynamic> _) { | |
| 911 } | |
| 912 ), DEVC$RT.type((List<T> _) { | |
| 913 } | |
| 914 ), "CompositeCast", """line 1115, column 31 of dart:_internal/iterable.dart: """
, l is List<T>, false)); | |
| 915 } | |
| 916 static bool setContainsAll(Set set, Iterable other) { | |
| 917 for (var element in other) { | |
| 918 if (!set.contains(element)) return false; | |
| 919 } | |
| 920 return true; | |
| 921 } | |
| 922 static Set setIntersection(Set set, Set other, Set result) { | |
| 923 Set smaller; | |
| 924 Set larger; | |
| 925 if (set.length < other.length) { | |
| 926 smaller = set; | |
| 927 larger = other; | |
| 928 } | |
| 929 else { | |
| 930 smaller = other; | |
| 931 larger = set; | |
| 932 } | |
| 933 for (var element in smaller) { | |
| 934 if (larger.contains(element)) { | |
| 935 result.add(element); | |
| 936 } | |
| 937 } | |
| 938 return result; | |
| 939 } | |
| 940 static Set setUnion(Set set, Set other, Set result) { | |
| 941 result.addAll(set); | |
| 942 result.addAll(other); | |
| 943 return result; | |
| 944 } | |
| 945 static Set setDifference(Set set, Set other, Set result) { | |
| 946 for (var element in set) { | |
| 947 if (!other.contains(element)) { | |
| 948 result.add(element); | |
| 949 } | |
| 950 } | |
| 951 return result; | |
| 952 } | |
| 953 } | |
| 954 abstract class IterableElementError {static StateError noElement() => new State
Error("No element"); | |
| 955 static StateError tooMany() => new StateError("Too many elements"); | |
| 956 static StateError tooFew() => new StateError("Too few elements"); | |
| 957 } | |
| 958 typedef Iterable<T> __CastType0<S, T>(S __u1); | |
| 959 typedef bool __CastType3<E>(E __u4); | |
| 960 typedef bool __CastType5<E>(E __u6); | |
| 961 typedef bool __CastType7<T>(T __u8); | |
| 962 typedef bool __CastType9(dynamic __u10); | |
| OLD | NEW |