/** * Fill given array with zeros at the specified position. * @param b * @param offset * @param length */ public static void zero(byte[] b, int offset, int length) { checkPositionIndex(offset, b.length, "offset"); checkArgument(length > 0, "length must be greater than 0"); checkPositionIndex(offset + length, b.length, "offset + length"); Arrays.fill(b, offset, offset + length, (byte) 0); }
/** * 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); }
/** * Fill given array with random bytes at the specified position. * @param b * @param offset * @param length */ public static void random(byte[] b, int offset, int length) { checkPositionIndex(offset, b.length, "offset"); checkArgument(length > 0, "length must be greater than 0"); checkPositionIndex(offset + length, b.length, "offset + length"); byte[] buf = new byte[length]; RNG.nextBytes(buf); System.arraycopy(buf, 0, b, offset, length); }
/** * Constructs an iterator across a sequence of the given size with the given * initial position. That is, the first call to {@link #nextIndex()} will * return {@code position}, and the first call to {@link #next()} will return * the element at that index, if available. Calls to {@link #previous()} can * retrieve the preceding {@code position} elements. * * @throws IndexOutOfBoundsException if {@code position} is negative or is * greater than {@code size} * @throws IllegalArgumentException if {@code size} is negative */ protected AbstractIndexedListIterator(int size, int position) { checkPositionIndex(position, size); this.size = size; this.position = position; }
@Override public int indexIn(CharSequence sequence, int start) { int length = sequence.length(); checkPositionIndex(start, length); return (start == length) ? -1 : start; }
@Override public int indexIn(CharSequence sequence, int start) { int length = sequence.length(); checkPositionIndex(start, length); return -1; }
@Override public void add(int index, V element) { checkPositionIndex(index, 0); throw new IllegalArgumentException("Key does not satisfy predicate: " + key); }
/** * Fill given array with zeros at the specified position. * @param b * @param offset * @param length */ public static void zero(byte[] b, int offset, int length) { checkPositionIndex(offset, b.length, "offset"); checkArgument(length > 0, "length must be greater than 0"); checkPositionIndex(offset + length, b.length, "offset + length"); Arrays.fill(b, offset, offset + length, (byte) 0); }
/** * Fill given array with zeros at the specified position. * @param b * @param offset * @param length */ public static void zero(byte[] b, int offset, int length) { checkPositionIndex(offset, b.length, "offset"); checkArgument(length > 0, "length must be greater than 0"); checkPositionIndex(offset + length, b.length, "offset + length"); Arrays.fill(b, offset, offset + length, (byte) 0); }
/** * Fill given array with random bytes at the specified position. * @param b * @param offset * @param length */ public static void random(byte[] b, int offset, int length) { checkPositionIndex(offset, b.length, "offset"); checkArgument(length > 0, "length must be greater than 0"); checkPositionIndex(offset + length, b.length, "offset + length"); byte[] buf = new byte[length]; RNG.nextBytes(buf); System.arraycopy(buf, 0, b, offset, length); }
/** * Returns a new {@link ByteArrayDataInput} instance to read from the {@code bytes} array, * starting at the given position. * * @throws IndexOutOfBoundsException if {@code start} is negative or greater than the length of * the array */ public static ByteArrayDataInput newDataInput(byte[] bytes, int start) { checkPositionIndex(start, bytes.length); return newDataInput(new ByteArrayInputStream(bytes, start, bytes.length - start)); }
/** * Fill given array with random bytes at the specified position. * @param b * @param offset * @param length */ public static void random(byte[] b, int offset, int length) { checkPositionIndex(offset, b.length, "offset"); checkArgument(length > 0, "length must be greater than 0"); checkPositionIndex(offset + length, b.length, "offset + length"); byte[] buf = new byte[length]; RNG.nextBytes(buf); System.arraycopy(buf, 0, b, offset, length); }
private int reversePosition(int index) { int size = size(); checkPositionIndex(index, size); return size - index; }
/** * Ensures that {@code index} specifies a valid <i>position</i> in an array, list or string of * size {@code size}. A position index may range from zero to {@code size}, inclusive. * * @param index a user-supplied index identifying a position in an array, list or string * @param size the size of that array, list or string * @return the value of {@code index} * @throws IndexOutOfBoundsException if {@code index} is negative or is greater than {@code size} * @throws IllegalArgumentException if {@code size} is negative */ @CanIgnoreReturnValue public static int checkPositionIndex(int index, int size) { return checkPositionIndex(index, size, "index"); }
@CanIgnoreReturnValue @Override public boolean addAll(int index, Collection<? extends V> elements) { checkNotNull(elements); checkPositionIndex(index, 0); throw new IllegalArgumentException("Key does not satisfy predicate: " + key); }
/** * Returns the index of the first matching character in a character sequence, starting from a * given position, or {@code -1} if no character matches after that position. * * <p>The default implementation iterates over the sequence in forward order, beginning at {@code * start}, calling {@link #matches} for each character. * * @param sequence the character sequence to examine * @param start the first index to examine; must be nonnegative and no greater than {@code * sequence.length()} * @return the index of the first matching character, guaranteed to be no less than {@code start}, * or {@code -1} if no character matches * @throws IndexOutOfBoundsException if start is negative or greater than {@code * sequence.length()} */ public int indexIn(CharSequence sequence, int start) { int length = sequence.length(); checkPositionIndex(start, length); for (int i = start; i < length; i++) { if (matches(sequence.charAt(i))) { return i; } } return -1; }
checkPositionIndex(n, entryArray.length); if (n == 0) { return (RegularImmutableMap<K, V>) EMPTY;
static <K, V> RegularImmutableBiMap<K, V> fromEntryArray(int n, Entry<K, V>[] entryArray) { checkPositionIndex(n, entryArray.length); int tableSize = Hashing.closedTableSize(n, MAX_LOAD_FACTOR); int mask = tableSize - 1;
@CanIgnoreReturnValue MoveDesc<E> removeAt(int index) { checkPositionIndex(index, size); modCount++; size--;