throw new IllegalArgumentException(
"subsequence() takes two or three arguments");
}
// First argument is a sequence.
Sequence sequence = arguments[0].getSequence();
// Second argument is a number.
int length = sequence.getLength();
int start = getIntRound(arguments[1]);
int end;
if (arguments.length == 3) {
end = start + getIntRound(arguments[2]);
} else {
end = length;
}
// If the start is before the first item then make it the first item.
if (start < 1) {
start = 1;
}
// If the end is after the last item then make it the last item.
if (end > length + 1) {
end = length + 1;
}
Sequence subsequence;
// The result sequence will be empty if:
// 1) The input sequence is empty.
// 2) The start is after the end of the sequence.
// 3) The end is before or the same as the start.