}
AckRange.sort(ranges);
// check proper bounds of acked ranges
AckRange lastAckRange = ranges.get(ranges.size() - 1);
if (data.getLastMessageNumber() < lastAckRange.upper) {
throw new InvalidAcknowledgementException(this.getId(), lastAckRange.upper, ranges);
}
final Collection<Long> unackedMessageNumbers = data.getUnackedMessageNumbers();
if (unackedMessageNumbers.isEmpty()) {
// we have checked the ranges are ok and there's nothing to acknowledge.
return;
}
// acknowledge messages
Iterator<AckRange> rangeIterator = ranges.iterator();
AckRange currentRange = rangeIterator.next();
for (long unackedMessageNumber : unackedMessageNumbers) {
if (unackedMessageNumber >= currentRange.lower && unackedMessageNumber <= currentRange.upper) {
data.markAsAcknowledged(unackedMessageNumber);
} else if (rangeIterator.hasNext()) {