Lines Matching refs:index

256    * Ensures that {@code index} specifies a valid <i>element</i> in an array,
257 * list or string of size {@code size}. An element index may range from zero,
260 * @param index a user-supplied index identifying an element of an array, list
263 * @return the value of {@code index}
264 * @throws IndexOutOfBoundsException if {@code index} is negative or is not
268 public static int checkElementIndex(int index, int size) {
269 return checkElementIndex(index, size, "index");
273 * Ensures that {@code index} specifies a valid <i>element</i> in an array,
274 * list or string of size {@code size}. An element index may range from zero,
277 * @param index a user-supplied index identifying an element of an array, list
280 * @param desc the text to use to describe this index in an error message
281 * @return the value of {@code index}
282 * @throws IndexOutOfBoundsException if {@code index} is negative or is not
286 public static int checkElementIndex(int index, int size, String desc) {
288 if (index < 0 || index >= size) {
289 throw new IndexOutOfBoundsException(badElementIndex(index, size, desc));
291 return index;
294 private static String badElementIndex(int index, int size, String desc) {
295 if (index < 0) {
296 return format("%s (%s) must not be negative", desc, index);
299 } else { // index >= size
300 return format("%s (%s) must be less than size (%s)", desc, index, size);
305 * Ensures that {@code index} specifies a valid <i>position</i> in an array,
306 * list or string of size {@code size}. A position index may range from zero
309 * @param index a user-supplied index identifying a position in an array, list
312 * @return the value of {@code index}
313 * @throws IndexOutOfBoundsException if {@code index} is negative or is
317 public static int checkPositionIndex(int index, int size) {
318 return checkPositionIndex(index, size, "index");
322 * Ensures that {@code index} specifies a valid <i>position</i> in an array,
323 * list or string of size {@code size}. A position index may range from zero
326 * @param index a user-supplied index identifying a position in an array, list
329 * @param desc the text to use to describe this index in an error message
330 * @return the value of {@code index}
331 * @throws IndexOutOfBoundsException if {@code index} is negative or is
335 public static int checkPositionIndex(int index, int size, String desc) {
337 if (index < 0 || index > size) {
338 throw new IndexOutOfBoundsException(badPositionIndex(index, size, desc));
340 return index;
343 private static String badPositionIndex(int index, int size, String desc) {
344 if (index < 0) {
345 return format("%s (%s) must not be negative", desc, index);
348 } else { // index > size
350 desc, index, size);
357 * position index may range from zero to {@code size}, inclusive.
359 * @param start a user-supplied index identifying a starting position in an
361 * @param end a user-supplied index identifying a ending position in an array,
364 * @throws IndexOutOfBoundsException if either index is negative or is
377 return badPositionIndex(start, size, "start index");
380 return badPositionIndex(end, size, "end index");
383 return format("end index (%s) must not be less than start index (%s)",