List of usage examples for java.lang IndexOutOfBoundsException IndexOutOfBoundsException
public IndexOutOfBoundsException()
From source file:com.replaymod.replaystudio.collection.PacketList.java
@Override public PacketData remove(int index) { if (index < 0 || index >= size) throw new IndexOutOfBoundsException(); PacketListIterator iter = listIterator(index); PacketData previous = iter.next();/*from w w w. j a va 2 s. c o m*/ iter.remove(); return previous; }
From source file:eu.stratosphere.types.StringValue.java
/** * Sets the value of the StringValue to a substring of the given value. * //from w w w . ja v a 2s .c o m * @param chars The new string value (as a character array). * @param offset The position to start the substring. * @param len The length of the substring. */ public void setValue(char[] chars, int offset, int len) { Validate.notNull(chars); if (offset < 0 || len < 0 || offset > chars.length - len) { throw new IndexOutOfBoundsException(); } ensureSize(len); System.arraycopy(chars, offset, this.value, 0, len); this.len = len; this.hashCode = 0; }
From source file:com.thoughtworks.go.config.merge.MergePipelineConfigs.java
public PipelineConfigs getPartWithIndex(int i) { if (i < 0) throw new IndexOutOfBoundsException(); int start = 0; for (PipelineConfigs part : this.parts) { int end = start + part.size(); if (i < end) return part; start = end;//from ww w . j ava 2 s . co m } throw new IndexOutOfBoundsException(); }
From source file:com.sawyer.advadapters.widget.NFJSONArrayAdapter.java
@Override public Object getItem(int position) { Object object = mObjects.opt(position); if (object == null) { //A pain but can't add throws to this overrided method if (position < 0 || position >= mObjects.length()) { throw new IndexOutOfBoundsException(); } else {//from ww w . j a v a 2s .c om throw new NullPointerException(); } } return object; }
From source file:eu.stratosphere.types.StringValue.java
/** * Sets the value of this <code>StringValue</code>, assuming that the binary data is ASCII coded. The n-th character of the * <code>StringValue</code> corresponds directly to the n-th byte in the given array after the offset. * /* w ww . j ava 2 s. c o m*/ * @param bytes The binary character data. * @param offset The offset in the array. * @param len The number of bytes to read from the array. */ public void setValueAscii(byte[] bytes, int offset, int len) { if (bytes == null) { throw new NullPointerException("Bytes must not be null"); } if (len < 0 | offset < 0 | offset > bytes.length - len) { throw new IndexOutOfBoundsException(); } ensureSize(len); this.len = len; this.hashCode = 0; final char[] chars = this.value; for (int i = 0, limit = offset + len; offset < limit; offset++, i++) { chars[i] = (char) (bytes[offset] & 0xff); } }
From source file:com.thoughtworks.go.config.merge.MergePipelineConfigs.java
public PipelineConfigs getPartWithIndexForInsert(int i) { if (i < 0) throw new IndexOutOfBoundsException(); int start = 0; for (PipelineConfigs part : this.parts) { int end = start + part.size(); if (i < end) return part; start = end;//from w w w .ja v a 2s. co m } return this.parts.get(this.parts.size() - 1); }
From source file:com.thoughtworks.go.config.merge.MergePipelineConfigs.java
@Override public PipelineConfig get(int i) { if (i < 0) throw new IndexOutOfBoundsException(); int start = 0; for (PipelineConfigs part : this.parts) { int end = start + part.size(); if (i < end) return part.get(i - start); start = end;/*www.j ava2 s .c o m*/ } throw new IndexOutOfBoundsException(); }
From source file:com.thoughtworks.go.config.merge.MergePipelineConfigs.java
@Override public PipelineConfig set(int i, PipelineConfig pipelineConfig) { if (i < 0) throw new IndexOutOfBoundsException(); int start = 0; for (PipelineConfigs part : this.parts) { int end = start + part.size(); if (i < end) { if (isEditable(part)) { return part.set(i - start, pipelineConfig); } else { throw bomb(String.format("Cannot edit pipeline %s", pipelineConfig.name())); }/*from ww w. ja va2 s.c o m*/ } start = end; } throw new IndexOutOfBoundsException(); }
From source file:ConcatReader.java
/** * Read characters into a portion of an array. This method will block until * some input is available, an I/O error occurs, or the end of all underlying * streams are reached./*from w w w .ja v a2s .c om*/ * <p> * If this class in not done accepting readers and the end of the last known * stream is reached, this method will block forever unless another thread * adds a reader or interrupts. * * @param cbuf Destination buffer * @param off Offset at which to start storing characters * @param len Maximum number of characters to read * @return The number of characters read, or -1 if the end of the stream has been reached * * @throws IOException - If an I/O error occurs * @throws NullPointerException - If the buffer is null. * @throws IndexOutOfBoundsException - if length or offset are not possible. * * @since ostermillerutils 1.04.00 */ @Override public int read(char[] cbuf, int off, int len) throws IOException { if (off < 0 || len < 0 || off + len > cbuf.length) throw new IndexOutOfBoundsException(); if (closed) throw new IOException("Reader closed"); int r = -1; while (r == -1) { Reader in = getCurrentReader(); if (in == null) { if (doneAddingReaders) return -1; try { Thread.sleep(100); } catch (InterruptedException iox) { throw new IOException("Interrupted"); } } else { r = in.read(cbuf, off, len); if (r == -1) advanceToNextReader(); } } return r; }
From source file:me.tatetian.hs.io.SamplableByteArrayOutputStream.java
/** * Write the bytes to byte array./*from w w w. ja va2 s. c om*/ * @param b the bytes to write * @param off The start offset * @param len The number of bytes to write */ @Override public void write(byte[] b, int off, int len) { if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) > b.length) || ((off + len) < 0)) { throw new IndexOutOfBoundsException(); } else if (len == 0) { return; } // synchronized (this) { int newcount = count + len; int remaining = len; int inBufferPos = count - filledBufferSum; while (remaining > 0) { int part = Math.min(remaining, currentBuffer.length - inBufferPos); System.arraycopy(b, off + len - remaining, currentBuffer, inBufferPos, part); remaining -= part; if (remaining > 0) { needNewBuffer(newcount); inBufferPos = 0; } } count = newcount; // Added by Hongliang Tian recordSize += len; // } }