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) 

Source Link

Document

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

Usage

From source file:edu.byu.nlp.stats.SymmetricDirichletOptimizationHelper.java

public static SymmetricDirichletOptimizationHelper newHelper(double[][] data) {
    Preconditions.checkNotNull(data);//from  w w  w.j  a  v a2 s  .co  m
    Preconditions.checkArgument(data.length > 0);

    double sum = 0.0;
    for (double[] theta : data) {
        sum += DoubleArrays.sum(theta);
    }
    return new SymmetricDirichletOptimizationHelper(data[0].length, data.length, sum);
}

From source file:org.xacml4j.v30.types.RFC822NameExp.java

public static RFC822NameExp of(String v) {
    Preconditions.checkArgument(!Strings.isNullOrEmpty(v));
    return new RFC822NameExp(RFC822Name.parse(v));
}

From source file:org.sonar.flex.checks.utils.MetadataTag.java

public static boolean isTag(AstNode metadata, String tagName) {
    Preconditions.checkArgument(metadata.is(FlexGrammar.METADATA_STATEMENT));
    if (isNotEmpty(metadata)) {
        AstNode postfixExpr = metadata.getFirstChild(FlexGrammar.ASSIGNMENT_EXPR)
                .getFirstChild(FlexGrammar.POSTFIX_EXPR);

        return postfixExpr != null && tagName.equals(postfixExpr.getTokenValue());
    }//from   w w w.j  a  va 2  s .c o m
    return false;
}

From source file:org.apache.aurora.scheduler.base.InstanceKeys.java

/**
 * Creates an instance key from a job and instance ID.
 *
 * @param job Job key./*from  w w  w .  j a va2  s . c  om*/
 * @param instanceId Instance id.
 * @return Instance ID.
 */
public static IInstanceKey from(IJobKey job, int instanceId) {
    Objects.requireNonNull(job);
    Preconditions.checkArgument(instanceId >= 0);
    return IInstanceKey.build(new InstanceKey(job.newBuilder(), instanceId));
}

From source file:com.cloudera.oryx.rdf.computation.RDFJobStepConfig.java

public static RDFJobStepConfig fromArgsArray(String... args) {
    Preconditions.checkNotNull(args);/*from   w  w  w .j a  v  a2s .c  o m*/
    Preconditions.checkArgument(args.length >= 4);
    return new RDFJobStepConfig(args[0], Integer.parseInt(args[1]), Integer.parseInt(args[2]),
            Integer.parseInt(args[3]));
}

From source file:auth.ReservedUsernames.java

private static String url(String url) {
    Preconditions.checkArgument(url.startsWith("/"));
    int nextSlash = url.indexOf('/', 1);
    if (nextSlash == -1) {
        return Text.lowercase(url.substring(1));
    } else if (nextSlash == url.length() - 1) {
        return Text.lowercase(url.substring(1, nextSlash));
    } else {//  w  w w  . java 2s .co  m
        throw new IllegalArgumentException("Must be just /url/ or /url, was " + url);
    }
}

From source file:org.trancecode.xml.saxon.SaxonMaps.java

public static Map<QName, String> attributes(final XdmNode element) {
    Preconditions.checkArgument(Saxon.isElement(element));
    return attributes(SaxonAxis.attributes(element));
}

From source file:org.opendaylight.controller.cluster.datastore.messages.DataExistsReply.java

public static DataExistsReply fromSerializable(final Object serializable) {
    Preconditions.checkArgument(serializable instanceof DataExistsReply);
    return (DataExistsReply) serializable;
}

From source file:edu.byu.nlp.stats.GammaDistribution.java

/**
 * self-contained gamma generator. Multiply result with scale parameter (or
 * divide by rate parameter). After Teh (npbayes).
 * //from w  ww.jav a  2s  . c om
 * Taken From knowceans.
 */
public static double sample(double shape, RandomGenerator rnd) {
    Preconditions.checkArgument(shape > 0.0);
    Preconditions.checkNotNull(rnd);

    if (shape == 1.0) {
        /* Exponential */
        return -Math.log(rnd.nextDouble());
    } else if (shape < 1.0) {
        /* Use Johnk's generator */
        double cc = 1.0 / shape;
        double dd = 1.0 / (1.0 - shape);
        while (true) {
            double xx = Math.pow(rnd.nextDouble(), cc);
            double yy = xx + Math.pow(rnd.nextDouble(), dd);
            if (yy <= 1.0) {
                // FIXME: assertion error for rr = 0.010817814317923407
                // assert yy != 0 && xx / yy > 0 : "rr = " + rr;
                // INFO: this if is a hack
                if (yy != 0 && xx / yy > 0) {
                    return -Math.log(rnd.nextDouble()) * xx / yy;
                }
            }
        }
    } else { /* rr > 1.0 */
        /* Use bests algorithm */
        double bb = shape - 1.0;
        double cc = 3.0 * shape - 0.75;
        while (true) {
            double uu = rnd.nextDouble();
            double vv = rnd.nextDouble();
            double ww = uu * (1.0 - uu);
            double yy = Math.sqrt(cc / ww) * (uu - 0.5);
            double xx = bb + yy;
            if (xx >= 0) {
                double zz = 64.0 * ww * ww * ww * vv * vv;
                assert zz > 0 && bb != 0 && xx / bb > 0;
                if ((zz <= (1.0 - 2.0 * yy * yy / xx))
                        || (Math.log(zz) <= 2.0 * (bb * Math.log(xx / bb) - yy))) {
                    return xx;
                }
            }
        }
    }
}

From source file:net.sourceforge.cilib.functions.continuous.moo.wfg.TransFunctions.java

public static double b_poly(double y, double alpha) {
    Preconditions.checkArgument(y >= 0.0);
    Preconditions.checkArgument(y <= 1.0);
    Preconditions.checkArgument(alpha > 0.0);
    Preconditions.checkArgument(alpha != 1.0);

    return Misc.correct_to_01(Math.pow(y, alpha));
}