本文整理汇总了Java中com.google.common.base.Preconditions.checkPositionIndexes方法的典型用法代码示例。如果您正苦于以下问题:Java Preconditions.checkPositionIndexes方法的具体用法?Java Preconditions.checkPositionIndexes怎么用?Java Preconditions.checkPositionIndexes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.base.Preconditions
的用法示例。
在下文中一共展示了Preconditions.checkPositionIndexes方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: forArray
import com.google.common.base.Preconditions; //导入方法依赖的package包/类
/**
* Returns a list iterator containing the elements in the specified range of
* {@code array} in order, starting at the specified index.
*
* <p>The {@code Iterable} equivalent of this method is {@code
* Arrays.asList(array).subList(offset, offset + length).listIterator(index)}.
*/
static <T> UnmodifiableListIterator<T> forArray(
final T[] array, final int offset, int length, int index) {
checkArgument(length >= 0);
int end = offset + length;
// Technically we should give a slightly more descriptive error on overflow
Preconditions.checkPositionIndexes(offset, end, array.length);
Preconditions.checkPositionIndex(index, length);
if (length == 0) {
return emptyListIterator();
}
return new ArrayItr<T>(array, offset, length, index);
}
示例2: subList
import com.google.common.base.Preconditions; //导入方法依赖的package包/类
@Override
public ImmutableList<E> subList(int fromIndex, int toIndex) {
Preconditions.checkPositionIndexes(fromIndex, toIndex, 1);
return (fromIndex == toIndex) ? ImmutableList.<E>of() : this;
}
示例3: subArray
import com.google.common.base.Preconditions; //导入方法依赖的package包/类
/**
* Returns a new immutable array containing the values in the specified range.
*
* <p><b>Performance note:</b> The returned array has the same full memory footprint as this one
* does (no actual copying is performed). To reduce memory usage, use {@code subArray(start,
* end).trimmed()}.
*/
public ImmutableIntArray subArray(int startIndex, int endIndex) {
Preconditions.checkPositionIndexes(startIndex, endIndex, length());
return startIndex == endIndex
? EMPTY
: new ImmutableIntArray(array, start + startIndex, start + endIndex);
}
示例4: writeBytesTo
import com.google.common.base.Preconditions; //导入方法依赖的package包/类
/**
* Copies bytes from this hash code into {@code dest}.
*
* @param dest the byte array into which the hash code will be written
* @param offset the start offset in the data
* @param maxLength the maximum number of bytes to write
* @return the number of bytes written to {@code dest}
* @throws IndexOutOfBoundsException if there is not enough room in {@code dest}
*/
@CanIgnoreReturnValue
public int writeBytesTo(byte[] dest, int offset, int maxLength) {
maxLength = Ints.min(maxLength, bits() / 8);
Preconditions.checkPositionIndexes(offset, offset + maxLength, dest.length);
writeBytesToImpl(dest, offset, maxLength);
return maxLength;
}