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, @Nullable Object errorMessage) 

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.linkedin.pinot.core.data.readers.RecordReaderFactory.java

public static RecordReader getRecordReader(SegmentGeneratorConfig segmentGeneratorConfig) throws Exception {
    File dataFile = new File(segmentGeneratorConfig.getInputFilePath());
    Preconditions.checkState(dataFile.exists(),
            "Input file: " + dataFile.getAbsolutePath() + " does not exist");

    Schema schema = segmentGeneratorConfig.getSchema();
    FileFormat fileFormat = segmentGeneratorConfig.getFormat();
    switch (fileFormat) {
    case AVRO:/* ww  w .  java  2s. c  o  m*/
    case GZIPPED_AVRO:
        return new AvroRecordReader(dataFile, schema);
    case CSV:
        return new CSVRecordReader(dataFile, schema,
                (CSVRecordReaderConfig) segmentGeneratorConfig.getReaderConfig());
    case JSON:
        return new JSONRecordReader(dataFile, schema);
    case PINOT:
        return new PinotSegmentRecordReader(dataFile, schema);
    case THRIFT:
        return new ThriftRecordReader(dataFile, schema,
                (ThriftRecordReaderConfig) segmentGeneratorConfig.getReaderConfig());
    default:
        throw new UnsupportedOperationException("Unsupported input file format: " + fileFormat);
    }
}

From source file:com.facebook.buck.android.BootClasspathAppender.java

private static String androidBootclasspath(AndroidPlatformTarget platform) {
    List<Path> bootclasspathEntries = platform.getBootclasspathEntries();
    Preconditions.checkState(!bootclasspathEntries.isEmpty(), "There should be entries for the bootclasspath");
    return Joiner.on(File.pathSeparator).join(bootclasspathEntries);
}

From source file:com.tellapart.taba.TabaApiFactory.java

public static synchronized void initialize(TabaClientProperties properties) {
    Preconditions.checkState(engine == null, "Already initialized.");

    TabaClientEngine clientEngine = new DefaultClientEngine(properties, HttpClients.createDefault(),
            Executors.newScheduledThreadPool(1));

    initialize(clientEngine);//from  w w  w. jav  a2s.c  o m
}

From source file:org.thelq.pircbotx.keepalive.JenkinsKeepAlive.java

public static void create() {
    Preconditions.checkState(!created, "Already created");
    created = true;//from   w  w  w .  j  a v a2s . com
    ImmutableList.Builder<String> jenkinsBotsBuilder = ImmutableList.builder();
    for (int i = 1;; i++) {

        String value = "";
        if (value == null)
            break;
        jenkinsBotsBuilder.add(value);
    }

    ImmutableList<String> jenkinsBots = jenkinsBotsBuilder.build();
    if (jenkinsBots.size() == 0)
        throw new RuntimeException("No jenkins bots setup!");
    log.info("Created jenkins keep alive for " + jenkinsBots.toString());
    KeepAlive.getExecutor().scheduleAtFixedRate(new JenkinsRunner(jenkinsBots), 0, 15, TimeUnit.MINUTES);
}

From source file:com.google.template.soy.jssrc.dsl.BinaryOperation.java

static CodeChunk.WithValue create(Operator operator, CodeChunk.WithValue arg1, CodeChunk.WithValue arg2) {
    Preconditions.checkState(operator != Operator.AND, "use BinaryOperation::and");
    Preconditions.checkState(operator != Operator.OR, "use BinaryOperation::or");
    return create(operator.getTokenString(), operator.getPrecedence(), operator.getAssociativity(), arg1, arg2);
}

From source file:org.geogit.rest.repository.GeogitResourceUtils.java

public static Catalog getCatalog(Request request) {
    Map<String, Object> attributes = request.getAttributes();
    Catalog catalog = (Catalog) attributes.get("catalog");
    Preconditions.checkState(catalog != null, "Catalog is not set as a request property");
    return catalog;
}

From source file:org.opendaylight.controller.config.yangjmxgenerator.attribute.SimpleTypeResolver.java

public static SimpleType<?> getSimpleType(String fullyQualifiedName) {
    SimpleType<?> expectedSimpleType = JAVA_TYPE_TO_SIMPLE_TYPE.get(fullyQualifiedName);
    Preconditions.checkState(expectedSimpleType != null, "Cannot find simple type for " + fullyQualifiedName);
    return expectedSimpleType;
}

From source file:com.dangdang.ddframe.rdb.sharding.hint.HintManagerHolder.java

/**
 * ?.//  w  w  w .j a  v  a  2 s . c o  m
 *
 * @param hintManager ?
 */
public static void setHintManager(final HintManager hintManager) {
    Preconditions.checkState(null == HINT_MANAGER_HOLDER.get(),
            "HintManagerHolder has previous value, please clear first.");
    HINT_MANAGER_HOLDER.set(hintManager);
}

From source file:com.spectralogic.ds3client.helpers.RangeHelper.java

static ImmutableCollection<Range> replaceRange(final ImmutableCollection<Range> existingRanges,
        final long numBytesTransferred, final long intendedNumBytesToTransfer) {
    Preconditions.checkState(numBytesTransferred >= 0, "numBytesTransferred must be >= 0.");
    Preconditions.checkState(intendedNumBytesToTransfer > 0, "intendedNumBytesToTransfer must be > 0.");
    Preconditions.checkState(intendedNumBytesToTransfer > numBytesTransferred,
            "intendedNumBytesToTransfer must be > numBytesTransferred");

    if (Guard.isNullOrEmpty(existingRanges)) {
        return ImmutableList
                .of(Range.byLength(numBytesTransferred, intendedNumBytesToTransfer - numBytesTransferred));
    }/*w  ww. j  a  v  a  2  s .c  om*/

    final ImmutableList.Builder<Range> newRangesbuilder = ImmutableList.builder();

    final UnmodifiableIterator<Range> existingRangesIterator = existingRanges.iterator();

    long previousAccumulatedBytesInRanges = 0;
    long currentAccumulatedBytesInRanges = existingRanges.iterator().next().getLength();

    while (existingRangesIterator.hasNext()) {
        final Range existingRange = existingRangesIterator.next();

        if (numBytesTransferred < currentAccumulatedBytesInRanges) {
            final Range firstNewRange = Range.byPosition(
                    existingRange.getStart() - previousAccumulatedBytesInRanges + numBytesTransferred,
                    existingRange.getEnd());
            newRangesbuilder.add(firstNewRange);

            addRemainingRanges(existingRangesIterator, newRangesbuilder);
            break;
        }

        previousAccumulatedBytesInRanges += existingRange.getLength();
        currentAccumulatedBytesInRanges += existingRange.getLength();
    }

    return newRangesbuilder.build();
}

From source file:codecrafter47.bungeetablistplus.api.sponge.BungeeTabListPlusSpongeAPI.java

/**
 * Registers a custom variable//from  ww  w . ja va 2s . co  m
 * <p>
 * You cannot use this to replace existing variables. If registering a variable which already
 * exists there may be an exception thrown but there is no guarantee that an exception
 * is thrown in that case.
 *
 * @param plugin   your plugin
 * @param variable your variable
 */
public static void registerVariable(Object plugin, Variable variable) {
    Preconditions.checkState(instance != null, "instance is null, is the plugin enabled?");
    instance.registerVariable0(plugin, variable);
}