removeWaveCompletely method
Removes all occurrences of the given wave
from the list of waves.
Returns true
if the wave
was in the list, false
otherwise.
Example:
List<Wave> waves = [wave1, wave1, wave2, wave1, wave3];
bool removed = removeWaveCompletely(wave1); // true
print(waves); // [wave2, wave3]
If the list of waves has only one wave (this also goes for multiple
instances of the one wave), this method will return false
and the wave
will be removed, expect for one instance of it. The list must never be
empty.
Example:
List<Wave> waves = [wave1, wave1, wave1];
bool removed = removeWaveCompletely(wave1); // false
print(waves); // [wave1]
Implementation
bool removeWaveCompletely(Wave wave) {
while (_waves.contains(wave)) {
_waves.remove(wave);
}
if (_waves.isNotEmpty) return true;
_waves.add(wave);
return false;
}