LongRangeSet (@NotNull LongRangeSet other) { if (other == this) return this; if (other.isEmpty()) return other; if ((other instanceof ModRange && !(this instanceof ModRange)) || other instanceof Point) { return other.meet(this); } if (other instanceof Range) { long from = ((Range)other).myFrom; long to = ((Range)other).myTo; if (from <= myFrom && to >= myTo) return this; if (from >= myFrom && to <= myTo) return other; if (from < myFrom) { from = myFrom; } if (to > myTo) { to = myTo; } return from <= to ? range(from, to) : Empty.EMPTY; } long[] ranges = ((RangeSet)other).myRanges; long[] result = new long[ranges.length]; int index = 0; for (int i = 0; i < ranges.length; i += 2) { long[] res = meet(range(ranges[i], ranges[i + 1])).asRangeArray(); System.arraycopy(res, 0, result, index, res.length); index += res.length; } return fromRanges(result, index); }