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:com.cloudera.nav.sdk.model.CustomIdGenerator.java

public static String generateIdentity(String... args) {
    for (String s : args) {
        Preconditions.checkArgument(!StringUtils.isEmpty(s), "An identity component must not be null or empty");
    }//from   w w w . j av  a2s.  c  om
    return MD5IdGenerator.generateIdentity(args);
}

From source file:io.pravega.common.MathHelpers.java

public static long minMax(long value, long min, long max) {
    Preconditions.checkArgument(min <= max, "min must be less than or equal to max");
    return Math.max(Math.min(value, max), min);
}

From source file:com.cloudera.nav.sdk.model.HiveIdGenerator.java

public static String generateTableId(String sourceId, String databaseName, String tableName) {
    Preconditions.checkArgument(
            !StringUtils.isEmpty(sourceId) && !StringUtils.isEmpty(databaseName)
                    && !StringUtils.isEmpty(tableName),
            "SourceId, database name, and table name must be supplied to " + "generate Hive table identity");
    return MD5IdGenerator.generateIdentity(sourceId, databaseName.toUpperCase(), tableName.toUpperCase());
}

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

public static List<PkgLocalization> findForPkg(ObjectContext context, Pkg pkg) {
    Preconditions.checkArgument(null != context, "the context must be supplied");
    Preconditions.checkArgument(null != pkg, "the pkg must be supplied");
    return ObjectSelect.query(PkgLocalization.class).where(PKG.eq(pkg)).sharedCache()
            .cacheGroup(HaikuDepot.CacheGroup.PKG_LOCALIZATION.name()).select(context);
}

From source file:com.cloudera.nav.plugin.model.HiveIdGenerator.java

public static String generateTableId(String sourceId, String databaseName, String tableName) {
    Preconditions.checkArgument(
            !StringUtils.isEmpty(sourceId) && !StringUtils.isEmpty(databaseName)
                    && !StringUtils.isEmpty(tableName),
            "SourceId, database name, and table name must be supplied to " + "generate Hive table identity");
    return MD5IdGenerator.generateIdentity(sourceId, databaseName, tableName);
}

From source file:co.cask.cdap.data2.transaction.stream.leveldb.LevelDBNameConverter.java

public static TableId from(String levelDBTableName) {
    Preconditions.checkArgument(levelDBTableName != null, "Table name should not be null.");
    // remove table-prefix
    String[] tablePrefixSplit = levelDBTableName.split("_");
    Preconditions.checkArgument(tablePrefixSplit.length > 1, "Missing table-prefix");
    String[] tableNameParts = tablePrefixSplit[1].split("\\.", 2);
    Preconditions.checkArgument(tableNameParts.length > 1, "Missing namespace or tableName");
    return TableId.from(tableNameParts[0], tableNameParts[1]);
}

From source file:app.philm.in.util.IntUtils.java

public static int weightedAverage(int... values) {
    Preconditions.checkArgument(values.length % 2 == 0, "values must have a multiples of 2");

    int sum = 0;/* ww w . j a  v  a 2 s .  c o  m*/
    int sumWeight = 0;

    for (int i = 0; i < values.length; i += 2) {
        int value = values[i];
        int weight = values[i + 1];

        sum += (value * weight);
        sumWeight += weight;
    }

    return sum / sumWeight;
}

From source file:org.opendaylight.controller.config.facade.xml.util.Util.java

public static void checkType(final Object value, final Class<?> clazz) {
    Preconditions.checkArgument(clazz.isAssignableFrom(value.getClass()),
            "Unexpected type " + value.getClass() + " should be " + clazz + " of " + value);
}

From source file:app.philm.in.util.FloatUtils.java

public static float weightedAverage(float... values) {
    Preconditions.checkArgument(values.length % 2 == 0, "values must have a multiples of 2");

    float sum = 0;
    float sumWeight = 0;

    for (int i = 0; i < values.length; i += 2) {
        float value = values[i];
        float weight = values[i + 1];

        sum += (value * weight);//  w  w  w .  j  av a 2s .  co m
        sumWeight += weight;
    }

    return sum / sumWeight;
}

From source file:rus.cpuinfo.Util.ConverterUtil.java

@NonNull
public static String convertFromKHzToMHz(final String KHz) {

    Preconditions.checkArgument(NumberUtils.isCreatable(KHz), "KHz must be a numeric value");
    return String.format(Locale.getDefault(), "%d", convertFromKHzToMHz(Integer.parseInt(KHz)));
}