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:org.apache.synapse.transport.utils.sslcert.pathvalidation.PathChecker.java

/**
 * @return the immediate issuer certificate of the current certificate which is being checked.
 *          This is tracked by the position variable
 *//*from   w ww.  ja  va  2 s .  com*/
private X509Certificate nextIssuer() {
    //get immediate issuer
    if (position > 0) {
        return certChainArray[position--];
    } else {
        throw new ArrayIndexOutOfBoundsException("Certificate Chain Index Out of Bounds");
    }
}

From source file:LongList.java

/**
 * Removes a value from this list/*from   w ww  .j  a  v a 2 s  .c o  m*/
 * 
 * @param index
 *            The index of the value to remove
 * @return The value that was removed
 */
public long remove(int index) {
    if (index < 0 || index >= theSize)
        throw new ArrayIndexOutOfBoundsException(index);
    long ret = theValue[index];
    for (int i = index; i < theSize - 1; i++)
        theValue[i] = theValue[i + 1];
    theSize--;
    return ret;
}

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

/**
 * Search only part of a list./*  w  w  w .ja  v a2  s  . c o m*/
 * 
 * @param a
 * @param fromIndex
 * @param toIndex
 * @param key
 * @param comp
 * 
 * @return found index
 */
static <E> int binarySearch(final List<E> a, final int fromIndex, final int toIndex, final E key,
        final Comparator<? super E> comp) {
    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 E midVal = a.get(mid);
        final int cmp = comp.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
}

From source file:org.openhie.openempi.util.BitArray.java

/**
 *  Returns the indexed bit in this BitArray.
 *//* w w w  .j  a va  2s . c o  m*/
public boolean get(int index) throws ArrayIndexOutOfBoundsException {
    if (index < 0 || index >= length) {
        throw new ArrayIndexOutOfBoundsException(Integer.toString(index));
    }

    return (repn[subscript(index)] & position(index)) != 0;
}

From source file:tilt.image.page.Page.java

/**
 * Convert an ArrayList of Integers to an int array
 * @param col the ArrayList of Integers/*from   www . j a  va2s . c o m*/
 * @param list the target int array
 * @throws Exception medianLineWidth
 */
private void listToIntArray(ArrayList col, int[] list) throws Exception {
    if (list.length != col.size())
        throw new ArrayIndexOutOfBoundsException("col not the same length as array");
    for (int j = 0; j < col.size(); j++) {
        Object obj = col.get(j);
        if (obj instanceof Integer)
            list[j] = ((Integer) col.get(j)).intValue();
        else
            throw new ClassCastException("object is not an Integer");
    }
}

From source file:microsoft.exchange.webservices.data.property.complex.ItemCollection.java

/**
 * Gets the item at the specified index.
 *
 * @param index The zero-based index of the item to get.
 * @return The item at the specified index.
 *//*from ww  w  . j  ava2  s. co  m*/
public TItem getItem(int index) {

    if (index < 0 || index >= this.getCount()) {
        throw new ArrayIndexOutOfBoundsException("index is out of range.");
    }
    return this.items.get(index);
}

From source file:org.openhie.openempi.util.BitArray.java

/**
 *  Sets the indexed bit in this BitArray.
 *///www  .ja v  a  2 s .c om
public void set(int index, boolean value) throws ArrayIndexOutOfBoundsException {
    if (index < 0 || index >= length) {
        throw new ArrayIndexOutOfBoundsException(Integer.toString(index));
    }
    int idx = subscript(index);
    int bit = position(index);

    if (value) {
        repn[idx] |= bit;
    } else {
        repn[idx] &= ~bit;
    }
}

From source file:com.shvet.poi.util.HexDump.java

/**
 * dump an array of bytes to a String/*from  w  w  w  .  j  a v a 2s. c  o m*/
 *
 * @param data   the byte array to be dumped
 * @param offset its offset, whatever that might mean
 * @param index  initial index into the byte array
 * @param length number of characters to output
 * @return output string
 * @throws ArrayIndexOutOfBoundsException if the index is
 *                                        outside the data array's bounds
 */

public static String dump(final byte[] data, final long offset, final int index, final int length) {
    if (data == null || data.length == 0) {
        return "No Data" + EOL;
    }

    int data_length = (length == Integer.MAX_VALUE || length < 0 || index + length < 0) ? data.length
            : Math.min(data.length, index + length);

    if ((index < 0) || (index >= data.length)) {
        String err = "illegal index: " + index + " into array of length " + data.length;
        throw new ArrayIndexOutOfBoundsException(err);
    }

    long display_offset = offset + index;
    StringBuilder buffer = new StringBuilder(74);

    for (int j = index; j < data_length; j += 16) {
        int chars_read = data_length - j;

        if (chars_read > 16) {
            chars_read = 16;
        }

        buffer.append(xpad(display_offset, 8, ""));
        for (int k = 0; k < 16; k++) {
            if (k < chars_read) {
                buffer.append(xpad(data[k + j], 2, " "));
            } else {
                buffer.append("   ");
            }
        }
        buffer.append(' ');
        for (int k = 0; k < chars_read; k++) {
            buffer.append(toAscii(data[k + j]));
        }
        buffer.append(EOL);
        display_offset += chars_read;
    }
    return buffer.toString();
}

From source file:ArrayMap.java

private static void put(Object array, Object element, int index) {
    try {//from ww w . ja v  a 2  s. co  m
        if (array instanceof Object[]) {
            try {
                ((Object[]) array)[index] = element;
            } catch (ArrayStoreException e) {
                throw new IllegalArgumentException(
                        e.getMessage() + ": " + (element == null ? "null" : element.getClass().getName())
                                + " into " + array.getClass().getName());
            }
        } else {
            try {
                Array.set(array, index, element);
            } catch (IllegalArgumentException e) {
                throw new IllegalArgumentException(
                        e.getMessage() + ": " + (element == null ? "null" : element.getClass().getName())
                                + " into " + array.getClass().getName(),
                        e);
            }
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        throw new ArrayIndexOutOfBoundsException(index + " into " + Array.getLength(array));
    }
}

From source file:DisplayModeModel.java

public Object getValueAt(int rowIndex, int colIndex) {
    DisplayMode dm = modes[rowIndex];
    switch (colIndex) {
    case DisplayModeTest.INDEX_WIDTH:
        return Integer.toString(dm.getWidth());
    case DisplayModeTest.INDEX_HEIGHT:
        return Integer.toString(dm.getHeight());
    case DisplayModeTest.INDEX_BITDEPTH: {
        int bitDepth = dm.getBitDepth();
        String ret;/*  w ww.  j a  v  a2s.c  o m*/
        if (bitDepth == DisplayMode.BIT_DEPTH_MULTI) {
            ret = "Multi";
        } else {
            ret = Integer.toString(bitDepth);
        }
        return ret;
    }
    case DisplayModeTest.INDEX_REFRESHRATE: {
        int refreshRate = dm.getRefreshRate();
        String ret;
        if (refreshRate == DisplayMode.REFRESH_RATE_UNKNOWN) {
            ret = "Unknown";
        } else {
            ret = Integer.toString(refreshRate);
        }
        return ret;
    }
    }
    throw new ArrayIndexOutOfBoundsException("Invalid column value");
}