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

Source Link

Document

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

Usage

From source file:org.apache.james.quota.search.Limit.java

public static Limit of(int value) {
    Preconditions.checkArgument(value >= 0, "A limit need to be positive");
    return new Limit(Optional.of(value));
}

From source file:gobblin.kafka.schemareg.KafkaSchemaRegistryFactory.java

@SuppressWarnings("unchecked")
public static KafkaSchemaRegistry getSchemaRegistry(Properties props) {
    Preconditions.checkArgument(
            props.containsKey(KafkaSchemaRegistryConfigurationKeys.KAFKA_SCHEMA_REGISTRY_CLASS),
            "Missing required property " + KafkaSchemaRegistryConfigurationKeys.KAFKA_SCHEMA_REGISTRY_CLASS);

    boolean tryCache = Boolean.parseBoolean(props.getProperty(
            KafkaSchemaRegistryConfigurationKeys.KAFKA_SCHEMA_REGISTRY_CACHE, DEFAULT_TRY_CACHING));

    Class<?> clazz;//from w ww. j  a v a 2 s  .co  m
    try {
        clazz = (Class<?>) Class
                .forName(props.getProperty(KafkaSchemaRegistryConfigurationKeys.KAFKA_SCHEMA_REGISTRY_CLASS));
        KafkaSchemaRegistry schemaRegistry = (KafkaSchemaRegistry) ConstructorUtils.invokeConstructor(clazz,
                props);
        if (tryCache && !schemaRegistry.hasInternalCache()) {
            schemaRegistry = new CachingKafkaSchemaRegistry(schemaRegistry);
        }
        return schemaRegistry;
    } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException
            | InstantiationException e) {
        log.error("Failed to instantiate " + KafkaSchemaRegistry.class, e);
        throw Throwables.propagate(e);
    }
}

From source file:com.google.uzaygezen.core.BitVectorMath.java

/**
 * Splits the bits from {@code bs} into {@code result} by putting the
 * lowest bits at the end of {@code result} and so on until the highest bits
 * are put at the beginning of {@code result}. This is similar to the big
 * endian representation of numbers, only that each digit has a potentially
 * different size. The bit set length must be equal to {@code
 * sum(elementLengths)}./*from  www . j ava2 s .  co  m*/
 * 
 * @param bs little endian bit set
 * @param result output
 */
public static void split(BitVector bs, BitVector[] result) {
    int sum = 0;
    for (BitVector bv : result) {
        sum += bv.size();
    }
    Preconditions.checkArgument(sum == bs.size(), "size sum does not match");
    int startIndex = 0;
    for (int i = result.length; --i >= 0;) {
        result[i].copyFromSection(bs, startIndex);
        startIndex += result[i].size();
    }
    Preconditions.checkArgument(startIndex >= bs.length(), "bit length is too high");
}

From source file:com.metamx.druid.query.Queries.java

public static void verifyAggregations(List<AggregatorFactory> aggFactories, List<PostAggregator> postAggs) {
    Preconditions.checkNotNull(aggFactories, "aggregations cannot be null");
    Preconditions.checkArgument(aggFactories.size() > 0, "Must have at least one AggregatorFactory");

    if (postAggs != null && !postAggs.isEmpty()) {
        Set<String> combinedAggNames = Sets
                .newHashSet(Lists.transform(aggFactories, new Function<AggregatorFactory, String>() {
                    @Override//from   w  w w .j a  va 2 s .c  om
                    public String apply(@Nullable AggregatorFactory input) {
                        return input.getName();
                    }
                }));

        for (PostAggregator postAgg : postAggs) {
            Set<String> dependencies = postAgg.getDependentFields();
            Set<String> missing = Sets.difference(dependencies, combinedAggNames);

            Preconditions.checkArgument(missing.isEmpty(), "Missing fields [%s] for postAggregator [%s]",
                    missing, postAgg.getName());
            combinedAggNames.add(postAgg.getName());
        }
    }
}

From source file:co.cask.cdap.data2.util.TableId.java

public static TableId from(Id.Namespace namespaceId, String tableName) {
    Preconditions.checkArgument(tableName != null, "Table name should not be null.");
    // Id.Namespace already checks for non-null namespace
    return new TableId(namespaceId, tableName);
}

From source file:com.google.cloud.bigtable.grpc.scanner.ResultQueueEntry.java

/**
 * <p>fromResponse.</p>//from   w  w  w . j a  va  2 s  .  c  o m
 *
 * @param response a T object.
 * @param <T> a T object.
 * @return a {@link com.google.cloud.bigtable.grpc.scanner.ResultQueueEntry} object.
 */
public static <T> ResultQueueEntry<T> fromResponse(T response) {
    Preconditions.checkArgument(response != null, "Response may not be null");
    return new ResponseResultQueueEntry<T>(response);
}

From source file:org.haiku.haikudepotserver.dataobjects.RepositorySource.java

public static RepositorySource get(ObjectContext context, ObjectId objectId) {
    Preconditions.checkArgument(null != context, "the context must be supplied");
    Preconditions.checkArgument(null != objectId, "the objectId must be supplied");
    Preconditions.checkArgument(objectId.getEntityName().equals(RepositorySource.class.getSimpleName()),
            "the objectId must be targetting RepositorySource");
    return SelectById.query(RepositorySource.class, objectId).sharedCache().selectOne(context);
}

From source file:webindex.data.fluo.PageLoader.java

public static PageLoader updatePage(Page page) {
    Preconditions.checkArgument(!page.isEmpty(), "Page cannot be empty");
    PageLoader update = new PageLoader();
    update.action = Action.UPDATE;
    update.page = page;/*from  w  ww  .j  ava 2s  .  c  om*/
    return update;
}

From source file:org.apache.james.jmap.model.BlobId.java

public static BlobId of(String rawValue) {
    Preconditions.checkArgument(!Strings.isNullOrEmpty(rawValue), "'rawValue' is mandatory");
    return new BlobId(rawValue);
}

From source file:org.apache.james.mailbox.store.mail.model.impl.Cid.java

public static Cid from(String cidAsString) {
    Preconditions.checkNotNull(cidAsString);
    Preconditions.checkArgument(!cidAsString.isEmpty(), "'cidAsString' is mandatory");
    return new Cid(normalizedCid(cidAsString));
}