当前位置: 首页>>代码示例>>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;未经允许,请勿转载。