public static CharRanges inclusive(int start, int end) { if (start > end) { throw new IndexOutOfBoundsException(start + " > " + end); } return new CharRanges(new int[] { start, end + 1 }); }
public static CharRanges inclusive(int start, int end) { if (start > end) { throw new IndexOutOfBoundsException(start + " > " + end); } return new CharRanges(new int[] { start, end + 1 }); }
/** * Returns an instance containing the given ranges. * @param ranges An even-length ordered sequence of non-overlapping, * non-contiguous, [inclusive start, exclusive end) ranges. */ public static CharRanges withRanges(int... ranges) { if ((ranges.length & 1) != 0) { throw new IllegalArgumentException(); } for (int i = 1; i < ranges.length; ++i) { if (ranges[i] <= ranges[i - 1]) { throw new IllegalArgumentException(ranges[i] + " > " + ranges[i - 1]); } } return new CharRanges(ranges); }
/** * Returns an instance containing the given ranges. * @param ranges An even-length ordered sequence of non-overlapping, * non-contiguous, [inclusive start, exclusive end) ranges. */ public static CharRanges withRanges(int... ranges) { if ((ranges.length & 1) != 0) { throw new IllegalArgumentException(); } for (int i = 1; i < ranges.length; ++i) { if (ranges[i] <= ranges[i - 1]) { throw new IllegalArgumentException(ranges[i] + " > " + ranges[i - 1]); } } return new CharRanges(ranges); }
/** * Shifts the bits matched by the given delta. * So if this has the bits (a, b, c, ..., z) set then the result has the bits * ((a - delta), (b - delta), (c - delta), ...., (z - delta)) set. * * @throws IndexOutOfBoundsException if shifting by delta would cause an * overflow or underflow in a 32 bit {@code signed int} range boundary. * Since the end boundaries of ranges are exclusive, even if there is no * range containing {@link Integer#MAX_VALUE}, shifting by a delta of 1 * can cause an overflow. */ public CharRanges shift(int delta) { int n = ranges.length; if (delta == 0 || n == 0) { return this; } // Test overflow/underflow if (delta < 0) { long lmin = ranges[0] + delta; if (lmin < Integer.MIN_VALUE) { throw new IndexOutOfBoundsException(); } } else { long lmax = ranges[n - 1] + delta; if (lmax > Integer.MAX_VALUE) { throw new IndexOutOfBoundsException(); } } // Create a shifted range. int[] shiftedRanges = new int[n]; for (int i = n; --i >= 0;) { shiftedRanges[i] = ranges[i] + delta; } return new CharRanges(shiftedRanges); }
/** * Returns an instance containing all and only the given members. */ public static CharRanges withMembers(int... members) { return new CharRanges(intArrayToRanges(members)); }
/** * Returns an instance containing all and only the given members. */ public static CharRanges withMembers(int... members) { return new CharRanges(intArrayToRanges(members)); }
/** * Shifts the bits matched by the given delta. * So if this has the bits (a, b, c, ..., z) set then the result has the bits * ((a - delta), (b - delta), (c - delta), ...., (z - delta)) set. * * @throws IndexOutOfBoundsException if shifting by delta would cause an * overflow or underflow in a 32 bit {@code signed int} range boundary. * Since the end boundaries of ranges are exclusive, even if there is no * range containing {@link Integer#MAX_VALUE}, shifting by a delta of 1 * can cause an overflow. */ public CharRanges shift(int delta) { int n = ranges.length; if (delta == 0 || n == 0) { return this; } // Test overflow/underflow if (delta < 0) { long lmin = ranges[0] + delta; if (lmin < Integer.MIN_VALUE) { throw new IndexOutOfBoundsException(); } } else { long lmax = ranges[n - 1] + delta; if (lmax > Integer.MAX_VALUE) { throw new IndexOutOfBoundsException(); } } // Create a shifted range. int[] shiftedRanges = new int[n]; for (int i = n; --i >= 0;) { shiftedRanges[i] = ranges[i] + delta; } return new CharRanges(shiftedRanges); }
return new CharRanges(difference);
return new CharRanges(difference);
intersection = newArr; return new CharRanges(intersection);
intersection = newArr; return new CharRanges(intersection);
out = clipped; return new CharRanges(out);
out = clipped; return new CharRanges(out);