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:tapestry.Constraints.java

/**
 * Constraint exception when flag is <code>true</code>.
 * /*  ww w.j  av  a  2s . co  m*/
 * @param flag
 *            boolean flag to be checked
 * @param message
 *            description of constraint
 */
public static final void constrain(boolean flag, String message) {
    try {
        Preconditions.checkArgument(flag, message);
    } catch (IllegalArgumentException e) {
        throw new ConstraintException(e);
    }
}

From source file:dodola.anole.lib.AsmUtils.java

/**
 * Gets the class name from a class member internal name, like {@code com/foo/Bar.baz:(I)V}.
 *//* w ww . java2s  .c  o  m*/
public static String getClassName(String memberName) {
    Preconditions.checkArgument(memberName.contains("."), "Class name passed as argument.");
    return memberName.substring(0, memberName.indexOf('.'));
}

From source file:com.continuuity.loom.scheduler.task.JobId.java

/**
 * Convert a string representation of a job id into an object while validating that the string is correctly
 * formatted. Throws an IllegalArgumentException if the string is invalid.
 *
 * @param jobIdStr String representation of a job id.
 * @return converted JobId based on the input string.
 *///  w  ww.java2s .  co  m
public static JobId fromString(String jobIdStr) {
    int index = jobIdStr.indexOf("-");
    Preconditions.checkArgument(index > 0, "invalid job id string " + jobIdStr);
    String clusterId = jobIdStr.substring(0, index);

    Preconditions.checkArgument(jobIdStr.indexOf("-", index + 1) < 0, "invalid job id string " + jobIdStr);
    long jobNum = Long.valueOf(jobIdStr.substring(index + 1));

    return new JobId(clusterId, jobNum);
}

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

public static List<UserRatingStability> getAll(ObjectContext context) {
    Preconditions.checkArgument(null != context, "the context must be supplied");
    return ObjectSelect.query(UserRatingStability.class).orderBy(NAME.asc()).sharedCache().select(context);
}

From source file:nl.matsv.viabackwards.ViaBackwards.java

public static void init(ViaBackwardsPlatform platform) {
    Preconditions.checkArgument(platform != null, "ViaBackwards is already initialized");

    ViaBackwards.platform = platform;/*from   w w w .  j a  va 2 s . c o m*/
}

From source file:com.zaradai.kunzite.optimizer.model.Series.java

public static Series newStepSeries(double start, double step, int steps) {
    Preconditions.checkArgument(step > 0, "Step must be positive");

    Series res = new Series();

    double value = start;

    for (int i = 0; i < steps; ++i) {
        res.values.add(value);/* www . j a  v a2  s .c om*/
        value += step;
    }

    return res;
}

From source file:com.google.security.zynamics.binnavi.disassembly.algorithms.CViewNodeHelpers.java

/**
 * Determines the start address of a view node.
 * //from   www  . ja va2  s .  co m
 * @param node The node whose address is determined.
 * 
 * @return The start address of the node.
 */
public static IAddress getAddress(final INaviViewNode node) {
    Preconditions.checkArgument(node instanceof IAddressNode,
            "IE00431: Node is not a code node or a function node");
    return ((IAddressNode) node).getAddress();
}

From source file:com.palantir.atlasdb.schema.SchemaVersion.java

public static SchemaVersion create(long version, long hotfix, long hotfixHotfix) {
    Preconditions.checkArgument(version > 0, "version must be greater than 0");
    return new SchemaVersion(version, hotfix, hotfixHotfix);
}

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

public static Optional<PkgLocalization> getForPkgAndNaturalLanguageCode(ObjectContext context, Pkg pkg,
        final String naturalLanguageCode) {
    Preconditions.checkArgument(null != context, "the context must be supplied");
    Preconditions.checkArgument(null != pkg, "the pkg must be supplied");
    Preconditions.checkArgument(!Strings.isNullOrEmpty(naturalLanguageCode),
            "the natural language code must be supplied");
    return findForPkg(context, pkg).stream()
            .filter(l -> l.getNaturalLanguage().getCode().equals(naturalLanguageCode))
            .collect(SingleCollector.optional());
}

From source file:org.fusesource.process.manager.support.FileUtils.java

public static void extractArchive(File archiveFile, File targetDirectory, String extractCommand,
        Duration timeLimit, Executor executor) throws CommandFailedException {
    Preconditions.checkNotNull(archiveFile, "archiveFile is null");
    Preconditions.checkNotNull(targetDirectory, "targetDirectory is null");
    Preconditions.checkArgument(targetDirectory.isDirectory(),
            "targetDirectory is not a directory: " + targetDirectory.getAbsolutePath());

    final String[] commands = extractCommand.split(" ");
    final String[] args = Arrays.copyOf(commands, commands.length + 1);
    args[args.length - 1] = archiveFile.getAbsolutePath();
    new Command(args).setDirectory(targetDirectory).setTimeLimit(timeLimit).execute(executor);
}