Java Number Range Check rangeCheck(int length, int fromIndex, int toIndex)

Here you can find the source of rangeCheck(int length, int fromIndex, int toIndex)

Description

Checks that fromIndex and toIndex are in the range and throws an appropriate exception, if they aren't.

License

Open Source License

Parameter

Parameter Description
length the length of the array.
fromIndex the starting index.
toIndex the end index.

Declaration

private static void rangeCheck(int length, int fromIndex, int toIndex) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from   w w w  .ja va2  s.co m*/
     * Checks that {@code fromIndex} and {@code toIndex} are in the range and throws an appropriate
     * exception, if they aren't.
     * 
     * @param length
     *            the length of the array.
     * @param fromIndex
     *            the starting index.
     * @param toIndex
     *            the end index.
     */
    private static void rangeCheck(int length, int fromIndex, int toIndex) {
        if (fromIndex > toIndex) {
            throw new IllegalArgumentException("fromIndex(" + fromIndex + ") > toIndex(" + toIndex + ")");
        }
        if (fromIndex < 0) {
            throw new ArrayIndexOutOfBoundsException(fromIndex);
        }
        if (toIndex > length) {
            throw new ArrayIndexOutOfBoundsException(toIndex);
        }
    }
}

Related

  1. rangeCheck(final C start, final C end, final C step)
  2. rangeCheck(final int value, final int min, final int max)
  3. rangeCheck(int arrayLen, int fromIndex, int toIndex)
  4. rangeCheck(int arrayLength, int offset, int length)
  5. rangeCheck(int index, int size)
  6. rangeCheck(int value, int begin, int end)
  7. rangeCheck(int value, int min, int max)
  8. rangeCheckForAdd(int index, int size)