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

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

Introduction

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

Prototype

public static void checkState(boolean expression) 

Source Link

Document

Ensures the truth of an expression involving the state of the calling instance, but not involving any parameters to the calling method.

Usage

From source file:com.google.devtools.build.lib.rules.SkylarkApiProvider.java

/** Must be called once (and only once). */
public void init(TransitiveInfoCollection info) {
    Preconditions.checkState(this.info == null);
    this.info = Preconditions.checkNotNull(info);
}

From source file:com.twitter.common.collections.Bits.java

/**
 * Tests whether a bit is set in a long value.
 *
 * @param value The bit field to test./*from ww w  . j  a  v  a  2 s. c om*/
 * @param bit The index of the bit to test, where bit 0 is the LSB.
 * @return {@code true} if the bit is set, {@code false} otherwise.
 */
public static boolean isBitSet(long value, int bit) {
    Preconditions.checkState(bit >= LSB);
    Preconditions.checkState(bit <= LONG_MSB);
    long mask = 1L << bit;
    return (value & mask) != 0;
}

From source file:com.torodb.core.cursors.EmptyCursor.java

@Override
public E next() {
    Preconditions.checkState(!closed);
    throw new NoSuchElementException();
}

From source file:eu.project.ttc.test.func.ControlFiles.java

public static Path getControlDirectory(Lang lang, String corpus) {
    Path controlDirectory = CONTROL_DIRETCORY_PATH.resolve(corpus).resolve(lang.getName()).resolve("control");
    Preconditions.checkState(controlDirectory.toFile().exists());
    Preconditions.checkState(controlDirectory.toFile().isDirectory());
    return controlDirectory;

}

From source file:org.apache.impala.infra.tableflattener.SchemaUtil.java

static Field createField(String name, Schema schema, String doc, JsonNode defaultValue) {
    Preconditions.checkState(!schemaHasNesting(schema));
    if (schema.getType() == Type.UNION) {
        return new Field(name, Schema.createUnion(schema.getTypes()), doc, defaultValue);
    }//from w w  w  .  j  a v  a 2s . c om
    return createField(name, schema.getType(), doc, defaultValue);
}

From source file:model.utilities.stats.processes.LinearNonDynamicProcess.java

public LinearNonDynamicProcess(int delay, double intercept, double slope, Double... initialInputs) {
    this.intercept = intercept;
    this.slope = slope;
    delayBin = new DelayBin<>(delay, 0d);
    Preconditions.checkState(initialInputs.length <= delay);
    for (double input : initialInputs)
        delayBin.addAndRetrieve(input);//ww w .  j  a  v a2 s.  co m

}

From source file:org.locationtech.geogig.storage.postgresql.functional.PGTestUtil.java

public static PGTemporaryTestConfig newTestConfig(String repoName) {
    Preconditions.checkNotNull(perTestSuiteDataSourceProvider);
    Preconditions.checkState(perTestSuiteDataSourceProvider.isEnabled());
    return new PGTemporaryTestConfig(repoName, perTestSuiteDataSourceProvider);
}

From source file:org.onos.yangtools.binding.data.codec.impl.NotificationCodecContext.java

@Override
public D deserialize(final NormalizedNode<?, ?> data) {
    Preconditions.checkState(data instanceof ContainerNode);
    return createBindingProxy((NormalizedNodeContainer<?, ?, ?>) data);
}

From source file:com.google.devtools.build.lib.concurrent.ExecutorShutdownUtil.java

private static boolean shutdownImpl(ExecutorService executor, boolean interruptible) {
    Preconditions.checkState(!executor.isShutdown());
    executor.shutdown();//from   w w  w  .ja va  2 s.c  o m

    // Common pattern: check for interrupt, but don't return until all threads
    // are finished.
    boolean interrupted = false;
    while (true) {
        try {
            executor.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS);
            break;
        } catch (InterruptedException e) {
            if (interruptible) {
                executor.shutdownNow();
            }
            interrupted = true;
        }
    }
    return interrupted;
}

From source file:com.cloudera.impala.analysis.FunctionArgs.java

public FunctionArgs(ArrayList<Type> argTypes, boolean varArgs) {
    this.argTypes = argTypes;
    this.hasVarArgs = varArgs;
    if (varArgs)/*from   ww  w . j  a  v  a 2s.  com*/
        Preconditions.checkState(argTypes.size() > 0);
}