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

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

Introduction

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

Prototype

public static void checkArgument(boolean expression) 

Source Link

Document

Ensures the truth of an expression involving one or more parameters to the calling method.

Usage

From source file:ch.poiuqwer.saitek.fip4j.Button.java

public static Button S(int i) {
    Preconditions.checkArgument(i >= 0 && i <= 6);
    return Button.valueOf("S" + i);
}

From source file:org.janusgraph.util.stats.NumberUtil.java

/**
 * Returns an integer X such that 2^X=value. Throws an exception
 * if value is not a power of 2.//from   ww  w . j a  v a  2 s. co  m
 *
 * @param value
 * @return
 */
public static int getPowerOf2(long value) {
    Preconditions.checkArgument(isPowerOf2(value));
    return Long.SIZE - (Long.numberOfLeadingZeros(value) + 1);
}

From source file:io.druid.segment.IntListUtils.java

public static IntList fromTo(int from, int to) {
    Preconditions.checkArgument(from <= to);
    return new RangeIntList(from, to);
}

From source file:org.trancecode.seq.EventQueues.java

public static void checkValidIdentifier(final String identifier) {
    Preconditions.checkArgument(identifier.matches("[\\w\\.]+"));
}

From source file:com.google.template.soy.types.ast.UnionTypeNode.java

public static UnionTypeNode create(Iterable<TypeNode> candidates) {
    ImmutableList<TypeNode> candidateList = ImmutableList.copyOf(candidates);
    Preconditions.checkArgument(candidateList.size() > 1);
    return new AutoValue_UnionTypeNode(
            candidateList.get(0).sourceLocation().extend(Iterables.getLast(candidateList).sourceLocation()),
            candidateList);//from   w  ww  .  jav a2 s. com
}

From source file:com.icosilune.fn.nodes.Connection.java

public static Connection create(AbstractNode inNode, AbstractNode outNode, String inSocketName,
        String outSocketName) {/*from  w ww . jav  a 2 s.  c o  m*/

    Socket inSocket = inNode.getInputSockets().get(inSocketName);
    Socket outSocket = outNode.getOutputSockets().get(outSocketName);

    Preconditions.checkNotNull(inSocket, "node %s does not contain input socket %s", inNode, inSocketName);
    Preconditions.checkNotNull(outSocket, "node %s does not contain input socket %s", outNode, outSocketName);
    Preconditions.checkArgument(inSocket.getSocketType() == Socket.SocketType.INPUT);
    Preconditions.checkArgument(outSocket.getSocketType() == Socket.SocketType.OUTPUT);
    Preconditions.checkArgument(inSocket.getType().isAssignableFrom(outSocket.getType()));

    return new AutoValue_Connection(inNode, outNode, inSocket, outSocket);
}

From source file:com.facebook.buck.zip.JarEntryContainer.java

static JarEntryContainer of(Path source) {
    Preconditions.checkArgument(source.isAbsolute());

    if (Files.isDirectory(source)) {
        return new DirectoryJarEntryContainer(source);
    } else if (Files.isRegularFile(source)) {
        // Assume a zip or jar file.
        return new ZipFileJarEntryContainer(source);
    } else {//from w  w w  .  j  a va 2 s  .  c o m
        throw new IllegalStateException("Must be a file or directory: " + source);
    }
}

From source file:com.palantir.lock.AtlasRowLockDescriptor.java

/** Returns a {@code LockDescriptor} instance for the given table and row. */
public static LockDescriptor of(String tableName, byte[] rowName) {
    Preconditions.checkArgument(!Strings.isNullOrEmpty(tableName));
    Preconditions.checkNotNull(rowName);
    byte[] tableBytes = tableName.getBytes();
    byte[] bytes = new byte[tableBytes.length + 1 + rowName.length];
    System.arraycopy(tableBytes, 0, bytes, 0, tableBytes.length);
    System.arraycopy(rowName, 0, bytes, tableBytes.length + 1, rowName.length);
    return new LockDescriptor(bytes);
}

From source file:org.terasology.rendering.animation.TimeModifiers.java

/**
 * Always returns the same constant value
 * @param constant the constant value/*from w  w w .  ja  v a 2  s  . co  m*/
 * @return a mapping function
 */
public static TimeModifier constant(float constant) {
    Preconditions.checkArgument(constant >= 0 && constant <= 1);
    return v -> constant;
}

From source file:de.hybris.platform.commercefacades.catalog.PageOption.java

public static PageOption createForPageNumberAndPageSize(final int currentPage, final int pageSize) {
    Preconditions.checkArgument(currentPage >= 0);
    Preconditions.checkArgument(pageSize > 0);
    if (pageSize == Integer.MAX_VALUE) {
        return new PageOption(currentPage, pageSize, false);
    } else {//from w  w  w.  j a  va  2 s . c om
        return new PageOption(currentPage, pageSize, true);
    }

}