List of usage examples for java.lang IndexOutOfBoundsException IndexOutOfBoundsException
public IndexOutOfBoundsException(int index)
From source file:com.clark.func.Functions.java
/** * <p>//from w w w . j a v a2s. c o m * Validates that the index is within the bounds of the argument character * sequence; otherwise throwing an exception with the specified message. * </p> * * <pre> * Validate.validIndex(myStr, 2, "The string index is invalid: "); * </pre> * * <p> * If the character sequence is <code>null</code>, then the message of the * exception is "The validated object is null". * </p> * * @param <T> * the character sequence type * @param chars * the character sequence to check * @param index * the index * @param message * the exception message if invalid * @return the validated character sequence (never <code>null</code> for * method chaining) * @throws NullPointerException * if the character sequence is <code>null</code> * @throws IndexOutOfBoundsException * if the index is invalid * @see #validIndex(CharSequence, int) */ public static <T extends CharSequence> T validIndex(T chars, int index, String message, Object... values) { notNull(chars); if (index < 0 || index >= chars.length()) { throw new IndexOutOfBoundsException(String.format(message, values)); } return chars; }