Example usage for com.google.common.base Preconditions checkPositionIndexes

List of usage examples for com.google.common.base Preconditions checkPositionIndexes

Introduction

In this page you can find the example usage for com.google.common.base Preconditions checkPositionIndexes.

Prototype

public static void checkPositionIndexes(int start, int end, int size) 

Source Link

Document

Ensures that start and end specify a valid positions in an array, list or string of size size , and are in order.

Usage

From source file:org.apache.kudu.util.Slice.java

/**
 * Gets a byte at the specified absolute {@code index} in this buffer.
 *
 * @throws IndexOutOfBoundsException if the specified {@code index} is less than {@code 0} or
 * {@code index + 1} is greater than {@code this.capacity}
 *//*from  www  . j a v  a 2  s  .  c  o  m*/
public byte getByte(int index) {
    Preconditions.checkPositionIndexes(index, index + 1, this.length);
    index += offset;
    return data[index];
}

From source file:io.druid.segment.writeout.ByteBufferWriteOutBytes.java

@Override
public void write(byte[] b, int off, int len) {
    Preconditions.checkPositionIndexes(off, off + len, b.length);
    write0(b, off, len);//from   w  ww  .  ja va2  s .co  m
}

From source file:net.automatalib.commons.util.array.RichArray.java

public RichArray(T[] contents, int start, int end) {
    Preconditions.checkPositionIndexes(start, end, contents.length);
    this.contents = contents;
    this.start = start;
    this.length = end - start;
}

From source file:ome.util.checksum.HashCode.java

/**
 * 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}
 *//*from  w ww.  ja v a 2 s  .  c  o m*/
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;
}

From source file:org.iq80.leveldb.util.Slice.java

/**
 * Gets a 16-bit short integer at the specified absolute {@code index} in
 * this slice.//from w ww.  j  a  va  2  s .  co m
 *
 * @throws IndexOutOfBoundsException if the specified {@code index} is less than {@code 0} or
 * {@code index + 2} is greater than {@code this.capacity}
 */
public short getShort(int index) {
    Preconditions.checkPositionIndexes(index, index + SIZE_OF_SHORT, this.length);
    index += offset;
    return (short) (data[index] & 0xFF | data[index + 1] << 8);
}

From source file:org.apache.kudu.util.Slice.java

/**
 * Gets a 16-bit short integer at the specified absolute {@code index} in
 * this slice.//from   w  w  w.ja v  a  2s.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 short getShort(int index) {
    Preconditions.checkPositionIndexes(index, index + Shorts.BYTES, this.length);
    index += offset;
    return (short) (data[index] & 0xFF | data[index + 1] << 8);
}

From source file:com.facebook.presto.block.snappy.SnappyBlock.java

@Override
public Block getRegion(int positionOffset, int length) {
    Preconditions.checkPositionIndexes(positionOffset, positionOffset + length, positionCount);
    return cursor().getRegionAndAdvance(length);
}

From source file:org.iq80.leveldb.util.Slice.java

/**
 * Gets a 32-bit integer at the specified absolute {@code index} in
 * this buffer. /*w  w w.j a  va2s  .co  m*/
 *
 * @throws IndexOutOfBoundsException if the specified {@code index} is less than {@code 0} or
 * {@code index + 4} is greater than {@code this.capacity}
 */
public int getInt(int index) {
    Preconditions.checkPositionIndexes(index, index + SIZE_OF_INT, this.length);
    index += offset;
    return (data[index] & 0xff) | (data[index + 1] & 0xff) << 8 | (data[index + 2] & 0xff) << 16
            | (data[index + 3] & 0xff) << 24;
}

From source file:org.apache.kudu.util.Slice.java

/**
 * Gets a 32-bit integer at the specified absolute {@code index} in
 * this buffer./*w w  w.  j a  v a2  s  .  co  m*/
 *
 * @throws IndexOutOfBoundsException if the specified {@code index} is less than {@code 0} or
 * {@code index + 4} is greater than {@code this.capacity}
 */
public int getInt(int index) {
    Preconditions.checkPositionIndexes(index, index + Ints.BYTES, this.length);
    index += offset;
    return (data[index] & 0xff) | (data[index + 1] & 0xff) << 8 | (data[index + 2] & 0xff) << 16
            | (data[index + 3] & 0xff) << 24;
}

From source file:net.automatalib.commons.util.array.RichArray.java

public void setAll(int startInclusive, int endExclusive, T value) {
    Preconditions.checkPositionIndexes(startInclusive, endExclusive, length);
    int end = start + endExclusive;
    for (int i = start + startInclusive; i < end; i++) {
        contents[i] = value;//from ww w.ja  v a  2  s  . c om
    }
}