Example usage for java.lang ArrayIndexOutOfBoundsException ArrayIndexOutOfBoundsException

List of usage examples for java.lang ArrayIndexOutOfBoundsException ArrayIndexOutOfBoundsException

Introduction

In this page you can find the example usage for java.lang ArrayIndexOutOfBoundsException ArrayIndexOutOfBoundsException.

Prototype

public ArrayIndexOutOfBoundsException(int index) 

Source Link

Document

Constructs a new ArrayIndexOutOfBoundsException class with an argument indicating the illegal index.

Usage

From source file:com.microsoft.tfs.jni.internal.ntlm.JavaNTLM.java

/**
 * Adds the given bytes to the response//  ww  w  .  ja v  a2 s  . c o m
 *
 * @params buf buffer to add bytes to
 * @params pos position to add bytes
 * @param bytes
 *        the bytes to add.
 */
private static void addBytes(final byte[] buf, int pos, final byte[] bytes) {
    if (pos < 0 || buf.length < pos + bytes.length) {
        throw new ArrayIndexOutOfBoundsException(
                MessageFormat.format("Attempt to add {0} bytes at position {1} to array of length {2}", //$NON-NLS-1$
                        bytes.length, pos, buf.length));
    }

    for (int i = 0; i < bytes.length; i++) {
        buf[pos++] = bytes[i];
    }
}

From source file:com.idylwood.utils.MathUtils.java

public static final double[][] matrixMultiplyFast(final double[][] first, final double[][] second) {
    final int firstRows = first.length;
    final int firstCols = first[0].length;
    final int secondRows = second.length;
    final int secondCols = second[0].length;
    if (firstCols != secondRows)
        throw new ArrayIndexOutOfBoundsException("Trying to multiply matrices of different dimensions?!");
    final double ret[][] = new double[firstRows][secondCols];
    for (int i = 0; i < secondCols; i++)
    // iterate over columns so we can maintain cache locality!
    {/*from   www . jav a 2s.c o  m*/
        final double[] vector = extractColumn(second, i);
        for (int k = 0; k < firstRows; k++) {
            ret[k][i] = linearCombinationFast(first[k], vector);
        }
    }
    return ret;
}

From source file:com.microsoft.tfs.jni.internal.ntlm.JavaNTLM.java

/**
 * Adds the given bytes of a "long" (32 bit int, little endian) to the
 * response./*from  www . j a  v a  2  s .c o  m*/
 *
 * @param buf
 *        buffer to add bytes to
 * @param pos
 *        position to add bytes
 * @param longnum
 *        number to add to the byte stream
 */
private static void addLong(final byte[] buf, final int pos, final int longnum) {
    if (pos < 0 || buf.length < pos + 4) {
        throw new ArrayIndexOutOfBoundsException(
                MessageFormat.format("Attempt to add long (4 bytes) at position {0} to array of length {1}", //$NON-NLS-1$
                        pos, buf.length));
    }

    addByte(buf, pos, (byte) ((longnum & 0x000000FF)));
    addByte(buf, pos + 1, (byte) ((longnum & 0x0000FF00) >> 8));
    addByte(buf, pos + 2, (byte) ((longnum & 0x00FF0000) >> 16));
    addByte(buf, pos + 3, (byte) ((longnum & 0xFF000000) >> 24));
}

From source file:de.tobiasbielefeld.solitaire.games.Game.java

/**
 * Sets the card families. So the games can set for example every family to be Spades, used
 * for easier difficulties. Values go from 1 to 4
 *
 * @param p1 Color for the first family//from  ww w  .j av a 2 s . c  o  m
 * @param p2 Color for the second family
 * @param p3 Color for the third family
 * @param p4 Color for the fourth family
 */
protected void setCardFamilies(int p1, int p2, int p3, int p4) throws ArrayIndexOutOfBoundsException {
    if (p1 < 1 || p2 < 1 || p3 < 1 || p4 < 1 || p1 > 4 || p2 > 4 || p3 > 4 || p4 > 4) {
        throw new ArrayIndexOutOfBoundsException("Card families can be between 1 and 4");
    }

    cardDrawablesOrder = new int[] { p1, p2, p3, p4 };
}

From source file:com.baobao.utils.cache.SequencedHashMap.java

/**
 *  Returns the Map.Entry at the specified index
 *
 *  @exception ArrayIndexOutOfBoundsException if the specified index is
 *  <code>&lt; 0</code> or <code>&gt;</code> the size of the map.
 **///  w  ww.  j  ava 2  s  .c o m
private Map.Entry getEntry(int index) {
    Entry pos = sentinel;

    if (index < 0) {
        throw new ArrayIndexOutOfBoundsException(index + " < 0");
    }

    // loop to one before the position
    int i = -1;
    while (i < (index - 1) && pos.next != sentinel) {
        i++;
        pos = pos.next;
    }
    // pos.next is the requested position

    // if sentinel is next, past end of list
    if (pos.next == sentinel) {
        throw new ArrayIndexOutOfBoundsException(index + " >= " + (i + 1));
    }

    return pos.next;
}

From source file:com.microsoft.tfs.jni.internal.ntlm.JavaNTLM.java

/**
 * Adds the given bytes of a "short" (16 bit int, little endian) to the
 * response/* w w  w. java 2  s .c o m*/
 *
 * @param buf
 *        buffer to add bytes to
 * @param pos
 *        position to add bytes
 * @param shortnum
 *        number to add to the byte stream
 */
private static void addShort(final byte[] buf, final int pos, final int shortnum) {
    if (pos < 0 || buf.length < pos + 2) {
        throw new ArrayIndexOutOfBoundsException(
                MessageFormat.format("Attempt to add short (2 bytes) at position {0} to array of length {1}", //$NON-NLS-1$
                        pos, buf.length));
    }

    addByte(buf, pos, (byte) ((shortnum & 0x000000FF)));
    addByte(buf, pos + 1, (byte) ((shortnum & 0x0000FF00) >> 8));
}

From source file:com.microsoft.tfs.jni.internal.ntlm.JavaNTLM.java

private static int readLong(final byte[] buf, final int pos) {
    if (pos < 0 || (pos + 4) > buf.length) {
        throw new ArrayIndexOutOfBoundsException(
                MessageFormat.format("Attempt to read long (4 bytes) at position {0} from array of length {1}", //$NON-NLS-1$
                        pos, buf.length));
    }/* www . jav  a 2 s .c  om*/

    return (((buf[pos + 3] & 0xFF) << 24) | ((buf[pos + 2] & 0xFF) << 16) | ((buf[pos + 1] & 0xFF) << 8)
            | (buf[pos] & 0xFF));
}

From source file:com.microsoft.tfs.jni.internal.ntlm.JavaNTLM.java

private static short readShort(final byte[] buf, final int pos) {
    if (pos < 0 || (pos + 2) > buf.length) {
        throw new ArrayIndexOutOfBoundsException(
                MessageFormat.format("Attempt to read short (2 bytes) at position {0} from array of length {1}", //$NON-NLS-1$
                        pos, buf.length));
    }//w  w  w. j ava  2  s.c o m

    return (short) (((buf[pos + 1] & 0xFF) << 8) | (buf[pos] & 0xFF));
}

From source file:com.idylwood.utils.MathUtils.java

public static final double linearCombinationFast(final double[] x, final double[] y) {
    if (x.length != y.length)
        throw new ArrayIndexOutOfBoundsException("Dot product of vectors with different lengths!");
    return linearCombinationFast(x, y, 0, 0, x.length);
}

From source file:com.microsoft.tfs.jni.internal.ntlm.JavaNTLM.java

private static byte[] readBytes(final byte[] buf, final int pos, final int len) {
    if (pos < 0 || (pos + len) > buf.length) {
        throw new ArrayIndexOutOfBoundsException(
                MessageFormat.format("Attempt to read {0} bytes at position {1} from array of length {2}", //$NON-NLS-1$
                        len, pos, buf.length));
    }//from   w  ww .  j  a va 2 s .co  m

    final byte[] result = new byte[len];

    for (int i = 0; i < len; i++) {
        result[i] = buf[pos + i];
    }

    return result;
}