List of usage examples for java.lang IndexOutOfBoundsException IndexOutOfBoundsException
public IndexOutOfBoundsException(int index)
From source file:com.actionbarsherlock.internal.view.MenuBuilder.java
@Override public MenuItemImpl findItem(int itemId) { for (MenuItemImpl item : this.mItems) { if (item.getItemId() == itemId) { return item; }/*from ww w . j a v a 2 s . c o m*/ } throw new IndexOutOfBoundsException("No item with id " + itemId); }
From source file:com.codelanx.codelanxlib.util.Reflections.java
/** * Returns a {@link StackTraceElement} of the direct caller of the current * method's context./*from w w w . j a v a 2 s . c o m*/ * * @since 0.1.0 * @version 0.1.0 * * @param offset The number of additional methods to look back * @return A {@link StackTraceElement} representing where the current * context was called from */ public static StackTraceElement getCaller(int offset) { Validate.isTrue(offset >= 0, "Offset must be a positive number"); StackTraceElement[] elems = Thread.currentThread().getStackTrace(); if (elems.length < 4 + offset) { //We shouldn't be able to get this high on the stack at theoritical offset 0 throw new IndexOutOfBoundsException("Offset too large for current stack"); } return elems[3 + offset]; }
From source file:ArraysX.java
/** * Duplicates the specified array.//w ww . jav a2 s .c om * * <p>The array could be an array of objects or primiitives. * * @param ary the array * @param jb the beginning index (included) * @param je the ending index (excluded) * @return an array duplicated from ary * @exception IllegalArgumentException if ary is not any array * @exception IndexOutOfBoundsException if out of bounds */ public static final Object duplicate(Object ary, int jb, int je) { int len = Array.getLength(ary); if (jb < 0 || je > len || jb > je) throw new IndexOutOfBoundsException(jb + " or " + je + " exceeds " + len); len = je - jb; Object dst = Array.newInstance(ary.getClass().getComponentType(), len); System.arraycopy(ary, jb, dst, 0, len); return dst; }
From source file:Polygon2D.java
/** * Constructs and initializes a <code>Polygon2D</code> from the specified * parameters./*from ww w . j a v a 2 s. c o m*/ * @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>Polygon2D</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 Polygon2D(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:net.sf.jasperreports.engine.base.ElementsBlockList.java
protected int blockIndex(int index) { if (index < 0) { throw new IndexOutOfBoundsException("index: " + index); }/*w w w .ja v a 2 s. co m*/ // see if the index falls in the lastIndex block if (lastIndex >= 0 && lastIndex < blockCount) { if (index >= offsets[lastIndex] && (lastIndex + 1 == blockCount || index < offsets[lastIndex + 1])) { return lastIndex; } } int blockIndex = Arrays.binarySearch(offsets, 0, blockCount, index); if (blockIndex < 0) { blockIndex = -blockIndex - 2; } // caching last index for fast serial access lastIndex = blockIndex; return blockIndex; }
From source file:com.netxforge.oss2.xml.event.EventReceipt.java
/** * /* w w w .j a v a 2 s.c o m*/ * * @param index * @param vUuid * @throws java.lang.IndexOutOfBoundsException if the index * given is outside the bounds of the collection */ public void setUuid(final int index, final java.lang.String vUuid) throws java.lang.IndexOutOfBoundsException { // check bounds for index if (index < 0 || index >= this._uuidList.size()) { throw new IndexOutOfBoundsException( "setUuid: Index value '" + index + "' not in range [0.." + (this._uuidList.size() - 1) + "]"); } this._uuidList.set(index, vUuid); }
From source file:edu.chalmers.dat255.audiobookplayer.model.Book.java
public void setSelectedTrackIndex(int index) { if (index < -1 || index > this.tracks.size() + 1) { throw new IndexOutOfBoundsException(TAG + " setSelectedTrackIndex with index out of bounds: " + index + ", list size: " + this.tracks.size()); }/*from w w w . ja va 2s . c o m*/ selectedTrackIndex = index; }
From source file:net.anidb.udp.UdpResponse.java
/** * Returns the entry on the given index. * @param index The index./*from www . j av a 2 s . c om*/ * @return The entry. * @throws IndexOutOfBoundsException If the index is out of bounds. */ public UdpResponseEntry getEntryAt(final int index) { if ((index < 0) || (index >= this.entries.size())) { throw new IndexOutOfBoundsException("Index is out of bounds. Lower " + "limit: 0; upper limit: " + (this.entries.size() - 1) + "; index: " + index); } return this.entries.elementAt(index); }
From source file:org.jfree.data.category.CategoryToPieDataset.java
/** * Returns the key at the specified index. * * @param index the item index (in the range <code>0</code> to * <code>getItemCount() - 1</code>). * * @return The key./*w w w . j ava 2 s . c o m*/ * * @throws IndexOutOfBoundsException if <code>index</code> is not in the * specified range. */ @Override public Comparable getKey(int index) { Comparable result = null; if (index < 0 || index >= getItemCount()) { // this includes the case where the underlying dataset is null throw new IndexOutOfBoundsException("Invalid 'index': " + index); } if (this.extract == TableOrder.BY_ROW) { result = this.source.getColumnKey(index); } else if (this.extract == TableOrder.BY_COLUMN) { result = this.source.getRowKey(index); } return result; }
From source file:LazyList.java
protected void removeRange(int from, int to) { if (from >= 0 && to <= m_size) { int length = m_size - to; if (length > 0) { System.arraycopy(m_array, to, m_array, from, length); }/* w w w. ja va 2 s .co m*/ m_size -= to - from; for (int i = m_size; i > to;) { m_array[--i] = null; } modCount++; } else { throw new IndexOutOfBoundsException("Range of " + from + "-" + to + " exceeds valid range 0-" + m_size); } }