toList method
Lists all entries of this sequence.
You must specify the number of existing messages with the exists
parameter, in case this sequence contains the last element '*'
in some form.
Use the containsLast method to determine if this sequence contains the last element '*'.
Implementation
List<int> toList([int? exists]) {
if (exists == null && containsLast()) {
throw InvalidArgumentException(
'Unable to list sequence when * is part of the list and the '
'\'exists\' parameter is not specified.',
);
}
if (_isNilSequence) {
throw InvalidArgumentException('Unable to list non existent sequence.');
}
final idSet = LinkedHashSet<int>.identity();
if (_isAllAdded) {
if (exists == null) {
throw InvalidArgumentException(
'Unable to list sequence when * is part of the list and the '
'\'exists\' parameter is not specified.',
);
}
for (var i = 1; i <= exists; i++) {
idSet.add(i);
}
} else {
var index = 0;
var zeroLoc = _ids.indexOf(_elementRangeStar, index);
while (zeroLoc > 0) {
idSet.addAll(_ids.sublist(index, zeroLoc));
// Using a for-loop because we must generate a sequence when
//reaching the `STAR` value
if (exists != null) {
idSet.addAll([for (var x = idSet.last + 1; x <= exists; x++) x]);
}
index = zeroLoc + 1;
zeroLoc = _ids.indexOf(_elementRangeStar, index);
}
if (index >= 0 && zeroLoc == -1) {
idSet.addAll(_ids.sublist(index));
}
}
if (idSet.remove(_elementStar) && exists != null) {
idSet.add(exists);
}
return idSet.toList();
}