List of usage examples for com.google.common.base Preconditions checkPositionIndexes
public static void checkPositionIndexes(int start, int end, int size)
From source file:org.apache.kudu.util.Slice.java
/** * Transfers the specified source array's data to this buffer starting at * the specified absolute {@code index}. * * @throws IndexOutOfBoundsException if the specified {@code index} is less than {@code 0}, * if the specified {@code srcIndex} is less than {@code 0}, * if {@code index + length} is greater than * {@code this.capacity}, or// ww w . ja v a 2 s. co m * if {@code srcIndex + length} is greater than {@code src.length} */ public void setBytes(int index, byte[] source, int sourceIndex, int length) { Preconditions.checkPositionIndexes(index, index + length, this.length); Preconditions.checkPositionIndexes(sourceIndex, sourceIndex + length, source.length); index += offset; System.arraycopy(source, sourceIndex, data, index, length); }
From source file:net.automatalib.commons.util.array.RichArray.java
public Spliterator<T> spliterator(int startInclusive, int endExclusive) { Preconditions.checkPositionIndexes(startInclusive, endExclusive, length); return Arrays.spliterator(contents, start + startInclusive, start + endExclusive); }
From source file:net.automatalib.commons.util.array.RichArray.java
public RichArray<T> copyFrom(T[] source, int sourceOfs, int destOfs, int len) { // source being checked by System.arraycopy Preconditions.checkPositionIndexes(destOfs, destOfs + len, length); System.arraycopy(source, sourceOfs, contents, start + destOfs, len); return this; }
From source file:org.apache.kudu.util.Slice.java
/** * Transfers the specified source buffer's data to this buffer starting at * the specified absolute {@code index} until the source buffer's position * reaches its limit.//from ww w . j a va 2 s . c o m * * @throws IndexOutOfBoundsException if the specified {@code index} is less than {@code 0} or * if {@code index + src.remaining()} is greater than * {@code this.capacity} */ public void setBytes(int index, ByteBuffer source) { Preconditions.checkPositionIndexes(index, index + source.remaining(), this.length); index += offset; source.get(data, index, source.remaining()); }
From source file:net.automatalib.commons.util.array.RichArray.java
public RichArray<T> copyInto(int sourceOfs, Object[] dest, int destOfs, int len) { Preconditions.checkPositionIndexes(sourceOfs, sourceOfs + len, length); // dest being checked by System.arraycopy System.arraycopy(contents, start + sourceOfs, dest, destOfs, len); return this; }
From source file:net.automatalib.commons.util.array.RichArray.java
public void parallelSort(int startInclusive, int endExclusive, Comparator<? super T> cmp) { Preconditions.checkPositionIndexes(startInclusive, endExclusive, length); Arrays.parallelSort(contents, start + startInclusive, start + endExclusive, cmp); }
From source file:org.apache.kudu.util.Slice.java
/** * Transfers the content of the specified source stream to this buffer * starting at the specified absolute {@code index}. * * @param length the number of bytes to transfer * @return the actual number of bytes read in from the specified channel. * {@code -1} if the specified channel is closed. * @throws IndexOutOfBoundsException if the specified {@code index} is less than {@code 0} or * if {@code index + length} is greater than {@code this.capacity} * @throws java.io.IOException if the specified stream threw an exception during I/O *//*from w w w . j av a 2 s . co m*/ public int setBytes(int index, InputStream in, int length) throws IOException { Preconditions.checkPositionIndexes(index, index + length, this.length); index += offset; int readBytes = 0; do { int localReadBytes = in.read(data, index, length); if (localReadBytes < 0) { if (readBytes == 0) { return -1; } else { break; } } readBytes += localReadBytes; index += localReadBytes; length -= localReadBytes; } while (length > 0); return readBytes; }
From source file:net.automatalib.commons.util.array.RichArray.java
@SuppressWarnings("unchecked") public void parallelSort(int startInclusive, int endExclusive) { Preconditions.checkPositionIndexes(startInclusive, endExclusive, length); Arrays.parallelSort(contents, start + startInclusive, start + endExclusive, (x, y) -> ((Comparable<T>) x).compareTo(y)); }
From source file:net.automatalib.commons.util.array.RichArray.java
public void parallelPrefix(int startInclusive, int endExclusive, BinaryOperator<T> op) { Preconditions.checkPositionIndexes(startInclusive, endExclusive, length); Arrays.parallelPrefix(contents, start + startInclusive, start + endExclusive, op); }
From source file:net.automatalib.commons.util.array.RichArray.java
public int binarySearch(int startInclusive, int endExclusive, T key, Comparator<? super T> cmp) { Preconditions.checkPositionIndexes(startInclusive, endExclusive, length); int result = Arrays.binarySearch(contents, start + startInclusive, start + endExclusive, key, cmp); if (result != -1) { result -= start;/*from w w w . jav a2s. c o m*/ } return result; }