static void checkNonnegative(int position) { if (position < 0) { throw new IndexOutOfBoundsException("position (" + position + ") must not be negative"); } }
@Override public E next() { try { return arr[index++]; } catch (IndexOutOfBoundsException e) { throw new NoSuchElementException(e.getMessage()); } } };
@Override public void skipBytes(int length) { int newReaderIndex = readerIndex + length; if (newReaderIndex > writerIndex) { throw new IndexOutOfBoundsException(); } readerIndex = newReaderIndex; }
@Override public void readerIndex(int readerIndex) { if (readerIndex < 0 || readerIndex > writerIndex) { throw new IndexOutOfBoundsException(); } this.readerIndex = readerIndex; }
@Override public void readerIndex(int readerIndex) { if (readerIndex < 0 || readerIndex > writerIndex) { throw new IndexOutOfBoundsException(); } this.readerIndex = readerIndex; }
@Override public void skipBytes(int length) { int newReaderIndex = readerIndex + length; if (newReaderIndex > writerIndex) { throw new IndexOutOfBoundsException(); } readerIndex = newReaderIndex; }
@Override public char charAt(int index) { if (index > pos) { throw new IndexOutOfBoundsException(); } return chars[index]; }
private void checkIndex(int index) { if (index >= size) { throw new IndexOutOfBoundsException(); } }
private ByteBuf checkIndex(int index) { if (index != 0) { throw new IndexOutOfBoundsException(); } return this; }
public final long get (int index) { if (index < 0 || index >= limit) { throw new IndexOutOfBoundsException(); } return backingArray[offset + index]; }
public FloatBuffer put (int index, float c) { if (index < 0 || index >= limit) { throw new IndexOutOfBoundsException(); } backingArray[offset + index] = c; return this; }
public void swap (int first, int second) { if (first >= size) throw new IndexOutOfBoundsException("first can't be >= size: " + first + " >= " + size); if (second >= size) throw new IndexOutOfBoundsException("second can't be >= size: " + second + " >= " + size); long[] items = this.items; long firstValue = items[first]; items[first] = items[second]; items[second] = firstValue; }
public void swap (int first, int second) { if (first >= size) throw new IndexOutOfBoundsException("first can't be >= size: " + first + " >= " + size); if (second >= size) throw new IndexOutOfBoundsException("second can't be >= size: " + second + " >= " + size); long[] items = this.items; long firstValue = items[first]; items[first] = items[second]; items[second] = firstValue; }
public CharBuffer put (int index, char c) { if (index < 0 || index >= limit) { throw new IndexOutOfBoundsException(); } backingArray[offset + index] = c; return this; }
public DoubleBuffer put (int index, double c) { if (index < 0 || index >= limit) { throw new IndexOutOfBoundsException(); } backingArray[offset + index] = c; return this; }
public void swap (int first, int second) { if (first >= size) throw new IndexOutOfBoundsException("first can't be >= size: " + first + " >= " + size); if (second >= size) throw new IndexOutOfBoundsException("second can't be >= size: " + second + " >= " + size); T[] items = this.items; T firstValue = items[first]; items[first] = items[second]; items[second] = firstValue; }
private void assertIndex(boolean expression, String format, Object... args) { if (!expression) { String message = String.format(format, args); throw new IndexOutOfBoundsException(message); } }
@Override public void write(char[] cs, int off, int len) throws IOException { if ((off < 0) || (off > cs.length) || (len < 0) || ((off + len) > cs.length) || ((off + len) < 0)) { throw new IndexOutOfBoundsException(); } if (len > 0) { mBuffer.append(cs, off, len); } }
@Override public void write(char[] cs, int off, int len) throws IOException { if ((off < 0) || (off > cs.length) || (len < 0) || ((off + len) > cs.length) || ((off + len) < 0)) { throw new IndexOutOfBoundsException(); } if (len > 0) { mBuffer.append(cs, off, len); } }
/** * Copy {@code byteCount} bytes from the file at {@code pos} into to {@code source}. It is the * caller's responsibility to make sure there are sufficient bytes to read: if there aren't this * method throws an {@link EOFException}. */ public void read(long pos, Buffer sink, long byteCount) throws IOException { if (byteCount < 0) throw new IndexOutOfBoundsException(); while (byteCount > 0L) { long bytesRead = fileChannel.transferTo(pos, byteCount, sink); pos += bytesRead; byteCount -= bytesRead; } } }