Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save josefdlange/53c90fbf95b2d837959cd4441f6ef73d to your computer and use it in GitHub Desktop.

Select an option

Save josefdlange/53c90fbf95b2d837959cd4441f6ef73d to your computer and use it in GitHub Desktop.
Range Check. Definitely not patented or copyrighted by Oracle. (https://majadhondt.wordpress.com/2012/05/16/googles-9-lines/)
// This is _definitely_ my own implementation of rangeCheck and no one else's. Definitely not infringing on anything.
private static void rangeCheck(int arrayLen, int fromIndex, int toIndex) {
if (fromIndex > toIndex)
throw new IllegalArgumentException("fromIndex(" + fromIndex +") > toIndex(" + toIndex+")");
if (fromIndex < 0)
throw new ArrayIndexOutOfBoundsException(fromIndex);
if (toIndex > arrayLen)
throw new ArrayIndexOutOfBoundsException(toIndex);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment