Substring (@NotNull Substring other) { if (!myString.equals(other.myString)) { throw new IllegalArgumentException(String.format("Substrings '%s' and '%s' must belong to the same origin", this, other)); } final TextRange unionRange = getTextRange().union(other.getTextRange()); return new Substring(getSuperString(), unionRange.getStartOffset(), unionRange.getEndOffset()); }