下面列出了java.util.Objects#checkIndex ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public long getValue(byte[] b, int offset, int size) {
Objects.checkFromIndexSize(offset, size, b.length);
Objects.checkIndex(size, Long.BYTES + 1);
long val = 0;
for (int i = 0; i < size; i++) {
val = (val << 8) | (b[offset + i] & 0xff);
}
return val;
}
@Override
public long getValue(byte[] b, int offset, int size) {
Objects.checkFromIndexSize(offset, size, b.length);
Objects.checkIndex(size, Long.BYTES + 1);
long val = 0;
for (int i = size - 1; i >= 0; i--) {
val = (val << 8) | (b[offset + i] & 0xff);
}
return val;
}
public void set(int index, T value) {
Objects.checkIndex(index, size);
final long offset = offset(ABASE, ASHIFT, index);
for (;;) {// like cas
final Object[] before = values;
unsafe().putOrderedObject(before, offset, value);
final Object[] after = values;
if (before == after) {
return;
}
}
}
/**
* 递增并获取该位置的值
*
* @param index
* @return
*/
public int incrementAndGet(int index) {
Objects.checkIndex(index, count);
unsafe().getAndAddInt(array, sumIndex, 1);
return unsafe().getAndAddInt(array, offset(index), 1) + 1;
}
@Override
long getStartPointer(int docID) {
Objects.checkIndex(docID, maxDoc);
long blockIndex = docs.binarySearch(0, numChunks, docID);
if (blockIndex < 0) {
blockIndex = -2 - blockIndex;
}
return startPointers.get(blockIndex);
}
public int xMinusY(int y) {
Objects.checkIndex(y, x);
return x - y;
}
@Override
public boolean get(int doc) {
Objects.checkIndex(doc, length);
return parent.get(doc+start);
}
@Override
public final char charAt(int index) {
Objects.checkIndex(index, termLength);
return termBuffer[index];
}
@SuppressWarnings("unchecked")
public T get(int index) {
Objects.checkIndex(index, size);
return (T) unsafe().getObjectVolatile(values, offset(ABASE, ASHIFT, index));
}
@Override
public E get(int index) {
Objects.checkIndex(index, size);
return array[index];
}
/**
* 增加并获取该位置的值
*
* @param index
* @param delta
* @return
*/
public int addAndGet(int index, int delta) {
Objects.checkIndex(index, count);
unsafe().getAndAddInt(array, sumIndex, delta);
return unsafe().getAndAddInt(array, offset(index), delta) + delta;
}
/**
* Get the min value for the given dimension
* @param dimension the dimension, always positive
* @return the decoded min value
*/
public float getMin(int dimension) {
Objects.checkIndex(dimension, type.pointDimensionCount()/2);
return decodeMin(((BytesRef)fieldsData).bytes, dimension);
}
/**
* Get the max value for the given dimension
* @param dimension the dimension, always positive
* @return the decoded max value
*/
public float getMax(int dimension) {
Objects.checkIndex(dimension, type.pointDimensionCount()/2);
return decodeMax(((BytesRef)fieldsData).bytes, dimension);
}
/**
* Get the min value for the given dimension
* @param dimension the dimension, always positive
* @return the decoded min value
*/
public int getMin(int dimension) {
Objects.checkIndex(dimension, type.pointDimensionCount()/2);
return decodeMin(((BytesRef)fieldsData).bytes, dimension);
}
/**
* Get the max value for the given dimension
* @param dimension the dimension, always positive
* @return the decoded max value
*/
public int getMax(int dimension) {
Objects.checkIndex(dimension, type.pointDimensionCount()/2);
return decodeMax(((BytesRef)fieldsData).bytes, dimension);
}
/**
* Get the max value for the given dimension
* @param dimension the dimension, always positive
* @return the decoded max value
*/
public double getMax(int dimension) {
Objects.checkIndex(dimension, type.pointDimensionCount()/2);
return decodeMax(((BytesRef)fieldsData).bytes, dimension);
}
/**
* 递增并获取该位置的值
*
* @param index
* @return
*/
public int incrementAndGet(int index) {
Objects.checkIndex(index, count);
return unsafe().getAndAddInt(array, offset(index), 1) + 1;
}
/**
* 增加并获取该位置的值
*
* @param index
* @param delta
* @return
*/
public int addAndGet(int index, int delta) {
Objects.checkIndex(index, count);
return unsafe().getAndAddInt(array, offset(index), delta) + delta;
}
/**
* 某个位置的值
*
* @param index
* @return
*/
public int get(int index) {
Objects.checkIndex(index, count);
return unsafe().getIntVolatile(array, offset(index));
}
/**
* 设置某位置的值
*
* @param index
* @param value
*/
public void set(int index, int value) {
Objects.checkIndex(index, count);
unsafe().putOrderedInt(array, offset(index), value);
}