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:uk.ac.diamond.scisoft.analysis.dataset.ShortDataset.java

/**
 * Sets the value at a particular point to the passed value. Note, this will automatically expand the dataset if the
 * given position is outside its bounds and make it discontiguous.
 *
 * @param value//w  w w .j  a v a2  s  .  com
 * @param pos
 */
public void setItem(final short value, final int... pos) { // PRIM_TYPE
    try {
        if (!isPositionInShape(pos)) {
            int[] nshape = shape.clone();

            for (int i = 0; i < pos.length; i++)
                if (pos[i] >= nshape[i])
                    nshape[i] = pos[i] + 1;

            allocateArray(nshape);
        }
        setAbs(get1DIndex(pos), value);
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException(
                String.format("Dimensionalities of requested position, %d, and dataset, %d, are incompatible",
                        pos.length, shape.length));
    } catch (ArrayIndexOutOfBoundsException e) {
        throw new ArrayIndexOutOfBoundsException("Index out of bounds - need to make dataset extendible");
    }
}

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

/**
 * Sets the value at a particular point to the passed value. Note, this will automatically expand the dataset if the
 * given position is outside its bounds and make it discontiguous.
 *
 * @param value/*  w w  w.  j  a va  2 s  .c  om*/
 * @param pos
 */
public void setItem(final int value, final int... pos) { // PRIM_TYPE
    try {
        if (!isPositionInShape(pos)) {
            int[] nshape = shape.clone();

            for (int i = 0; i < pos.length; i++)
                if (pos[i] >= nshape[i])
                    nshape[i] = pos[i] + 1;

            allocateArray(nshape);
        }
        setAbs(get1DIndex(pos), value);
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException(
                String.format("Dimensionalities of requested position, %d, and dataset, %d, are incompatible",
                        pos.length, shape.length));
    } catch (ArrayIndexOutOfBoundsException e) {
        throw new ArrayIndexOutOfBoundsException("Index out of bounds - need to make dataset extendible");
    }
}

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

/**
 * Sets the value at a particular point to the passed value. Note, this will automatically expand the dataset if the
 * given position is outside its bounds and make it discontiguous.
 *
 * @param value/*from w w  w. ja  va 2s.  c  o  m*/
 * @param pos
 */
public void setItem(final float value, final int... pos) { // PRIM_TYPE
    try {
        if (!isPositionInShape(pos)) {
            int[] nshape = shape.clone();

            for (int i = 0; i < pos.length; i++)
                if (pos[i] >= nshape[i])
                    nshape[i] = pos[i] + 1;

            allocateArray(nshape);
        }
        setAbs(get1DIndex(pos), value);
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException(
                String.format("Dimensionalities of requested position, %d, and dataset, %d, are incompatible",
                        pos.length, shape.length));
    } catch (ArrayIndexOutOfBoundsException e) {
        throw new ArrayIndexOutOfBoundsException("Index out of bounds - need to make dataset extendible");
    }
}

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

/**
 * Sets the value at a particular point to the passed value. Note, this will automatically expand the dataset if the
 * given position is outside its bounds and make it discontiguous.
 * // w w w .j  a va  2s.com
 * @param value
 * @param pos
 */
public void setItem(final double value, final int... pos) { // PRIM_TYPE
    try {
        if (!isPositionInShape(pos)) {
            int[] nshape = shape.clone();

            for (int i = 0; i < pos.length; i++)
                if (pos[i] >= nshape[i])
                    nshape[i] = pos[i] + 1;

            allocateArray(nshape);
        }
        setAbs(get1DIndex(pos), value);
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException(
                String.format("Dimensionalities of requested position, %d, and dataset, %d, are incompatible",
                        pos.length, shape.length));
    } catch (ArrayIndexOutOfBoundsException e) {
        throw new ArrayIndexOutOfBoundsException("Index out of bounds - need to make dataset extendible");
    }
}

From source file:org.apache.phoenix.util.StringUtil.java

/**
 * Checks that fromIndex and toIndex are in the range and throws an appropriate exception, if they
 * are not//from w w  w .j  a v a  2  s  .  c  om
 */
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);
    }
}

From source file:Matrix.java

/**
 * Set a submatrix.//from   w ww .  j a va 2 s .c  om
 * 
 * @param i0
 *            Initial row index
 * @param i1
 *            Final row index
 * @param j0
 *            Initial column index
 * @param j1
 *            Final column index
 * @param X
 *            A(i0:i1,j0:j1)
 * @exception ArrayIndexOutOfBoundsException
 *                Submatrix indices
 */

public void setMatrix(int i0, int i1, int j0, int j1, Matrix X) {
    try {
        for (int i = i0; i <= i1; i++) {
            for (int j = j0; j <= j1; j++) {
                A[i][j] = X.get(i - i0, j - j0);
            }
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        throw new ArrayIndexOutOfBoundsException("Submatrix indices");
    }
}

From source file:com.flexive.shared.FxArrayUtils.java

/**
 * Get an integer element from a string array
 *
 * @param array     the string array//from w  ww  .j av  a  2  s.c  om
 * @param separator seperator character
 * @param index     index to get the element at
 * @return element  or <code>Integer.MIN_VALUE</code> if not set
 */
public static int getIntElementAt(String array, char separator, int index) {
    try {
        if (index == 0) {
            final int sep = array.indexOf(separator);
            return sep == 0 ? Integer.MIN_VALUE : Integer.parseInt(sep == -1 ? array : array.substring(0, sep));
        }
        int curr = 0;
        int start = 0;
        for (int i = 0; i < array.length(); i++) {
            final char c = array.charAt(i);
            if (c == separator)
                curr++;
            if (curr == index) {
                final int numStart = start + 1;
                int end = array.indexOf(',', numStart);
                if (end == -1) {
                    return numStart == array.length() ? Integer.MIN_VALUE
                            : Integer.parseInt(array.substring(numStart));
                } else if (end == numStart) {
                    return Integer.MIN_VALUE; // no entry
                }
                return Integer.parseInt(array.substring(numStart, end));
            }
            start++;
        }
    } catch (NumberFormatException e) {
        return Integer.MIN_VALUE;
    }
    throw new ArrayIndexOutOfBoundsException("Index " + index + " is out of bounds for [" + array + "]");
}

From source file:Matrix.java

/**
 * Set a submatrix./*w  w  w . j a  va  2  s  .c om*/
 * 
 * @param r
 *            Array of row indices.
 * @param c
 *            Array of column indices.
 * @param X
 *            A(r(:),c(:))
 * @exception ArrayIndexOutOfBoundsException
 *                Submatrix indices
 */

public void setMatrix(int[] r, int[] c, Matrix X) {
    try {
        for (int i = 0; i < r.length; i++) {
            for (int j = 0; j < c.length; j++) {
                A[r[i]][c[j]] = X.get(i, j);
            }
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        throw new ArrayIndexOutOfBoundsException("Submatrix indices");
    }
}

From source file:de.thomaskrille.dropwizard.environment_configuration.EnvironmentConfigurationFactory.java

private void addOverride(JsonNode root, String name, String value) {
    JsonNode node = root;/*from   w  ww.j  a v  a2 s  . com*/
    final Iterable<String> split = Splitter.on('.').trimResults().split(name);
    final String[] parts = Iterables.toArray(split, String.class);

    for (int i = 0; i < parts.length; i++) {
        String key = parts[i];

        if (!(node instanceof ObjectNode)) {
            throw new IllegalArgumentException("Unable to override " + name + "; it's not a valid path.");
        }
        final ObjectNode obj = (ObjectNode) node;

        final String remainingPath = Joiner.on('.').join(Arrays.copyOfRange(parts, i, parts.length));
        if (obj.has(remainingPath) && !remainingPath.equals(key)) {
            if (obj.get(remainingPath).isValueNode()) {
                obj.put(remainingPath, value);
                return;
            }
        }

        JsonNode child;
        final boolean moreParts = i < parts.length - 1;

        if (key.matches(".+\\[\\d+\\]$")) {
            final int s = key.indexOf('[');
            final int index = Integer.parseInt(key.substring(s + 1, key.length() - 1));
            key = key.substring(0, s);
            child = obj.get(key);
            if (child == null) {
                throw new IllegalArgumentException(
                        "Unable to override " + name + "; node with index not found.");
            }
            if (!child.isArray()) {
                throw new IllegalArgumentException(
                        "Unable to override " + name + "; node with index is not an array.");
            } else if (index >= child.size()) {
                throw new ArrayIndexOutOfBoundsException(
                        "Unable to override " + name + "; index is greater than size of array.");
            }
            if (moreParts) {
                child = child.get(index);
                node = child;
            } else {
                ArrayNode array = (ArrayNode) child;
                array.set(index, TextNode.valueOf(value));
                return;
            }
        } else if (moreParts) {
            child = obj.get(key);
            if (child == null) {
                child = obj.objectNode();
                obj.put(key, child);
            }
            if (child.isArray()) {
                throw new IllegalArgumentException(
                        "Unable to override " + name + "; target is an array but no index specified");
            }
            node = child;
        }

        if (!moreParts) {
            if (node.get(key) != null && node.get(key).isArray()) {
                ArrayNode arrayNode = (ArrayNode) obj.get(key);
                arrayNode.removeAll();
                Pattern escapedComma = Pattern.compile("\\\\,");
                for (String val : Splitter.on(Pattern.compile("(?<!\\\\),")).trimResults().split(value)) {
                    arrayNode.add(escapedComma.matcher(val).replaceAll(","));
                }
            } else {
                obj.put(key, value);
            }
        }
    }
}

From source file:Matrix.java

/**
 * Set a submatrix./*ww  w.  j  ava  2  s . co m*/
 * 
 * @param r
 *            Array of row indices.
 * @param j0
 *            Initial column index
 * @param j1
 *            Final column index
 * @param X
 *            A(r(:),j0:j1)
 * @exception ArrayIndexOutOfBoundsException
 *                Submatrix indices
 */

public void setMatrix(int[] r, int j0, int j1, Matrix X) {
    try {
        for (int i = 0; i < r.length; i++) {
            for (int j = j0; j <= j1; j++) {
                A[r[i]][j] = X.get(i, j - j0);
            }
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        throw new ArrayIndexOutOfBoundsException("Submatrix indices");
    }
}