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:app.philm.in.fragments.PersonCrewListFragment.java

public static PersonCrewListFragment create(String personId) {
    Preconditions.checkArgument(!TextUtils.isEmpty(personId), "personId cannot be empty");

    Bundle bundle = new Bundle();
    bundle.putString(KEY_QUERY_PERSON_ID, personId);

    PersonCrewListFragment fragment = new PersonCrewListFragment();
    fragment.setArguments(bundle);/*  w  w  w  . java  2 s  .  com*/

    return fragment;
}

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

public static List<PkgUserRatingAggregate> findByPkg(ObjectContext context, Pkg pkg) {
    Preconditions.checkArgument(null != context, "the context must be supplied");
    Preconditions.checkArgument(null != pkg,
            "a package is required to identify the pkg user rating aggregates to return");
    return ObjectSelect.query(PkgUserRatingAggregate.class).where(PKG.eq(pkg)).sharedCache()
            .cacheGroup(HaikuDepot.CacheGroup.PKG_USER_RATING_AGGREGATE.name()).select(context);
}

From source file:app.philm.in.fragments.RelatedMoviesFragment.java

public static RelatedMoviesFragment create(String movieId) {
    Preconditions.checkArgument(!TextUtils.isEmpty(movieId), "movieId cannot be empty");

    Bundle bundle = new Bundle();
    bundle.putString(KEY_QUERY_MOVIE_ID, movieId);

    RelatedMoviesFragment fragment = new RelatedMoviesFragment();
    fragment.setArguments(bundle);/* w w w . j av a  2  s.  c o m*/

    return fragment;
}

From source file:org.voltdb.utils.Digester.java

final public static byte[] sha1(final byte buf[]) {
    Preconditions.checkArgument(buf != null, "specified null buffer");
    MessageDigest md = null;//from   ww w .  j  a v  a  2 s .c  o m
    try {
        md = MessageDigest.getInstance("SHA-1");
    } catch (NoSuchAlgorithmException e) {
        Throwables.propagate(e);
    }
    md.reset();
    return md.digest(buf);
}

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

public static List<Architecture> getAll(ObjectContext context) {
    Preconditions.checkArgument(null != context, "the context must be provided");
    return ObjectSelect.query(Architecture.class).orderBy(Architecture.CODE.asc())
            .cacheStrategy(QueryCacheStrategy.SHARED_CACHE).select(context);
}

From source file:io.airlift.stats.cardinality.Utils.java

public static boolean isPowerOf2(long value) {
    Preconditions.checkArgument(value > 0, "value must be positive");
    return (value & (value - 1)) == 0;
}

From source file:com.mgmtp.jfunk.core.JFunk.java

/**
 * Starts jFunk./*  w ww.  j a  va  2  s. co m*/
 * 
 * <pre>
 * -threadcount=&lt;count&gt;    Optional    Number of threads to be used. Allows for parallel
 *                                     execution of test scripts.
 * -parallel               Optional    Allows a single script to be executed in parallel
 *                                     depending on the number of threads specified. The
 *                                     argument is ignored if multiple scripts are specified.
 * &lt;script parameters&gt     Optional    Similar to Java system properties they can be provided
 *                                     as key-value-pairs preceded by -S, e.g. -Skey=value.
 *                                     These parameters are then available in the script as
 *                                     Groovy variables.
 * &lt;script(s)&gt;             Required    At least one test script must be specified.
 *
 * Example:
 * java -cp &lt;jFunkClasspath&gt; com.mgmtp.jfunk.core.JFunk -Skey=value -threadcount=4 -parallel mytest.script
 * </pre>
 * 
 * @param args
 *            The program arguments.
 */
public static void main(final String[] args) {
    SLF4JBridgeHandler.install();

    boolean exitWithError = true;
    StopWatch stopWatch = new StopWatch();

    try {
        RESULT_LOG.info("jFunk started");
        stopWatch.start();

        int threadCount = 1;
        boolean parallel = false;
        Properties scriptProperties = new Properties();
        List<File> scripts = Lists.newArrayList();

        for (String arg : args) {
            if (arg.startsWith("-threadcount")) {
                String[] split = arg.split("=");
                Preconditions.checkArgument(split.length == 2,
                        "The number of threads must be specified as follows: -threadcount=<value>");
                threadCount = Integer.parseInt(split[1]);
                RESULT_LOG.info("Using " + threadCount + (threadCount == 1 ? " thread" : " threads"));
            } else if (arg.startsWith("-S")) {
                arg = arg.substring(2);
                String[] split = arg.split("=");
                Preconditions.checkArgument(split.length == 2,
                        "Script parameters must be given in the form -S<name>=<value>");
                scriptProperties.setProperty(split[0], normalizeScriptParameterValue(split[1]));
                RESULT_LOG.info("Using script parameter " + split[0] + " with value " + split[1]);
            } else if (arg.equals("-parallel")) {
                parallel = true;
                RESULT_LOG.info("Using parallel mode");
            } else {
                scripts.add(new File(arg));
            }
        }

        if (scripts.isEmpty()) {
            scripts.addAll(requestScriptsViaGui());

            if (scripts.isEmpty()) {
                RESULT_LOG.info("Execution finished (took " + stopWatch + " H:mm:ss.SSS)");
                System.exit(0);
            }
        }

        String propsFileName = System.getProperty("jfunk.props.file", "jfunk.properties");
        Module module = ModulesLoader.loadModulesFromProperties(new JFunkDefaultModule(), propsFileName);
        Injector injector = Guice.createInjector(module);

        JFunkFactory factory = injector.getInstance(JFunkFactory.class);
        JFunkBase jFunk = factory.create(threadCount, parallel, scripts, scriptProperties);
        jFunk.execute();

        exitWithError = false;
    } catch (JFunkExecutionException ex) {
        // no logging necessary
    } catch (Exception ex) {
        Logger.getLogger(JFunk.class).error("jFunk terminated unexpectedly.", ex);
    } finally {
        stopWatch.stop();
        RESULT_LOG.info("Execution finished (took " + stopWatch + " H:mm:ss.SSS)");
    }

    System.exit(exitWithError ? -1 : 0);
}

From source file:net.awired.clients.sonar.QualityMeasures.java

public static SonarQualityMeasure asQualityMeasure(Measure measure, String measureKey) {
    Preconditions.checkNotNull(measure, "measure is mandatory");
    Preconditions.checkArgument(!measureKey.isEmpty(), "measureKey is mandatory");
    Preconditions.checkNotNull(measure.getValue(), "measure must have a value");
    Double value = measure.getValue();
    SonarQualityMeasure qualityMeasure = new SonarQualityMeasure();
    qualityMeasure.setKey(measureKey);/*from   w  ww  .  j  a v  a  2 s .  c o  m*/
    qualityMeasure.setValue(value);
    qualityMeasure.setFormattedValue(measure.getFormattedValue());
    return qualityMeasure;
}

From source file:org.usergrid.services.assets.data.AssetUtils.java

/**
 * Returns the key for the bucket in the following form:
 * [appId]/[{@link org.usergrid.persistence.entities.Asset#getPath()}
 * @param appId/*  w w w.  java  2s.  c o  m*/
 * @param asset
 * @return
 */
public static String buildAssetKey(UUID appId, Asset asset) {
    Preconditions.checkArgument(asset.getUuid() != null, "The asset provided to buildAssetKey had a null UUID");
    Preconditions.checkArgument(appId != null, "The appId provided to buildAssetKey was null");
    return appId.toString().concat("/").concat(asset.getUuid().toString());
}

From source file:org.renyan.leveldb.impl.SequenceNumber.java

public static long packSequenceAndValueType(long sequence, ValueType valueType) {
    Preconditions.checkArgument(sequence <= MAX_SEQUENCE_NUMBER,
            "Sequence number is greater than MAX_SEQUENCE_NUMBER");
    Preconditions.checkNotNull(valueType, "valueType is null");

    return (sequence << 8) | valueType.getPersistentId();
}