LongRangeSet (@NotNull LongRangeSet other) { if (other instanceof ModRange modRange) { int lcm = lcm(modRange.myMod); if (lcm <= Long.SIZE) { long bits = widenBits(lcm) | modRange.widenBits(lcm); if (myTo >= modRange.myFrom && myFrom <= modRange.myTo || myTo < modRange.myFrom && modRange(myTo + 1, modRange.myFrom - 1, lcm, bits).isEmpty() || modRange.myTo < myFrom && modRange(modRange.myTo + 1, myFrom - 1, lcm, bits).isEmpty()) { return modRange(Math.min(myFrom, modRange.myFrom), Math.max(myTo, modRange.myTo), lcm, bits); } } } if (other instanceof Point) { long val = ((Point)other).myValue; if (isSet(myBits, remainder(val, myMod))) { if (val >= myFrom && val <= myTo) return this; if (val < myFrom && modRange(val + 1, myFrom - 1, myMod, myBits).isEmpty() || val > myTo && modRange(myTo + 1, val - 1, myMod, myBits).isEmpty()) { return modRange(Math.min(myFrom, val), Math.max(myTo, val), myMod, myBits); } } return other.join(range(myFrom, myTo)); } return super.join(other); }