List of usage examples for java.lang ArrayIndexOutOfBoundsException ArrayIndexOutOfBoundsException
public ArrayIndexOutOfBoundsException(int index)
From source file:IntStack.java
/** * Pop multiple values from the stack. The last value popped is the * one returned.//from w w w. ja v a 2s . c o m * * @param count number of values to pop from stack (must be strictly * positive) * @return value from top of stack * @exception ArrayIndexOutOfBoundsException on attempt to pop past end of * stack */ public int pop(int count) { if (count <= 0) { throw new IllegalArgumentException("Count must be greater than 0"); } else if (m_countPresent >= count) { m_countPresent -= count; return m_baseArray[m_countPresent]; } else { throw new ArrayIndexOutOfBoundsException("Attempt to pop past end of stack"); } }
From source file:org.novelang.common.tree.TreeTools.java
/** * Returns a copy of this {@code Tree} minus the child of given index. * @param parent non-null object that may implement {@link StorageTypeProvider}. * @param index a value between [0, {@link Tree#getChildCount()}[. * @return a non-null object./*from w w w . j a v a 2s. c om*/ * @throws ArrayIndexOutOfBoundsException */ public static <T extends Tree<T>> T replace(final T parent, final int index, final T newChild) throws ArrayIndexOutOfBoundsException { if (index < 0) { throw new ArrayIndexOutOfBoundsException("Negative index: " + index); } if (parent.getChildCount() < index) { throw new ArrayIndexOutOfBoundsException( "Cannot remove child at index " + index + " (child count: " + parent.getChildCount() + ")"); } final List<T> newChildList = Lists.newArrayListWithCapacity(parent.getChildCount()); for (int i = 0; i < parent.getChildCount(); i++) { if (i == index) { newChildList.add(i, newChild); } else { newChildList.add(i, parent.getChildAt(i)); } } return parent.adopt(newChildList); }
From source file:org.apache.hadoop.hbase.regionserver.idx.support.arrays.$.java
get(int index) { if (index >= size) { throw new ArrayIndexOutOfBoundsException("Attempted to access index " + index + " but array is " + size + " elements"); }/*from w w w . j a v a 2 s . co m*/ return values[index]; }
From source file:com.alvermont.terraj.fracplanet.geom.TriangleBufferArray.java
/** * Set a value in this triangle array// w w w. java2 s .c om * * @param index The index of the element to be set * @param vertex The vertex number to be set (0,1 or 2) * @param value The value to set this vertex to */ public void set(int index, int vertex, int value) { // first make sure there's room while (this.buffer.capacity() < (index * INTS_PER_ENTRY)) { resizeBuffer(); } if ((index + 1) >= (this.buffer.limit() / INTS_PER_ENTRY)) { this.buffer.limit((index + 1) * INTS_PER_ENTRY); } if (vertex > 2) { throw new ArrayIndexOutOfBoundsException("Illegal access to triangle vertex > 2: " + index); } this.buffer.put((index * INTS_PER_ENTRY) + vertex, value); }
From source file:com.examples.with.different.packagename.concolic.MathRuntimeException.java
/** * Constructs a new <code>ArrayIndexOutOfBoundsException</code> with specified formatted detail message. * Message formatting is delegated to {@link java.text.MessageFormat}. * @param pattern format specifier/*from ww w. j a va2s.c o m*/ * @param arguments format arguments * @return built exception */ public static ArrayIndexOutOfBoundsException createArrayIndexOutOfBoundsException(final String pattern, final Object... arguments) { return new ArrayIndexOutOfBoundsException(buildMessage(Locale.US, pattern, arguments)) { /** Serializable version identifier. */ private static final long serialVersionUID = -3394748305449283486L; /** {@inheritDoc} */ @Override public String getLocalizedMessage() { return buildMessage(Locale.getDefault(), pattern, arguments); } }; }
From source file:org.pentaho.chart.data.BaseChartTableModel.java
/** * Set the value of the data array.//w ww . j a v a2s. co m * * @param value The value to be set * @param row The row number to be used * @param col The col number to be used * @throws ArrayIndexOutOfBoundsException if the row or column number are out of bounds * @throws IllegalStateException if the data array is not initialized */ public void setValueAt(final Object value, final int row, final int col) throws ArrayIndexOutOfBoundsException, IllegalStateException { if (row > getRowCount() || row < 0) { throw new ArrayIndexOutOfBoundsException( Messages.getErrorString("ChartTableModel.ERROR_0004_ROW_NUM_OUT_OF_BOUNDS")); //$NON-NLS-1$ } else if (col > getColumnCount() || col < 0) { throw new ArrayIndexOutOfBoundsException( Messages.getErrorString("ChartTableModel.ERROR_0002_COLUMN_NUM_OUT_OF_BOUNDS")); //$NON-NLS-1$ } else if (null == data) { throw new IllegalStateException("Data array not initialized."); //$NON-NLS-1$ } data[row][col] = value; }
From source file:StringArray.java
/** * Remove some number of values from the end of the array. * * @param count number of values to be removed * @exception ArrayIndexOutOfBoundsException on attempt to remove more than * the count present//from ww w . j a v a2 s . c o m */ public void remove(int count) { int start = m_countPresent - count; if (start >= 0) { discardValues(start, m_countPresent); m_countPresent = start; } else { throw new ArrayIndexOutOfBoundsException("Attempt to remove too many values from array"); } }
From source file:mml.handler.scratch.ScratchVersionSet.java
public String getDocid() throws ArrayIndexOutOfBoundsException { if (this.list == null || this.list.length == 0) throw new ArrayIndexOutOfBoundsException("List is empty"); return this.list[0].getDocid(); }
From source file:IntStack.java
/** * Copy a value from the stack. This returns a value from within * the stack without modifying the stack. * * @param depth depth of value to be returned * @return value from stack//from w w w .j a v a 2 s . c om * @exception ArrayIndexOutOfBoundsException on attempt to peek past end of * stack */ public int peek(int depth) { if (m_countPresent > depth) { return m_baseArray[m_countPresent - depth - 1]; } else { throw new ArrayIndexOutOfBoundsException("Attempt to peek past end of stack"); } }
From source file:com.alvermont.terraj.fracplanet.geom.TriangleBufferArray.java
/** * Get a value from this triangle array//from ww w . j a v a 2s .c o m * * @param index The index of the element to be retrieved * @return The <code>Triangle</code> object at this index */ public Triangle get(int index) { if (index >= size()) { throw new ArrayIndexOutOfBoundsException( "Request for invalid triangle index: " + index + " max is: " + size()); } return new BufferedTriangle(index * INTS_PER_ENTRY); }