operator []= method

void operator []=(
  1. E element,
  2. int occurrences
)

Sets the number of occurrences of an element.

Throws an ArgumentError if occurrences is negative.

Implementation

void operator []=(E element, int occurrences) {
  if (occurrences < 0) {
    throw ArgumentError.value(
        occurrences, 'occurrences', 'Negative number of occurrences');
  } else {
    final current = this[element];
    if (occurrences > 0) {
      _container[element] = occurrences;
      _length += occurrences - current;
    } else {
      _container.remove(element);
      _length -= current;
    }
  }
}