本文整理匯總了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;
}