Example usage for java.lang IndexOutOfBoundsException IndexOutOfBoundsException

List of usage examples for java.lang IndexOutOfBoundsException IndexOutOfBoundsException

Introduction

In this page you can find the example usage for java.lang IndexOutOfBoundsException IndexOutOfBoundsException.

Prototype

public IndexOutOfBoundsException(int index) 

Source Link

Document

Constructs a new IndexOutOfBoundsException class with an argument indicating the illegal index.

Usage

From source file:com.netxforge.oss2.xml.event.Maskelement.java

/**
 * Method getMevalue.//from   w  w  w.  jav a  2 s .  c  o  m
 * 
 * @param index
 * @throws java.lang.IndexOutOfBoundsException if the index
 * given is outside the bounds of the collection
 * @return the value of the java.lang.String at the given index
 */
public java.lang.String getMevalue(final int index) throws java.lang.IndexOutOfBoundsException {
    // check bounds for index
    if (index < 0 || index >= this._mevalueList.size()) {
        throw new IndexOutOfBoundsException("getMevalue: Index value '" + index + "' not in range [0.."
                + (this._mevalueList.size() - 1) + "]");
    }

    return (java.lang.String) _mevalueList.get(index);
}

From source file:CircularQueue.java

private void checkIndex(int idx) {
    if (idx < 0 || idx >= size()) {
        throw new IndexOutOfBoundsException(String.valueOf(idx));
    }/*from   ww w . j  av  a 2 s. com*/
}

From source file:jason.jml.alist.AbstractLinkedList.java

private/*@ helper @*//*@ nullable @*/Node getNode(int index, boolean endMarkerAllowed)
        throws IndexOutOfBoundsException {

    if (index < 0)
        throw new IndexOutOfBoundsException(
                "Couldn't get the node: " + "index (" + index + ") less than zero.");

    if (!endMarkerAllowed && index == this.size)
        throw new IndexOutOfBoundsException(
                "Couldn't get the node: " + "index (" + index + ") is the size of the list.");

    if (index > this.size)
        throw new IndexOutOfBoundsException("Couldn't get the node: " + "index (" + index
                + ") greater than the size of the " + "list (" + size + ").");

    Node node;/*from   www. j  a v a 2  s.c o  m*/
    if (index < (this.size / 2)) {

        node = this.header.next;
        for (int currentIndex = 0; currentIndex < index; currentIndex++) {
            node = node.next;
        }

    } else {

        node = this.header;
        for (int currentIndex = size; currentIndex > index; currentIndex--) {
            node = node.previous;
            currentIndex = currentIndex - 1;
        }
    }
    return node;
}

From source file:bulat.diet.helper_couch.common.data.ExampleExpandableDataProvider.java

@Override
public DayTimeGroupData getGroupItem(int groupPosition) {
    if (groupPosition < 0 || groupPosition >= getGroupCount()) {
        throw new IndexOutOfBoundsException("groupPosition = " + groupPosition);
    }/*ww  w  .  j  a v a  2s.c o  m*/

    return mData.get(groupPosition).first;
}

From source file:net.ontopia.topicmaps.nav2.taglibs.TMvalue.TologQueryTag.java

/**
 * INTERNAL: Wraps a QueryResultIF instance in a suitable
 * MapCollection implementation.//from  w  ww . j  ava2  s  .c o m
 */
protected Collection getMapCollection(QueryResultIF result) {

    if (select != null) {
        int index = result.getIndex(select);
        if (index < 0)
            throw new IndexOutOfBoundsException("No query result column named '" + select + "'");

        List list = new ArrayList();
        while (result.next())
            list.add(result.getValue(index));
        result.close();
        return list;
    }

    if (result instanceof net.ontopia.topicmaps.query.impl.basic.QueryResult)
        // BASIC
        return net.ontopia.topicmaps.query.impl.basic.QueryResultWrappers.getWrapper(result);
    else {
        // FIXME: Should pass collection size if available.
        return IteratorUtils.toList(new QueryResultIterator(result));
    }
}

From source file:org.t2framework.commons.util.ArrayMap.java

 public final Entry<K, V> getEntry(final int index) {
   if (index >= size) {
      throw new IndexOutOfBoundsException("Index:" + index + ", Size:"
            + size);/*  w  ww.  ja v  a2  s . co m*/
   }
   return listTable[index];
}

From source file:io.horizondb.io.buffers.CompositeBuffer.java

/**
 * {@inheritDoc}/*from   w w  w.  ja va  2s.  c  om*/
 */
@Override
public CompositeBuffer getBytes(int index, byte[] array, int offset, int length) {

    if (index < 0 || (index + length) > this.capacity) {

        @SuppressWarnings("boxing")
        String msg = format("Index: %d Length: %d Expected: 0 <= index and index + length < capacity(%d)",
                index, length, this.capacity);

        throw new IndexOutOfBoundsException(msg);
    }

    int position = index + this.offset;
    int bufferOffset = 0;
    int off = offset;
    int remaining = length;

    for (int i = 0, m = this.buffers.size(); i < m; i++) {

        ReadableBuffer buffer = this.buffers.get(i);

        if (position < bufferOffset + buffer.readableBytes()) {

            int len = Math.min(buffer.readableBytes() - (position - bufferOffset), remaining);

            buffer.getBytes(position - bufferOffset, array, off, len);

            remaining -= len;

            if (remaining == 0) {
                break;
            }

            position += len;
            off += len;
        }

        bufferOffset += buffer.readableBytes();
    }

    return this;
}

From source file:engagement1.tests.bzip2.BZip2CompressorInputStream.java

@Override
public int read(final byte[] dest, final int offs, final int len) throws IOException {
    if (offs < 0) {
        throw new IndexOutOfBoundsException("offs(" + offs + ") < 0.");
    }// w ww  .  jav  a  2  s.co  m
    if (len < 0) {
        throw new IndexOutOfBoundsException("len(" + len + ") < 0.");
    }
    if (offs + len > dest.length) {
        throw new IndexOutOfBoundsException(
                "offs(" + offs + ") + len(" + len + ") > dest.length(" + dest.length + ").");
    }
    if (this.in == null) {
        throw new IOException("stream closed");
    }

    final int hi = offs + len;
    int destOffs = offs;
    for (int b; (destOffs < hi) && ((b = read0()) >= 0);) {
        dest[destOffs++] = (byte) b;
    }

    int c = (destOffs == offs) ? -1 : (destOffs - offs);
    count(c);
    return c;
}

From source file:me.cybermaxke.merchants.v16r3.SMerchant.java

@Override
public MerchantOffer getOfferAt(int index) {
    if (index < 0 || index >= this.offers.size()) {
        throw new IndexOutOfBoundsException(
                "index (" + index + ") out of bounds min (0) and max (" + this.offers.size() + ")");
    }/*from ww w.j ava  2  s.co  m*/

    return (MerchantOffer) this.offers.get(index);
}

From source file:io.lightlink.dao.LightLinkDAO.java

public <T> T queryForSingleRow(Object params, Class<T> aClass) {
    try {/* w  ww  . j a v  a  2 s  .  c om*/
        Map<String, Object> data = doExecute(params);

        List<Map<String, Object>> resultSet = (List<Map<String, Object>>) data.get("resultSet");
        if (resultSet != null) {
            return ((List<T>) new BeanMapper(aClass, getFieldNames(resultSet)).convert(resultSet)).get(0);
        } else
            throw new IndexOutOfBoundsException("No resultSet returned");

    } catch (Exception e) {
        LOG.error(e.toString(), e);
        throw new RuntimeException(e.toString(), e);
    }
}