本文整理了Java中java.lang.IndexOutOfBoundsException
类的一些代码示例,展示了IndexOutOfBoundsException
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IndexOutOfBoundsException
类的具体详情如下:
包路径:java.lang.IndexOutOfBoundsException
类名称:IndexOutOfBoundsException
[英]Thrown when a program attempts to access a value in an indexable collection using a value which is outside of the range of valid indices.
[中]当程序试图使用超出有效索引范围的值访问可索引集合中的值时引发。
代码示例来源:origin: google/guava
static void checkNonnegative(int position) {
if (position < 0) {
throw new IndexOutOfBoundsException("position (" + position + ") must not be negative");
}
}
代码示例来源:origin: skylot/jadx
@Override
public E next() {
try {
return arr[index++];
} catch (IndexOutOfBoundsException e) {
throw new NoSuchElementException(e.getMessage());
}
}
};
代码示例来源:origin: apache/incubator-dubbo
@Override
public void skipBytes(int length) {
int newReaderIndex = readerIndex + length;
if (newReaderIndex > writerIndex) {
throw new IndexOutOfBoundsException();
}
readerIndex = newReaderIndex;
}
代码示例来源:origin: apache/incubator-dubbo
@Override
public void readerIndex(int readerIndex) {
if (readerIndex < 0 || readerIndex > writerIndex) {
throw new IndexOutOfBoundsException();
}
this.readerIndex = readerIndex;
}
代码示例来源:origin: apache/incubator-dubbo
@Override
public void readerIndex(int readerIndex) {
if (readerIndex < 0 || readerIndex > writerIndex) {
throw new IndexOutOfBoundsException();
}
this.readerIndex = readerIndex;
}
代码示例来源:origin: apache/incubator-dubbo
@Override
public void skipBytes(int length) {
int newReaderIndex = readerIndex + length;
if (newReaderIndex > writerIndex) {
throw new IndexOutOfBoundsException();
}
readerIndex = newReaderIndex;
}
代码示例来源:origin: netty/netty
@Override
public char charAt(int index) {
if (index > pos) {
throw new IndexOutOfBoundsException();
}
return chars[index];
}
代码示例来源:origin: netty/netty
private void checkIndex(int index) {
if (index >= size) {
throw new IndexOutOfBoundsException();
}
}
代码示例来源:origin: netty/netty
private ByteBuf checkIndex(int index) {
if (index != 0) {
throw new IndexOutOfBoundsException();
}
return this;
}
代码示例来源:origin: libgdx/libgdx
public final long get (int index) {
if (index < 0 || index >= limit) {
throw new IndexOutOfBoundsException();
}
return backingArray[offset + index];
}
代码示例来源:origin: libgdx/libgdx
public FloatBuffer put (int index, float c) {
if (index < 0 || index >= limit) {
throw new IndexOutOfBoundsException();
}
backingArray[offset + index] = c;
return this;
}
代码示例来源:origin: libgdx/libgdx
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;
}
代码示例来源:origin: libgdx/libgdx
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;
}
代码示例来源:origin: libgdx/libgdx
public CharBuffer put (int index, char c) {
if (index < 0 || index >= limit) {
throw new IndexOutOfBoundsException();
}
backingArray[offset + index] = c;
return this;
}
代码示例来源:origin: libgdx/libgdx
public DoubleBuffer put (int index, double c) {
if (index < 0 || index >= limit) {
throw new IndexOutOfBoundsException();
}
backingArray[offset + index] = c;
return this;
}
代码示例来源:origin: libgdx/libgdx
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;
}
代码示例来源:origin: spring-projects/spring-framework
private void assertIndex(boolean expression, String format, Object... args) {
if (!expression) {
String message = String.format(format, args);
throw new IndexOutOfBoundsException(message);
}
}
代码示例来源:origin: apache/incubator-dubbo
@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);
}
}
代码示例来源:origin: apache/incubator-dubbo
@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);
}
}
代码示例来源:origin: square/okhttp
/**
* 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;
}
}
}
内容来源于网络,如有侵权,请联系作者删除!