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.idylwood.utils.MathUtils.java

public static final double linearCombinationFast(final double[] x, final double[] y, final int startOne,
        final int startTwo, final int len) {
    if (startOne + len > x.length || startTwo + len > y.length)
        throw new ArrayIndexOutOfBoundsException("Bad length!");
    double ret = 0;
    final int unroll = 3;
    final int modLen = len - len % unroll;
    int i = 0;/*from  w w w  . j  a v a  2 s .  c o  m*/
    for (; i < modLen; i += unroll) {
        final int xPtr = i + startOne;
        final int yPtr = i + startTwo;
        ret += x[xPtr] * y[yPtr] + x[xPtr + 1] * y[yPtr + 1] + x[xPtr + 2] * y[yPtr + 2];
        //+ x[xPtr+3]*y[yPtr+3];
    }
    // get the terms at the end
    for (; i < len; i++) {
        ret += x[i + startOne] * y[i + startTwo];
    }
    return ret;
}

From source file:org.apache.nifi.cdc.mysql.processors.CaptureChangeMySQL.java

/**
 * Get a list of hosts from a NiFi property, e.g.
 *
 * @param hostsString A comma-separated list of hosts (host:port,host2:port2, etc.)
 * @return List of InetSocketAddresses for the hosts
 */// ww  w  . ja  v a 2  s. co m
private List<InetSocketAddress> getHosts(String hostsString) {

    if (hostsString == null) {
        return null;
    }
    final List<String> hostsSplit = Arrays.asList(hostsString.split(","));
    List<InetSocketAddress> hostsList = new ArrayList<>();

    for (String item : hostsSplit) {
        String[] addresses = item.split(":");
        if (addresses.length != 2) {
            throw new ArrayIndexOutOfBoundsException("Not in host:port format");
        }

        hostsList.add(new InetSocketAddress(addresses[0].trim(), Integer.parseInt(addresses[1].trim())));
    }
    return hostsList;
}

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

public Stack getMainStack() throws ArrayIndexOutOfBoundsException {
    if (mainStackIDs[0] == -1) {
        throw new ArrayIndexOutOfBoundsException("No main stack specified");
    }//from w  ww.j a  v a2  s .  c om

    return stacks[mainStackIDs[0]];
}

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

public int getLastTableauId() throws ArrayIndexOutOfBoundsException {
    if (lastTableauID == -1) {
        throw new ArrayIndexOutOfBoundsException("No last tableau stack specified");
    }// ww  w. j  a v  a 2s . c om

    return lastTableauID;
}

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

public Stack getLastTableauStack() throws ArrayIndexOutOfBoundsException {
    if (lastTableauID == -1) {
        throw new ArrayIndexOutOfBoundsException("No last tableau stack specified");
    }/*  w w w  .jav  a 2s .c o  m*/

    return stacks[lastTableauID];
}

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

public Stack getDiscardStack() throws ArrayIndexOutOfBoundsException {
    if (firstDiscardStackID == -1) {
        throw new ArrayIndexOutOfBoundsException("No discard stack specified");
    }//  www  .j  av  a 2 s  . c o  m

    return stacks[firstDiscardStackID];
}

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

public ArrayList<Stack> getDiscardStacks() throws ArrayIndexOutOfBoundsException {
    ArrayList<Stack> discardStacks = new ArrayList<>();

    for (int id : discardStackIDs) {
        if (id == -1) {
            throw new ArrayIndexOutOfBoundsException("No discard stack specified");
        }/*from  ww  w  .  j a va2 s. co m*/

        discardStacks.add(stacks[id]);
    }

    return discardStacks;
}

From source file:syncleus.dann.data.matrix.SimpleRealMatrix.java

/**
 * Get a submatrix.//  w  w w . j av  a 2 s .  c o  m
 *
 * @param r  Array of row indices.
 * @param j0 Initial column index
 * @param j1 Final column index
 * @return The specified submatrix.
 */
public SimpleRealMatrix getMatrix(final int[] r, final int j0, final int j1) {
    final SimpleRealMatrix result = new SimpleRealMatrix(r.length, j1 - j0 + 1);
    final double[][] b = result.getData();
    try {
        for (int i = 0; i < r.length; i++) {
            System.arraycopy(this.matrixElements[r[i]], j0, b[i], j0 - j0, j1 + 1 - j0);
        }
    } catch (final ArrayIndexOutOfBoundsException e) {
        throw new ArrayIndexOutOfBoundsException("Submatrix indices");
    }
    return result;
}

From source file:org.apache.bookkeeper.client.LedgerHandle.java

/**
 * Add entry asynchronously to an open ledger, using an offset and range.
 *
 * @param data/*from www .  j av a  2 s  . c  o m*/
 *          array of bytes to be written
 * @param offset
 *          offset from which to take bytes from data
 * @param length
 *          number of bytes to take from data
 * @param cb
 *          object implementing callbackinterface
 * @param ctx
 *          some control object
 * @throws ArrayIndexOutOfBoundsException if offset or length is negative or
 *          offset and length sum to a value higher than the length of data.
 */
public void asyncAddEntry(final byte[] data, final int offset, final int length, final AddCallback cb,
        final Object ctx) {
    if (offset < 0 || length < 0 || (offset + length) > data.length) {
        throw new ArrayIndexOutOfBoundsException(
                "Invalid values for offset(" + offset + ") or length(" + length + ")");
    }

    asyncAddEntry(Unpooled.wrappedBuffer(data, offset, length), cb, ctx);
}

From source file:uk.ac.diamond.scisoft.analysis.dataset.AbstractDataset.java

/**
 * Function that uses the knowledge of the dataset to calculate the index in the data array that corresponds to the
 * n-dimensional position given by the int array. The input values <b>must</b> be inside the arrays, this should be
 * ok as this function is mainly in code which will be run inside the get and set functions
 * /*from   w  w w . ja v a 2  s .  c  om*/
 * @param n
 *            the integer array specifying the n-D position
 * @return the index on the data array corresponding to that location
 */
protected int get1DIndex(final int... n) {
    final int imax = n.length;
    final int rank = shape.length;
    if (imax == 0) {
        if (rank == 0)
            return 0;
        if (rank == 1 && shape[0] == 0) {
            return 0;
        }
        throw new IllegalArgumentException("One or more index parameters must be supplied");
    } else if (imax > rank) {
        throw new IllegalArgumentException("No of index parameters is different to the shape of data: " + imax
                + " given " + rank + " required");
    }

    // once checked return the appropriate value.
    int index = n[0];
    final int sz = shape[0];
    if (index < -sz || index >= sz) {
        throw new ArrayIndexOutOfBoundsException(
                "Index (" + index + ") out of range [-" + sz + "," + sz + ") in dimension 0");
    }
    if (index < 0) {
        index += sz;
    }

    if (rank == 1) {
        return index;
    }

    final int[] lshape = dataShape == null ? shape : dataShape;

    int i = 1;
    for (; i < imax; i++) {
        final int ni = n[i];
        final int si = shape[i];
        if (ni < -si || ni >= si) {
            throw new ArrayIndexOutOfBoundsException(
                    "Index (" + ni + ") out of range [-" + si + "," + si + ") in dimension " + i);
        }
        index = index * lshape[i] + ni;
        if (ni < 0) {
            index += si;
        }
    }
    for (; i < lshape.length; i++) {
        index *= lshape[i];
    }

    return index;
}