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.Event.java

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

    return _loggroupList.get(index);
}

From source file:de.codesourcery.jasm16.ast.ASTNode.java

private final ASTNode addChild(int index, ASTNode node, boolean mergeTextRegion) {
    if (node == null) {
        throw new IllegalArgumentException("node must not be NULL.");
    }/* w w w.jav  a2  s  . c o m*/

    // all nodes must accept this
    if (!(node instanceof UnparsedContentNode)) {
        assertSupportsChildNodes();
    }

    if (index == children.size()) {
        this.children.add(node);
    } else if (index < 0) {
        throw new IndexOutOfBoundsException("Invalid child index " + index);
    } else if (index < children.size()) {
        this.children.add(index, node);
    } else {
        throw new IndexOutOfBoundsException("Child index " + index + " is out of range, node " + this
                + " only has " + getChildCount() + " children.");
    }

    if (mergeTextRegion) {
        if (node.textRegionIncludingAllTokens != null) {
            if (this.textRegionIncludingAllTokens == null) {
                this.textRegionIncludingAllTokens = new TextRegion(node.textRegionIncludingAllTokens);
            } else {
                this.textRegionIncludingAllTokens.merge(node.textRegionIncludingAllTokens);
            }
        }
        mergeTextRegion(node.getTextRegion());
    }

    node.setParent(this);
    return node;
}

From source file:com.sm.store.hessian.HessianReader.java

public String readType() {
    int code = read();

    switch (code) {
    case 0x00://from   w w  w. j  ava 2s .c  o m
    case 0x01:
    case 0x02:
    case 0x03:
    case 0x04:
    case 0x05:
    case 0x06:
    case 0x07:
    case 0x08:
    case 0x09:
    case 0x0a:
    case 0x0b:
    case 0x0c:
    case 0x0d:
    case 0x0e:
    case 0x0f:

    case 0x10:
    case 0x11:
    case 0x12:
    case 0x13:
    case 0x14:
    case 0x15:
    case 0x16:
    case 0x17:
    case 0x18:
    case 0x19:
    case 0x1a:
    case 0x1b:
    case 0x1c:
    case 0x1d:
    case 0x1e:
    case 0x1f:

    case 0x30:
    case 0x31:
    case 0x32:
    case 0x33:
    case BC_STRING_CHUNK:
    case 'S': {
        String type = readString();
        if (_types == null)
            _types = new ArrayList();
        _types.add(type);
        return type;
    }

    default: {
        int ref = readInt();

        if (_types.size() <= ref)
            throw new IndexOutOfBoundsException(
                    "type ref #" + ref + " is greater than the number of valid types (" + _types.size() + ")");
        else
            return (String) _types.get(ref);
    } //default
    }// switch
}

From source file:Polygon2D.java

/**
 * Constructs and initializes a <code>Polyline2D</code> from the specified
 * parameters.//  w ww .jav a2s  . c  om
 * @param xpoints an array of <i>x</i> coordinates
 * @param ypoints an array of <i>y</i> coordinates
 * @param npoints the total number of points in the <code>Polyline2D</code>
 * @exception  NegativeArraySizeException if the value of
 *                       <code>npoints</code> is negative.
 * @exception  IndexOutOfBoundsException if <code>npoints</code> is
 *             greater than the length of <code>xpoints</code>
 *             or the length of <code>ypoints</code>.
 * @exception  NullPointerException if <code>xpoints</code> or
 *             <code>ypoints</code> is <code>null</code>.
 */
public Polyline2D(int[] xpoints, int[] ypoints, int npoints) {
    if (npoints > xpoints.length || npoints > ypoints.length) {
        throw new IndexOutOfBoundsException("npoints > xpoints.length || npoints > ypoints.length");
    }
    this.npoints = npoints;
    this.xpoints = new float[npoints];
    this.ypoints = new float[npoints];
    for (int i = 0; i < npoints; i++) {
        this.xpoints[i] = xpoints[i];
        this.ypoints[i] = ypoints[i];
    }
    calculatePath();
}

From source file:com.example.ray.firstapp.bottombar.BottomBar.java

/**
 * Creates a new Badge (for example, an indicator for unread messages) for a Tab at
 * the specified position./*from   w ww .  j ava  2s  .  co  m*/
 *
 * @param tabPosition     zero-based index for the tab.
 * @param backgroundColor a color for this badge, such as 0xFFFF0000.
 * @param initialCount    text displayed initially for this Badge.
 * @return a {@link BottomBarBadge} object.
 */
public BottomBarBadge makeBadgeForTabAt(int tabPosition, int backgroundColor, int initialCount) {
    if (mItems == null || mItems.length == 0) {
        throw new UnsupportedOperationException("You have no BottomBar Tabs set yet. "
                + "Please set them first before calling the makeBadgeForTabAt() method.");
    } else if (tabPosition > mItems.length - 1 || tabPosition < 0) {
        throw new IndexOutOfBoundsException("Cant make a Badge for Tab " + "index " + tabPosition
                + ". You have no BottomBar Tabs at that position.");
    }

    BottomBarBadge badge = new BottomBarBadge(mContext, mItemContainer.getChildAt(tabPosition),
            backgroundColor);
    badge.setTag(TAG_BADGE + tabPosition);
    badge.setCount(initialCount);

    if (mBadgeMap == null) {
        mBadgeMap = new HashMap<>();
    }

    mBadgeMap.put(tabPosition, badge.getTag());
    mOuterContainer.addView(badge);

    boolean canShow = true;

    if (mIsComingFromRestoredState && mBadgeStateMap != null && mBadgeStateMap.containsKey(tabPosition)) {
        canShow = mBadgeStateMap.get(tabPosition);
    }

    if (canShow && mCurrentTabPosition != tabPosition && initialCount != 0) {
        badge.show();
    } else {
        badge.hide();
    }

    return badge;
}

From source file:edu.chalmers.dat255.audiobookplayer.model.Bookshelf.java

/**
 * Convenience method. Checks if the index is valid for a book.
 * <p>/*from w  w  w  . j  a  v  a2  s.  c  om*/
 * USED FOR DEBUGGING.
 * 
 * @param index
 */
private void checkBookIndexLegal(int index) {
    if (!isLegalBookIndex(index)) {
        throw new IndexOutOfBoundsException("Book index is illegal: " + index);
    }
}

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

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

    return _operactionList.get(index);
}

From source file:com.orion.parser.UrT42Parser.java

/**
 * Return the <tt>Gametype</tt> matching the given code
 * /*from ww w.  j av  a 2s  .  co  m*/
 * @author Daniele Pantaleone
 * @param  code The <tt>Gametype</tt> code
 * @throws IndexOutOfBoundsException If the <tt>Gametype</tt> code is not mapped
 * @return The <tt>Gametype</tt> matching the given code
 **/
public Gametype getGametypeByCode(Integer code) throws IndexOutOfBoundsException {

    if (!gametypeByCode.containsKey(code))
        throw new IndexOutOfBoundsException("could not retrieve a Gametype using the given code: " + code);

    return gametypeByCode.get(code);
}

From source file:edu.chalmers.dat255.audiobookplayer.model.Bookshelf.java

/**
 * Convenience method. Checks if the index is valid for a track in a book.
 * <p>//  w ww. ja v  a 2s . c  om
 * USED FOR DEBUGGING.
 * 
 * @param bookIndex
 *            Book to check in.
 * @param trackIndex
 *            Track to check.
 */
private void checkTrackIndexLegalAt(int bookIndex, int trackIndex) {
    if (!isLegalTrackIndexAt(bookIndex, trackIndex)) {
        throw new IndexOutOfBoundsException(
                "Track or book index is illegal (book, track): " + bookIndex + ", " + trackIndex);
    }
}