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:net.sf.maltcms.common.charts.api.selection.category.CategoryMouseSelectionHandler.java

/**
 *
 * @param cme// ww  w  . j a va 2s .  c o m
 */
@Override
public void chartMouseMoved(ChartMouseEvent cme) {
    if (cme.getEntity() instanceof CategoryItemEntity) {
        CategoryItemEntity itemEntity = ((CategoryItemEntity) cme.getEntity());
        int seriesIndex = dataset.getRowIndex(itemEntity.getRowKey());
        int itemIndex = dataset.getColumnIndex(itemEntity.getColumnKey());
        if (seriesIndex == -1 || itemIndex == -1) {
            throw new ArrayIndexOutOfBoundsException("Could not locate series and item index for entity!");
        }
        selection = new CategorySelection(dataset, seriesIndex, itemIndex, XYSelection.Type.HOVER,
                dataset.getSource(seriesIndex), dataset.getTarget(seriesIndex, itemIndex),
                shapeFactory.createSelectionShape(itemEntity));
        selection.setName(provider.getName(selection));
        selection.setDisplayName(provider.getDisplayName(selection));
        selection.setShortDescription(provider.getShortDescription(selection));
        fireSelectionChange();
    } else {
        clear();
    }
}

From source file:org.novelang.common.tree.TreeTools.java

/**
 * Returns a copy of this {@code Tree} minus the child of given index.
 * @param tree a non-null object that may implement {@link StorageTypeProvider}.
 * @param index a value between [0, {@link Tree#getChildCount()}[.
 * @return a non-null object.//from ww w .j a  v a  2  s  .  com
 * @throws ArrayIndexOutOfBoundsException
 */
public static <T extends Tree<T>> T remove(final T tree, final int index)
        throws ArrayIndexOutOfBoundsException {
    Preconditions.checkArgument(index >= 0);

    if (tree.getChildCount() < index) {
        throw new ArrayIndexOutOfBoundsException(
                "Cannot remove child at index " + index + " (child count: " + tree.getChildCount() + ")");
    }

    final List<T> newChildList = Lists.newArrayListWithCapacity(tree.getChildCount() - 1);

    int keep = 0;
    for (int i = 0; i < tree.getChildCount(); i++) {
        if (i != index) {
            newChildList.add(keep++, tree.getChildAt(i));
        }
    }
    return tree.adopt(newChildList);
}

From source file:termint.gui.graphics.TilesImageBlock.java

/**
 * Assuming that the ImageData is a grid of images, each one (imageHeight * imageWidth),
 * extract and return the image at the given grid location.
 * @param x//www.j  a  v  a  2  s  .  co m
 * @param y
 * @return
 */
protected Image getIconAt(int x, int y) {
    if (x >= imageBlockColumns)
        throw new ArrayIndexOutOfBoundsException(
                "getIconAt(" + x + "," + y + "): x exceeds max val " + imageBlockColumns);
    Image i = new Image(display, imageWidth, imageHeight);
    GC g = new GC(i);
    try {
        g.drawImage(bigImage, x * imageWidth, y * imageHeight, imageWidth, imageHeight, 0, 0, imageHeight,
                imageWidth);
    } catch (Exception e) {
        throw new RuntimeException("Failed to draw image from " + x + "," + y, e);
    }
    g.dispose();
    return i;
}

From source file:org.openecomp.sdnc.sli.SliPluginUtils.SvcLogicContextList.java

private static int getCtxListIndex(String key, String prefix, int list_size) {
    int index = getCtxListIndex(key, prefix);
    if (index >= list_size) {
        throw new IllegalArgumentException(
                "Context memory list \"" + prefix + "[]\" contains an index >= the size of the list",
                new ArrayIndexOutOfBoundsException(
                        "index \"" + index + "\" is outside the bounds of the context memory list \"" + prefix
                                + "[]. List Length = " + list_size));
    } else if (index < 0) {
        throw new IllegalArgumentException("Context memory list \"" + prefix + "[]\" contains a negative index",
                new NegativeArraySizeException("index \"" + index + "\" of context memory list is negative"));
    }/*from  ww  w .  jav  a 2 s  .com*/

    return index;
}

From source file:org.frameworkset.spi.remote.RPCMessage.java

/**
 * Set the internal buffer to point to a subset of a given buffer
 * //from ww  w .j  av  a  2  s . c o  m
 * @param b
 *            The reference to a given buffer. If null, we'll reset the
 *            buffer to null
 * @param offset
 *            The initial position
 * @param length
 *            The number of bytes
 */
final public void setBuffer(byte[] b, int offset, int length) {
    buf = b;
    if (buf != null) {
        if (offset < 0 || offset > buf.length)
            throw new ArrayIndexOutOfBoundsException(offset);
        if ((offset + length) > buf.length)
            throw new ArrayIndexOutOfBoundsException((offset + length));
        this.offset = offset;
        this.length = length;
    } else {
        this.offset = this.length = 0;
    }
}

From source file:org.jcurl.math.CurveCombined.java

/**
 * Search only part of an array. Could be more general operating with
 * {@link Comparable} and {@link Object}s.
 * /*from w  ww  .j  a  v a  2s  .  co  m*/
 * @param a
 * @param fromIndex
 * @param toIndex
 * @param key
 * 
 * @return found index
 */
static <V extends R1RNFunction> int binarySearch(final List<Entry<Double, V>> a, int fromIndex, int toIndex,
        final double key) {
    if (false) {
        if (fromIndex > toIndex)
            throw new IllegalArgumentException("fromIndex(" + fromIndex + ") > toIndex(" + toIndex + ")");
        if (fromIndex < 0)
            throw new ArrayIndexOutOfBoundsException(fromIndex);
        if (toIndex > a.size())
            throw new ArrayIndexOutOfBoundsException(toIndex);

        int low = fromIndex;
        int high = toIndex - 1;
        while (low <= high) {
            final int mid = low + high >>> 1;
            final double midVal = a.get(mid).getKey().doubleValue();
            final int cmp = Double.compare(midVal, key);
            if (cmp < 0)
                low = mid + 1;
            else if (cmp > 0)
                high = mid - 1;
            else
                return mid; // done
        }
        return -(low + 1); // no such key
    } else {
        double fromKey = a.get(fromIndex).getKey().doubleValue();
        double toKey = a.get(toIndex).getKey().doubleValue();
        for (;;) {
            if (key == fromKey)
                return fromIndex;
            if (key == toKey)
                return toIndex;
            final int midIndex = (toIndex + fromIndex) / 2;
            final double midKey = a.get(midIndex).getKey().doubleValue();
            if (key == midKey)
                return midIndex;
            if (fromIndex + 1 >= toIndex) {
                if (fromKey < key && key < toKey)
                    return -1 - toIndex;
                return -1;
            }
            if (key < midKey) {
                toIndex = midIndex;
                toKey = midKey;
                continue;
            } else if (key > midKey) {
                fromIndex = midIndex;
                fromKey = midKey;
                continue;
            }
        }
    }
}

From source file:CharBuf.java

/**
 * Adjust the characters in the array to make room for an insertion or
 * replacement. Depending on the relative sizes of the range being
 * replaced and the range being inserted, this may move characters past
 * the start of the replacement range up or down in the array.
 *
 * @param from index number of first character to be replaced
 * @param to index number past last character to be replaced
 * @param length length of character range being inserted
 *///w ww  .ja  v a 2 s  .c  om
protected void adjust(int from, int to, int length) {
    if (from >= 0 && to < size && from <= to) {
        int change = from + length - to;
        if (change > 0) {
            ensureCapacity(size + change);
        }
        if (to < size) {
            System.arraycopy(buf, to, buf, to + change, size - to);
            size += change;
        }
    } else {
        throw new ArrayIndexOutOfBoundsException("Invalid remove range");
    }
}

From source file:org.anarres.lzo.hadoop.codec.LzoDecompressor.java

@Override
public void setInput(byte[] b, int off, int len) {
    if (b == null)
        throw new NullPointerException();
    if (off < 0 || len < 0 || off > b.length - len)
        throw new ArrayIndexOutOfBoundsException(
                "Illegal range in buffer: Buffer length=" + b.length + ", offset=" + off + ", length=" + len);
    if (!needsInput())
        throw new IllegalStateException(
                "I don't need input: pos=" + outputBufferPos + "; len=" + outputBufferLen);
    // logState("Before setInput");
    // LOG.info("Decompressing " + len + " bytes at " + off);
    outputBufferLen.value = outputBuffer.length;
    // try {/* w ww.ja v a  2  s  .co m*/
    try {
        outputBufferPos = 0;
        int code = decompressor.decompress(b, off, len, outputBuffer, outputBufferPos, outputBufferLen);
        if (code != LzoTransformer.LZO_E_OK) {
            logState("LZO error: " + code);
            // FileUtils.writeByteArrayToFile(new File("bytes.out"), Arrays.copyOfRange(b, off, off + len));
            throw new IllegalArgumentException(decompressor.toErrorString(code));
        }
    } catch (IndexOutOfBoundsException e) {
        logState("IndexOutOfBoundsException: " + e);
        // FileUtils.writeByteArrayToFile(new File("bytes.out"), Arrays.copyOfRange(b, off, off + len));
        throw e;
    }
    // } catch (IOException _e) {
    // throw new RuntimeException(_e);
    // }
    // LOG.info(len + " -> " + outputBufferLen);
    // logState("After setInput");
}

From source file:org.apache.hadoop.hbase.replication.regionserver.ReplicationSink.java

/**
 * Replicate this array of entries directly into the local cluster using the native client. Only
 * operates against raw protobuf type saving on a conversion from pb to pojo.
 * @param entries// ww  w  .  j  ava 2  s. c  om
 * @param cells
 * @throws IOException
 */
public void replicateEntries(List<WALEntry> entries, final CellScanner cells) throws IOException {
    if (entries.isEmpty())
        return;
    if (cells == null)
        throw new NullPointerException("TODO: Add handling of null CellScanner");
    // Very simple optimization where we batch sequences of rows going
    // to the same table.
    try {
        long totalReplicated = 0;
        // Map of table => list of Rows, grouped by cluster id, we only want to flushCommits once per
        // invocation of this method per table and cluster id.
        Map<TableName, Map<List<UUID>, List<Row>>> rowMap = new TreeMap<TableName, Map<List<UUID>, List<Row>>>();
        for (WALEntry entry : entries) {
            TableName table = TableName.valueOf(entry.getKey().getTableName().toByteArray());
            Cell previousCell = null;
            Mutation m = null;
            int count = entry.getAssociatedCellCount();
            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 (isNewRowOrType(previousCell, cell)) {
                    // Create new mutation
                    m = CellUtil.isDelete(cell)
                            ? new Delete(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength())
                            : new Put(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength());
                    List<UUID> clusterIds = new ArrayList<UUID>();
                    for (HBaseProtos.UUID clusterId : entry.getKey().getClusterIdsList()) {
                        clusterIds.add(toUUID(clusterId));
                    }
                    m.setClusterIds(clusterIds);
                    addToHashMultiMap(rowMap, table, clusterIds, m);
                }
                if (CellUtil.isDelete(cell)) {
                    ((Delete) m).addDeleteMarker(KeyValueUtil.ensureKeyValue(cell));
                } else {
                    ((Put) m).add(KeyValueUtil.ensureKeyValue(cell));
                }
                previousCell = cell;
            }
            totalReplicated++;
        }
        for (Entry<TableName, Map<List<UUID>, List<Row>>> entry : rowMap.entrySet()) {
            batch(entry.getKey(), entry.getValue().values());
        }
        int size = entries.size();
        this.metrics.setAgeOfLastAppliedOp(entries.get(size - 1).getKey().getWriteTime());
        this.metrics.applyBatch(size);
        this.totalReplicatedEdits.addAndGet(totalReplicated);
    } catch (IOException ex) {
        LOG.error("Unable to accept edit because:", ex);
        throw ex;
    }
}

From source file:IntStack.java

/**
 * Pop a value from the stack.//from www.j  ava 2 s  . co m
 *
 * @return value from top of stack
 * @exception ArrayIndexOutOfBoundsException on attempt to pop empty stack
 */

public int pop() {
    if (m_countPresent > 0) {
        return m_baseArray[--m_countPresent];
    } else {
        throw new ArrayIndexOutOfBoundsException("Attempt to pop empty stack");
    }
}