Spec-Zone.ru › Dart 1

dart:collection

Метод setRange

void setRange(int start, int end, Iterable<E> iterable, [ int skipCount = 0 ])

Копирует объекты iterable, пропуская skipCount объектов сначала, в диапазон start, включительно, до end, исключая, списка.

List<int> list1 = [1, 2, 3, 4];
List<int> list2 = [5, 6, 7, 8, 9];
// Copies the 4th and 5th items in list2 as the 2nd and 3rd items
// of list1.
list1.setRange(1, 3, list2, 3);
list1.join(', '); // '1, 8, 9, 4'

Указанный диапазон, заданный start и end, должен быть допустимым. Диапазон от start до end допустим, если 0 <= start <= end <= len, где len — это length списка. Диапазон начинается с start и имеет длину end - start. Пустой диапазон (с end == start) допустим.

iterable должен содержать достаточно объектов, чтобы заполнить диапазон от start до end после пропуска skipCount объектов.

Если iterable — это этот список, операция копирует элементы, изначально находящиеся в диапазоне от skipCount до skipCount + (end - start) в диапазон start до end, даже если два диапазона перекрываются.

Если iterable зависит от этого списка каким-либо другим образом, никакие гарантии не предоставляются.

Исходный код

void setRange(int start, int end, Iterable<E> iterable, [int skipCount = 0]) {
  RangeError.checkValidRange(start, end, this.length);
  int length = end - start;
  if (length == 0) return;
  RangeError.checkNotNegative(skipCount, "skipCount");

  List<E> otherList;
  int otherStart;
  // TODO(floitsch): Make this accept more.
  if (iterable is List<E>) {
    otherList = iterable;
    otherStart = skipCount;
  } else {
    otherList = iterable.skip(skipCount).toList(growable: false);
    otherStart = 0;
  }
  if (otherStart + length > otherList.length) {
    throw IterableElementError.tooFew();
  }
  if (otherStart < start) {
    // Copy backwards to ensure correct copy if [from] is this.
    for (int i = length - 1; i >= 0; i--) {
      this[start + i] = otherList[otherStart + i];
    }
  } else {
    for (int i = 0; i < length; i++) {
      this[start + i] = otherList[otherStart + i];
    }
  }
}

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dartlang.org/stable/1.24.3/dart-collection/ListMixin/setRange.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API