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

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

Introduction

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

Prototype

public static int checkPositionIndex(int index, int size, @Nullable String desc) 

Source Link

Document

Ensures that index specifies a valid position in an array, list or string of size size .

Usage

From source file:org.jalphanode.cluster.SimpleMasterNodeElectionPolicy.java

/**
 * {@inheritDoc}//from   w  ww  .  j  a v  a  2  s  .co  m
 */
@Override
public NodeAddress elect(final List<NodeAddress> nodes) {
    Preconditions.checkNotNull(nodes, "nodes");
    Preconditions.checkPositionIndex(0, nodes.size(), "nodes");

    return nodes.get(0);
}

From source file:com.zaradai.primes.Guess.java

public int get(int index) {
    Preconditions.checkPositionIndex(index, rows(), "Invalid index");

    return rowData[index];
}

From source file:com.zaradai.kunzite.optimizer.model.OutputRow.java

public double getValue(int index) {
    Preconditions.checkPositionIndex(index, values.length, "Index is out of range");

    return values[index];
}

From source file:com.zaradai.kunzite.optimizer.model.InputRow.java

public int getValue(int index) {
    Preconditions.checkPositionIndex(index, values.length, "Index is out of range");
    return values[index];
}

From source file:com.zaradai.primes.Guess.java

public void set(int index, int rowValue) {
    Preconditions.checkPositionIndex(index, rows(), "Invalid index");

    rowData[index] = rowValue;//from  w  ww  . j  av a  2  s.  c  o  m
}

From source file:com.zaradai.kunzite.optimizer.model.OutputRow.java

public void setValue(int index, double value) {
    Preconditions.checkPositionIndex(index, values.length, "Index is out of range");

    values[index] = value;//w w w .  ja  va 2s.  com
}

From source file:com.zaradai.kunzite.optimizer.model.InputRow.java

public void setValue(int index, int value) {
    Preconditions.checkPositionIndex(index, values.length, "Index is out of range");
    values[index] = value;/*from w  w  w.jav  a  2s  .  co  m*/
}

From source file:com.android.builder.internal.packaging.sign.v2.ByteArrayDigestSource.java

@Override
public void feedDigests(long offset, int size, @NonNull MessageDigest[] digests) {
    Preconditions.checkArgument(offset >= 0, "offset: %s", offset);
    Preconditions.checkArgument(size >= 0, "size: %s", size);
    Preconditions.checkArgument(offset <= mBuf.length, "offset too large: %s", offset);
    int offsetInBuf = (int) offset;
    Preconditions.checkPositionIndex(offsetInBuf, mBuf.length, "offset out of range");
    int availableSize = mBuf.length - offsetInBuf;
    Preconditions.checkArgument(size <= availableSize, "offset (%s) + size (%s) > array length (%s)", offset,
            size, mBuf.length);//from  w  ww .  j  a v a 2s .c om

    for (MessageDigest md : digests) {
        md.update(mBuf, offsetInBuf, size);
    }
}

From source file:com.google.security.zynamics.binnavi.ZyGraph.Menus.Actions.CCopyLineAction.java

/**
 * Creates a new copy line action.// w  w  w  .  ja  va  2 s .  c  o  m
 *
 * @param node Node that provides the line to copy.
 * @param line Index of the line to copy.
 */
public CCopyLineAction(final NaviNode node, final int line) {
    super("Copy line to clipboard");

    m_node = Preconditions.checkNotNull(node, "IE02153: Node argument can not be null");
    Preconditions.checkPositionIndex(line, node.getRealizer().getNodeContent().getLineCount(),
            "IE02154: Line argument is out of bounds");
    m_line = line;
}

From source file:org.apache.hadoop.hdfs.server.namenode.AclFeature.java

/**
 * Get the entry at the specified position
 * @param pos Position of the entry to be obtained
 * @return integer representation of AclEntry
 * @throws IndexOutOfBoundsException if pos out of bound
 *//*from  ww  w  .j  av a 2  s.c om*/
int getEntryAt(int pos) {
    Preconditions.checkPositionIndex(pos, entries.length, "Invalid position for AclEntry");
    return entries[pos];
}