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:FloatList.java

public void put(int index, float val) {
    if (index >= numElements) {
        throw new ArrayIndexOutOfBoundsException(index);
    }//  w ww  .j  av a  2 s. com
    data[index] = val;
}

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

@Override
public final T getChildAt(final int index) {
    if (index >= getChildCount()) {
        throw new ArrayIndexOutOfBoundsException(
                "Unsupported index: " + index + " (child count: " + getChildCount() + ")");
    }//from  ww w  . j  a va2s .  c o  m
    return children[index];
}

From source file:org.cloudfoundry.identity.uaa.rest.jdbc.JdbcPagingList.java

@Override
public E get(int index) {
    if (index >= size) {
        throw new ArrayIndexOutOfBoundsException(index);
    }/* w  ww  . ja v  a  2  s.  co m*/
    if (current == null || index - start >= pageSize || index < start) {
        current = parameterJdbcTemplate.query(limitSqlAdapter.getLimitSql(sql, index, pageSize), args, mapper);
        start = index;
    }
    return current.get(index - start);
}

From source file:org.apache.hama.util.BSPNetUtils.java

/**
 * Gets a new InetSocketAddress from the given peerName. peerName must contain
 * a colon to distinct between host and port.
 * //from ww  w .  j av  a 2  s . c o m
 * @param peerName the name as a String of the BSP peer to get the address
 *          from
 * @return the InetSocketAddress of the given BSP peer
 */
public static InetSocketAddress getAddress(String peerName) {
    int index = peerName.lastIndexOf(':');
    if (index <= 0 || index == peerName.length() - 1) {
        throw new ArrayIndexOutOfBoundsException("Invalid host and port information. "
                + "Peername must consist of atleast ONE \":\"! " + "Given peername was: " + peerName);
    }
    return new InetSocketAddress(peerName.substring(0, index), Integer.valueOf(peerName.substring(index + 1)));
}

From source file:ArrayUtils.java

/**
 * Inserts an element into the array--for primitive types
 * /* w ww  .ja va  2  s  .c om*/
 * @param anArray
 *            The array to insert into
 * @param anElement
 *            The element to insert
 * @param anIndex
 *            The index for the new element
 * @return The new array with all elements of <code>anArray</code>, but with
 *         <code>anElement</code> inserted at index <code>anIndex</code>
 */
public static Object addP(Object anArray, Object anElement, int anIndex) {
    Object ret;
    int length;
    if (anArray == null) {
        if (anIndex != 0)
            throw new ArrayIndexOutOfBoundsException("Cannot set " + anIndex + " element in a null array");
        ret = Array.newInstance(anElement.getClass(), 1);
        Array.set(ret, 0, anElement);
        return ret;
    } else {
        length = Array.getLength(anArray);
        ret = Array.newInstance(anArray.getClass().getComponentType(), length + 1);
    }
    System.arraycopy(anArray, 0, ret, 0, anIndex);
    put(ret, anElement, anIndex);
    System.arraycopy(anArray, anIndex, ret, anIndex + 1, length - anIndex);
    return ret;
}

From source file:com.evolveum.midpoint.web.component.util.AssignmentListDataProvider.java

@Override
public Iterator<? extends ContainerValueWrapper<AssignmentType>> internalIterator(long first, long count) {
    getAvailableData().clear();/*w w  w  .  j av a 2 s  .c  o m*/

    List<ContainerValueWrapper<AssignmentType>> list = searchThroughList();

    if (sortable && getSort() != null) {
        sort(list);
    }
    if (list != null) {
        for (long i = first; i < first + count; i++) {
            if (i < 0 || i >= list.size()) {
                throw new ArrayIndexOutOfBoundsException(
                        "Trying to get item on index " + i + " but list size is " + list.size());
            }
            getAvailableData().add(list.get(WebComponentUtil.safeLongToInteger(i)));
        }
    }

    return getAvailableData().iterator();
}

From source file:ArrayMap.java

/**
 * Inserts an element into the array/*from  ww  w. j ava 2  s.  co m*/
 * 
 * @param <T>
 *            The type of the object array
 * @param anArray
 *            The array to insert into
 * @param anElement
 *            The element to insert
 * @param anIndex
 *            The index for the new element
 * @return The new array with all elements of <code>anArray</code>, but with
 *         <code>anElement</code> inserted at index <code>anIndex</code>
 */
public static <T> T[] add(T[] anArray, T anElement, int anIndex) {
    T[] ret;
    if (anArray == null) {
        if (anIndex != 0)
            throw new ArrayIndexOutOfBoundsException("Cannot set " + anIndex + " element in a null array");
        ret = (T[]) Array.newInstance(anElement.getClass(), 1);
        ret[0] = anElement;
        return ret;
    } else
        ret = (T[]) Array.newInstance(anArray.getClass().getComponentType(), anArray.length + 1);
    System.arraycopy(anArray, 0, ret, 0, anIndex);
    put(ret, anElement, anIndex);
    System.arraycopy(anArray, anIndex, ret, anIndex + 1, anArray.length - anIndex);
    return ret;
}

From source file:MyStackDemo.java

public T pop() {
    if (hasNext()) {
        return data[--ix];
    }
    throw new ArrayIndexOutOfBoundsException(-1);
}

From source file:org.pentaho.reporting.engine.classic.core.layout.model.table.columns.AbstractColumnModel.java

public TableColumn getColumn(final int i) {
    buildColumns();/* w ww.j  a va  2 s .  c  o m*/
    if (i >= columns.length) {
        throw new ArrayIndexOutOfBoundsException(i);
    }
    return columns[i];
}

From source file:de.micromata.genome.gwiki.utils.IntArray.java

@Override
public Integer set(int index, Integer element) {
    if (index < 0 || index >= length) {
        throw new ArrayIndexOutOfBoundsException(index);
    }//from www .  j a v a 2s . c o  m
    int prev = getInt(index);
    data[index] = element;
    return prev;
}