/** * Ensures that {@code index} specifies a valid <i>position</i> in an array, * list or string of size {@code size}. A position index may range from zero * to {@code size}, inclusive. * * @param index a user-supplied index identifying a position in an array, list * or string * @param size the size of that array, list or string * @throws IndexOutOfBoundsException if {@code index} is negative or is * greater than {@code size} * @throws IllegalArgumentException if {@code size} is negative */ public static void checkPositionIndex(int index, int size) { checkPositionIndex(index, size, "index"); }
/** * Ensures that {@code start} and {@code end} specify a valid <i>positions</i> * in an array, list or string of size {@code size}, and are in order. A * position index may range from zero to {@code size}, inclusive. * * @param start a user-supplied index identifying a starting position in an * array, list or string * @param end a user-supplied index identifying a ending position in an array, * list or string * @param size the size of that array, list or string * @throws IndexOutOfBoundsException if either index is negative or is * greater than {@code size}, or if {@code end} is less than {@code start} * @throws IllegalArgumentException if {@code size} is negative */ public static void checkPositionIndexes(int start, int end, int size) { checkPositionIndex(start, size, "start index"); checkPositionIndex(end, size, "end index"); if (end < start) { throw new IndexOutOfBoundsException(format( "end index (%s) must not be less than start index (%s)", end, start)); } }
/** * Ensures that {@code index} specifies a valid <i>position</i> in an array, * list or string of size {@code size}. A position index may range from zero * to {@code size}, inclusive. * * @param index a user-supplied index identifying a position in an array, list * or string * @param size the size of that array, list or string * @throws IndexOutOfBoundsException if {@code index} is negative or is * greater than {@code size} * @throws IllegalArgumentException if {@code size} is negative */ public static void checkPositionIndex(int index, int size) { checkPositionIndex(index, size, "index"); }
/** * Ensures that {@code index} specifies a valid <i>position</i> in an array, * list or string of size {@code size}. A position index may range from zero * to {@code size}, inclusive. * * @param index a user-supplied index identifying a position in an array, list * or string * @param size the size of that array, list or string * @throws IndexOutOfBoundsException if {@code index} is negative or is * greater than {@code size} * @throws IllegalArgumentException if {@code size} is negative */ public static void checkPositionIndex(int index, int size) { checkPositionIndex(index, size, "index"); }
/** * Ensures that {@code index} specifies a valid <i>position</i> in an array, * list or string of size {@code size}. A position index may range from zero * to {@code size}, inclusive. * * @param index a user-supplied index identifying a position in an array, list * or string * @param size the size of that array, list or string * @throws IndexOutOfBoundsException if {@code index} is negative or is * greater than {@code size} * @throws IllegalArgumentException if {@code size} is negative */ public static void checkPositionIndex(int index, int size) { checkPositionIndex(index, size, "index"); }
/** * Ensures that {@code index} specifies a valid <i>position</i> in an array, * list or string of size {@code size}. A position index may range from zero * to {@code size}, inclusive. * * @param index a user-supplied index identifying a position in an array, list * or string * @param size the size of that array, list or string * @throws IndexOutOfBoundsException if {@code index} is negative or is * greater than {@code size} * @throws IllegalArgumentException if {@code size} is negative */ public static void checkPositionIndex(int index, int size) { checkPositionIndex(index, size, "index"); }
@Override public int indexIn(CharSequence sequence, int start) { int length = sequence.length(); Preconditions.checkPositionIndex(start, length); return (start == length) ? -1 : start; } @Override public int lastIndexIn(CharSequence sequence) {
@Override public int indexIn(CharSequence sequence, int start) { int length = sequence.length(); Preconditions.checkPositionIndex(start, length); return -1; } @Override public int lastIndexIn(CharSequence sequence) {
@Override public int indexIn(CharSequence sequence, int start) { int length = sequence.length(); Preconditions.checkPositionIndex(start, length); return (start == length) ? -1 : start; } @Override public int lastIndexIn(CharSequence sequence) {
@Override public int indexIn(CharSequence sequence, int start) { int length = sequence.length(); Preconditions.checkPositionIndex(start, length); return -1; } @Override public int lastIndexIn(CharSequence sequence) {
@Override public int indexIn(CharSequence sequence, int start) { int length = sequence.length(); Preconditions.checkPositionIndex(start, length); return (start == length) ? -1 : start; } @Override public int lastIndexIn(CharSequence sequence) {
@Override public int indexIn(CharSequence sequence, int start) { int length = sequence.length(); Preconditions.checkPositionIndex(start, length); return -1; } @Override public int lastIndexIn(CharSequence sequence) {
/** * Ensures that {@code start} and {@code end} specify a valid <i>positions</i> * in an array, list or string of size {@code size}, and are in order. A * position index may range from zero to {@code size}, inclusive. * * @param start a user-supplied index identifying a starting position in an * array, list or string * @param end a user-supplied index identifying a ending position in an array, * list or string * @param size the size of that array, list or string * @throws IndexOutOfBoundsException if either index is negative or is * greater than {@code size}, or if {@code end} is less than {@code start} * @throws IllegalArgumentException if {@code size} is negative */ public static void checkPositionIndexes(int start, int end, int size) { checkPositionIndex(start, size, "start index"); checkPositionIndex(end, size, "end index"); if (end < start) { throw new IndexOutOfBoundsException(format( "end index (%s) must not be less than start index (%s)", end, start)); } }
/** * Ensures that {@code start} and {@code end} specify a valid <i>positions</i> * in an array, list or string of size {@code size}, and are in order. A * position index may range from zero to {@code size}, inclusive. * * @param start a user-supplied index identifying a starting position in an * array, list or string * @param end a user-supplied index identifying a ending position in an array, * list or string * @param size the size of that array, list or string * @throws IndexOutOfBoundsException if either index is negative or is * greater than {@code size}, or if {@code end} is less than {@code start} * @throws IllegalArgumentException if {@code size} is negative */ public static void checkPositionIndexes(int start, int end, int size) { checkPositionIndex(start, size, "start index"); checkPositionIndex(end, size, "end index"); if (end < start) { throw new IndexOutOfBoundsException(format( "end index (%s) must not be less than start index (%s)", end, start)); } }
/** * Ensures that {@code start} and {@code end} specify a valid <i>positions</i> * in an array, list or string of size {@code size}, and are in order. A * position index may range from zero to {@code size}, inclusive. * * @param start a user-supplied index identifying a starting position in an * array, list or string * @param end a user-supplied index identifying a ending position in an array, * list or string * @param size the size of that array, list or string * @throws IndexOutOfBoundsException if either index is negative or is * greater than {@code size}, or if {@code end} is less than {@code start} * @throws IllegalArgumentException if {@code size} is negative */ public static void checkPositionIndexes(int start, int end, int size) { checkPositionIndex(start, size, "start index"); checkPositionIndex(end, size, "end index"); if (end < start) { throw new IndexOutOfBoundsException(format( "end index (%s) must not be less than start index (%s)", end, start)); } }
/** * Ensures that {@code start} and {@code end} specify a valid <i>positions</i> * in an array, list or string of size {@code size}, and are in order. A * position index may range from zero to {@code size}, inclusive. * * @param start a user-supplied index identifying a starting position in an * array, list or string * @param end a user-supplied index identifying a ending position in an array, * list or string * @param size the size of that array, list or string * @throws IndexOutOfBoundsException if either index is negative or is * greater than {@code size}, or if {@code end} is less than {@code start} * @throws IllegalArgumentException if {@code size} is negative */ public static void checkPositionIndexes(int start, int end, int size) { checkPositionIndex(start, size, "start index"); checkPositionIndex(end, size, "end index"); if (end < start) { throw new IndexOutOfBoundsException(format( "end index (%s) must not be less than start index (%s)", end, start)); } }
/** * Returns the index of the first matching character in a character sequence, * starting from a given position, or {@code -1} if no character matches after * that position. * * <p>The default implementation iterates over the sequence in forward order, * beginning at {@code start}, calling {@link #matches} for each character. * * @param sequence the character sequence to examine * @param start the first index to examine; must be nonnegative and no * greater than {@code sequence.length()} * @return the index of the first matching character, guaranteed to be no less * than {@code start}, or {@code -1} if no character matches * @throws IndexOutOfBoundsException if start is negative or greater than * {@code sequence.length()} */ public int indexIn(CharSequence sequence, int start) { int length = sequence.length(); Preconditions.checkPositionIndex(start, length); for (int i = start; i < length; i++) { if (matches(sequence.charAt(i))) { return i; } } return -1; }
/** * Returns the index of the first matching character in a character sequence, * starting from a given position, or {@code -1} if no character matches after * that position. * * <p>The default implementation iterates over the sequence in forward order, * beginning at {@code start}, calling {@link #matches} for each character. * * @param sequence the character sequence to examine * @param start the first index to examine; must be nonnegative and no * greater than {@code sequence.length()} * @return the index of the first matching character, guaranteed to be no less * than {@code start}, or {@code -1} if no character matches * @throws IndexOutOfBoundsException if start is negative or greater than * {@code sequence.length()} */ public int indexIn(CharSequence sequence, int start) { int length = sequence.length(); Preconditions.checkPositionIndex(start, length); for (int i = start; i < length; i++) { if (matches(sequence.charAt(i))) { return i; } } return -1; }
/** * Returns the index of the first matching character in a character sequence, * starting from a given position, or {@code -1} if no character matches after * that position. * * <p>The default implementation iterates over the sequence in forward order, * beginning at {@code start}, calling {@link #matches} for each character. * * @param sequence the character sequence to examine * @param start the first index to examine; must be nonnegative and no * greater than {@code sequence.length()} * @return the index of the first matching character, guaranteed to be no less * than {@code start}, or {@code -1} if no character matches * @throws IndexOutOfBoundsException if start is negative or greater than * {@code sequence.length()} */ public int indexIn(CharSequence sequence, int start) { int length = sequence.length(); Preconditions.checkPositionIndex(start, length); for (int i = start; i < length; i++) { if (matches(sequence.charAt(i))) { return i; } } return -1; }