LongRangeSet (LongRangeSet left, LongRangeSet right, LongRangeType lrType) { if (left.isEmpty() || right.isEmpty()) return LongRangeSet.empty(); long sumMin = left.min() + right.min(); long sumMax = left.max() + right.max(); LongRangeSet result = LongRangeSet.empty(); if (sumMin < lrType.min()) { result = result.join(LongRangeSet.range(lrType.cast(sumMin), lrType.max())); } if (sumMax > lrType.max()) { result = result.join(LongRangeSet.range(lrType.min(), lrType.cast(sumMax))); } return result; }