當前位置: 首頁>>代碼示例>>Java>>正文


Java Preconditions.checkPositionIndexes方法代碼示例

本文整理匯總了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);
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:21,代碼來源:Iterators.java

示例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;
}
 
開發者ID:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:6,代碼來源:SingletonImmutableList.java

示例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);
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:14,代碼來源:ImmutableIntArray.java

示例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;
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:17,代碼來源:HashCode.java


注:本文中的com.google.common.base.Preconditions.checkPositionIndexes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。