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.flexive.shared.FxArrayUtils.java

/**
 * Get an integer element from a string array containing hexadecimal values
 *
 * @param array     the string array containing hexadecimal values
 * @param separator separator character//from  ww  w  .  java 2s  . c o m
 * @param index     index to get the element at
 * @return element  or <code>null</code> if not set
 */
public static Integer getHexIntElementAt(String array, char separator, int index) {
    try {
        if (StringUtils.isBlank(array))
            return null;
        if (index == 0) {
            final int sep = array.indexOf(separator);
            return evalIntValue(sep == -1 ? array : array.substring(0, sep), 16);
        }
        int curr = 0;
        int start = 0;
        int len = array.length();
        for (int i = 0; i < len; i++) {
            final char c = array.charAt(i);
            if (c == separator)
                curr++;
            if (curr == index) {
                int end = array.substring(start + 1).indexOf(separator);
                if (end == -1)
                    return evalIntValue(array.substring(start + 1), 16);
                else if (end == 0)
                    return null;
                return evalIntValue(array.substring(start + 1, start + end + 1), 16);
            }
            start++;
        }
    } catch (NumberFormatException e) {
        return null;
    }
    throw new ArrayIndexOutOfBoundsException("Index " + index + " is out of bounds for [" + array + "]");
}

From source file:Matrix.java

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

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

From source file:com.livinglogic.ul4.Color.java

int getItemIntegerUL4(int index) {
    switch (index) {
    case 0:/*from www.j  ava2s.  c  o  m*/
    case -4:
        return r;
    case 1:
    case -3:
        return g;
    case 2:
    case -2:
        return b;
    case 3:
    case -1:
        return a;
    default:
        throw new ArrayIndexOutOfBoundsException(index);
    }
}

From source file:org.apache.carbondata.core.util.CarbonUtil.java

/**
 * Checks that {@code fromIndex} and {@code toIndex} are in the range and
 * throws an exception if they aren't./*from ww w .  ja  v a 2 s.  co m*/
 */
private static void rangeCheck(int fromIndex, int toIndex) {
    if (fromIndex > toIndex) {
        throw new IllegalArgumentException("fromIndex(" + fromIndex + ") > toIndex(" + toIndex + ")");
    }
    if (fromIndex < 0) {
        throw new ArrayIndexOutOfBoundsException(fromIndex);
    }
}

From source file:com.enonic.cms.business.core.content.index.ContentIndexServiceImpl.java

private void verifyContent(ContentIndexEntity from, ContentIndexEntity to, int numValuesToCopy) {
    if (from == null && to == null) {
        throw new ArrayIndexOutOfBoundsException(
                "ContentIndexServiceImpl.copyValues(): Neither fromList nor toList contains " + numValuesToCopy
                        + " elements.");
    }/*from  w w  w . ja  v  a  2 s.c  om*/
    if (from == null) {
        throw new ArrayIndexOutOfBoundsException(
                "ContentIndexServiceImpl.copyValues(): fromList does not contain " + numValuesToCopy
                        + " elements.  Path in toList is:" + to.getPath());
    }
    if (to == null) {
        throw new ArrayIndexOutOfBoundsException(
                "ContentIndexServiceImpl.copyValues(): toList does not contain " + numValuesToCopy
                        + " elements.  Path in fromList is:" + from.getPath());
    }
}

From source file:ResizableDoubleArray.java

/**
 * Returns the element at the specified index
 * /*www .  j a  v a  2 s  . c  o m*/
 * @param index
 *          index to fetch a value from
 * @return value stored at the specified index
 * @throws ArrayIndexOutOfBoundsException
 *           if <code>index</code> is less than zero or is greater than
 *           <code>getNumElements() - 1</code>.
 */
public synchronized double getElement(int index) {
    if (index >= numElements) {
        String msg = "The index specified: " + index + " is larger than the current number of elements";
        throw new ArrayIndexOutOfBoundsException(msg);
    } else if (index >= 0) {
        return internalArray[startIndex + index];
    } else {
        String msg = "Elements cannot be retrieved from a negative array index";
        throw new ArrayIndexOutOfBoundsException(msg);
    }
}

From source file:edu.uci.ics.jung.graph.OrderedKAryTree.java

/**
 * Returns the child of <code>vertex</code> at position <code>index</code> 
 * in this tree, or <code>null</code> if it has no child at that position.
 * @param vertex the vertex to query/*from  ww  w  .  ja v  a2 s  . com*/
 * @return the child of <code>vertex</code> at position <code>index</code> 
 * in this tree, or <code>null</code> if it has no child at that position
 * @throws ArrayIndexOutOfBoundsException if <code>index</code> is not in 
 * the range {@code [0, order-1]}
 */
public V getChild(V vertex, int index) {
    if (index < 0 || index >= order)
        throw new ArrayIndexOutOfBoundsException(index + " is not in [0, order-1]");
    if (!containsVertex(vertex))
        return null;
    List<E> edges = vertex_data.get(vertex).child_edges;
    if (edges == null)
        return null;
    E edge = edges.get(index);
    return edge == null ? null : edge_vpairs.get(edge).getSecond();
}

From source file:languages.TabFile.java

public void addRow(String[] newValues) {
    if (newValues.length != getColumnCount()) {
        throw new ArrayIndexOutOfBoundsException(
                "The given values-array dows not match the column-count of this file. (The file has "
                        + this.getColumnCount() + " columns and you wanted to add " + newValues.length
                        + " columns)");
    }//from w w w. jav  a2s  .c o m

    values.add(new ArrayListWithSortableKey<>(Arrays.asList(newValues)));
}

From source file:org.apache.hadoop.hbase.wal.WALSplitUtil.java

/**
 * This function is used to construct mutations from a WALEntry. It also reconstructs WALKey &amp;
 * WALEdit from the passed in WALEntry//from w  w  w . j a  v a2 s. co m
 * @param entry
 * @param cells
 * @param logEntry pair of WALKey and WALEdit instance stores WALKey and WALEdit instances
 *          extracted from the passed in WALEntry.
 * @return list of Pair&lt;MutationType, Mutation&gt; to be replayed
 * @throws IOException
 */
public static List<MutationReplay> getMutationsFromWALEntry(AdminProtos.WALEntry entry, CellScanner cells,
        Pair<WALKey, WALEdit> logEntry, Durability durability) throws IOException {
    if (entry == null) {
        // return an empty array
        return Collections.emptyList();
    }

    long replaySeqId = (entry.getKey().hasOrigSequenceNumber()) ? entry.getKey().getOrigSequenceNumber()
            : entry.getKey().getLogSequenceNumber();
    int count = entry.getAssociatedCellCount();
    List<MutationReplay> mutations = new ArrayList<>();
    Cell previousCell = null;
    Mutation m = null;
    WALKeyImpl key = null;
    WALEdit val = null;
    if (logEntry != null) {
        val = new WALEdit();
    }

    for (int i = 0; i < count; i++) {
        // Throw index out of bounds if our cell count is off
        if (!cells.advance()) {
            throw new ArrayIndexOutOfBoundsException("Expected=" + count + ", index=" + i);
        }
        Cell cell = cells.current();
        if (val != null)
            val.add(cell);

        boolean isNewRowOrType = previousCell == null || previousCell.getTypeByte() != cell.getTypeByte()
                || !CellUtil.matchingRows(previousCell, cell);
        if (isNewRowOrType) {
            // Create new mutation
            if (CellUtil.isDelete(cell)) {
                m = new Delete(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength());
                // Deletes don't have nonces.
                mutations.add(new MutationReplay(ClientProtos.MutationProto.MutationType.DELETE, m,
                        HConstants.NO_NONCE, HConstants.NO_NONCE));
            } else {
                m = new Put(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength());
                // Puts might come from increment or append, thus we need nonces.
                long nonceGroup = entry.getKey().hasNonceGroup() ? entry.getKey().getNonceGroup()
                        : HConstants.NO_NONCE;
                long nonce = entry.getKey().hasNonce() ? entry.getKey().getNonce() : HConstants.NO_NONCE;
                mutations.add(
                        new MutationReplay(ClientProtos.MutationProto.MutationType.PUT, m, nonceGroup, nonce));
            }
        }
        if (CellUtil.isDelete(cell)) {
            ((Delete) m).add(cell);
        } else {
            ((Put) m).add(cell);
        }
        m.setDurability(durability);
        previousCell = cell;
    }

    // reconstruct WALKey
    if (logEntry != null) {
        org.apache.hadoop.hbase.shaded.protobuf.generated.WALProtos.WALKey walKeyProto = entry.getKey();
        List<UUID> clusterIds = new ArrayList<>(walKeyProto.getClusterIdsCount());
        for (HBaseProtos.UUID uuid : entry.getKey().getClusterIdsList()) {
            clusterIds.add(new UUID(uuid.getMostSigBits(), uuid.getLeastSigBits()));
        }
        key = new WALKeyImpl(walKeyProto.getEncodedRegionName().toByteArray(),
                TableName.valueOf(walKeyProto.getTableName().toByteArray()), replaySeqId,
                walKeyProto.getWriteTime(), clusterIds, walKeyProto.getNonceGroup(), walKeyProto.getNonce(),
                null);
        logEntry.setFirst(key);
        logEntry.setSecond(val);
    }

    return mutations;
}

From source file:br.com.blackhubos.eventozero.util.Framework.java

/**
 * Verifica igualdade do tamanho de duas strings.
 *
 * @param expected Primeira string//  w  w w.j  a  va 2 s.com
 * @param obtained Segunda string
 * @return Retorna 0 a 1, sendo = nada haver, 1 = total possivel igualdade
 */
public static float checkSameSize(final String expected, final String obtained) {
    if (expected.length() != obtained.length()) {
        throw new ArrayIndexOutOfBoundsException(
                "Failed to use checkSameSize() param; strings have no igual length.");
    }

    final int iLen = expected.length();
    int iDiffs = 0;

    for (int i = 0; i < iLen; i++) {
        if (expected.charAt(i) != obtained.charAt(i)) {
            iDiffs++;
        }
    }

    // 1 = igual, 0 = nada haver
    return 1f - ((float) iDiffs / iLen);
}