setAll method
Overwrites objects of this
with the objects of iterable
, starting
at position index
in this list.
List<String> list = ['a', 'b', 'c'];
list.setAll(1, ['bee', 'sea']);
list.join(', '); // 'a, bee, sea'
This operation does not increase the length of this
.
The index
must be non-negative and no greater than length.
The iterable
must not have more elements than what can fit from index
to length.
If iterable
is based on this list, its values may change during the
setAll
operation.
If any of iterable
's elements already exist in the list, a
DuplicateValueError will be thrown regardless of whether the list
is strict or not, unless the resulting list does not contain any duplicate
values once all values have been set.
Implementation
@override
void setAll(int index, Iterable<E> iterable) {
// Check if any of the values in [iterable] already exist in the list.
for (var value in iterable) {
if (_contains(value)) {
// If so, check whether the list will contain any duplicate values once
// every value has been set.
final result = List<E>.of(elements)..setAll(index, iterable);
if (_containsDuplicateValues(result, nullable: nullable)) {
throw DuplicateValueError(
_getDuplicateValue(result, nullable: nullable));
} else {
break;
}
}
}
elements.setAll(index, iterable);
}