for (Range range : ranges.getRangeList()) {
Range.Builder currentRange = range.toBuilder();
for (int i = s; i < subtractRanges.size(); i++) {
Range matchedRange = subtractRanges.get(i);
if (matchedRange.getBegin() < currentRange.getBegin() || matchedRange.getEnd() > currentRange.getEnd()) {
s = i;
break;
}
currentRange.setEnd(matchedRange.getBegin() - 1);
if (currentRange.getEnd() >= currentRange.getBegin()) {
newRanges.addRange(currentRange.build());
}
currentRange = Range.newBuilder();
currentRange.setBegin(matchedRange.getEnd() + 1);
currentRange.setEnd(range.getEnd());
}
if (currentRange.getEnd() >= currentRange.getBegin()) {
newRanges.addRange(currentRange.build());