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.iq80.leveldb.util.Slice.java
/** * Gets a 64-bit long integer at the specified absolute {@code index} in * this buffer. //w w w. j ava2s . c o m * * @throws IndexOutOfBoundsException if the specified {@code index} is less than {@code 0} or * {@code index + 8} is greater than {@code this.capacity} */ public long getLong(int index) { Preconditions.checkPositionIndexes(index, index + SIZE_OF_LONG, this.length); index += offset; return ((long) data[index] & 0xff) | ((long) data[index + 1] & 0xff) << 8 | ((long) data[index + 2] & 0xff) << 16 | ((long) data[index + 3] & 0xff) << 24 | ((long) data[index + 4] & 0xff) << 32 | ((long) data[index + 5] & 0xff) << 40 | ((long) data[index + 6] & 0xff) << 48 | ((long) data[index + 7] & 0xff) << 56; }
From source file:org.apache.kudu.util.Slice.java
/** * Gets a 64-bit long integer at the specified absolute {@code index} in * this buffer./*from w w w . j a v a 2s. c o m*/ * * @throws IndexOutOfBoundsException if the specified {@code index} is less than {@code 0} or * {@code index + 8} is greater than {@code this.capacity} */ public long getLong(int index) { Preconditions.checkPositionIndexes(index, index + Longs.BYTES, this.length); index += offset; return ((long) data[index] & 0xff) | ((long) data[index + 1] & 0xff) << 8 | ((long) data[index + 2] & 0xff) << 16 | ((long) data[index + 3] & 0xff) << 24 | ((long) data[index + 4] & 0xff) << 32 | ((long) data[index + 5] & 0xff) << 40 | ((long) data[index + 6] & 0xff) << 48 | ((long) data[index + 7] & 0xff) << 56; }
From source file:net.automatalib.commons.util.array.RichArray.java
public void setAll(int startInclusive, int endExclusive, IntFunction<? extends T> generator) { Preconditions.checkPositionIndexes(startInclusive, endExclusive, length); Objects.requireNonNull(generator); for (int i = start + startInclusive, j = startInclusive; j < endExclusive; i++, j++) { contents[i] = generator.apply(j); }//from w w w.ja va2s . c o m }
From source file:net.automatalib.commons.util.array.RichArray.java
public void setAll(int startInclusive, int endExclusive, Supplier<? extends T> supplier) { Preconditions.checkPositionIndexes(startInclusive, endExclusive, length); Objects.requireNonNull(supplier); int end = start + endExclusive; for (int i = start + startInclusive; i < end; i++) { contents[i] = supplier.get();/*from w ww. ja va 2 s. c om*/ } }
From source file:org.apache.kudu.util.Slice.java
/** * Transfers this buffer's data to the specified destination starting at * the specified absolute {@code index}. * * @param destinationIndex the first index of the destination * @param length the number of bytes to transfer * @throws IndexOutOfBoundsException if the specified {@code index} is less than {@code 0}, * if the specified {@code dstIndex} is less than {@code 0}, * if {@code index + length} is greater than * {@code this.capacity}, or/* ww w. j av a 2 s. c om*/ * if {@code dstIndex + length} is greater than * {@code dst.length} */ public void getBytes(int index, byte[] destination, int destinationIndex, int length) { Preconditions.checkPositionIndexes(index, index + length, this.length); Preconditions.checkPositionIndexes(destinationIndex, destinationIndex + length, destination.length); index += offset; System.arraycopy(data, index, destination, destinationIndex, length); }
From source file:net.automatalib.commons.util.array.RichArray.java
public boolean contentEquals(Object[] array, int start, int end) { Preconditions.checkPositionIndexes(start, end, array.length); int alength = end - start; if (alength != length) { return false; }/* www.j a va 2 s . c om*/ for (int i = this.start, j = start; j < end; i++, j++) { if (!Objects.equals(contents[i], array[j])) { return false; } } return true; }
From source file:net.automatalib.commons.util.array.RichArray.java
public boolean contentDeepEquals(Object[] array, int start, int end) { Preconditions.checkPositionIndexes(start, end, array.length); int alength = end - start; if (alength != length) { return false; }//from w w w.ja v a2 s . c o m for (int i = this.start, j = start; j < end; i++, j++) { if (!Objects.deepEquals(contents[i], array[j])) { return false; } } return true; }
From source file:org.apache.kudu.util.Slice.java
/** * Transfers this buffer's data to the specified stream starting at the * specified absolute {@code index}./* w w w . j ava 2 s .c o m*/ * * @param length the number of bytes to transfer * @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 */ public void getBytes(int index, OutputStream out, int length) throws IOException { Preconditions.checkPositionIndexes(index, index + length, this.length); index += offset; out.write(data, index, length); }
From source file:org.apache.kudu.util.Slice.java
/** * Transfers this buffer's data to the specified channel starting at the * specified absolute {@code index}./*from ww w. j a v a 2s . c om*/ * * @param length the maximum number of bytes to transfer * @return the actual number of bytes written out to the specified channel * @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 channel threw an exception during I/O */ public int getBytes(int index, GatheringByteChannel out, int length) throws IOException { Preconditions.checkPositionIndexes(index, index + length, this.length); index += offset; return out.write(ByteBuffer.wrap(data, index, length)); }
From source file:org.iq80.leveldb.util.Slice.java
/** * Sets the specified 16-bit short integer at the specified absolute * {@code index} in this buffer. The 16 high-order bits of the specified * value are ignored./*from w w w . j a v a 2 s.c o m*/ * * @throws IndexOutOfBoundsException if the specified {@code index} is less than {@code 0} or * {@code index + 2} is greater than {@code this.capacity} */ public void setShort(int index, int value) { Preconditions.checkPositionIndexes(index, index + SIZE_OF_SHORT, this.length); index += offset; data[index] = (byte) (value); data[index + 1] = (byte) (value >>> 8); }