Example usage for com.google.common.base Preconditions checkNotNull

List of usage examples for com.google.common.base Preconditions checkNotNull

Introduction

In this page you can find the example usage for com.google.common.base Preconditions checkNotNull.

Prototype

public static <T> T checkNotNull(T reference) 

Source Link

Document

Ensures that an object reference passed as a parameter to the calling method is not null.

Usage

From source file:cz.cuni.mff.ms.brodecva.botnicek.ide.aiml.types.AttributeImplementation.java

/**
 * Vytvo atribut podporovan verze jazyka AIML.
 * //from   w w w. j a v  a 2 s .  c  o  m
 * @param name
 *            nzev
 * @param value
 *            hodnota
 * @return atribut
 */
public static AttributeImplementation create(final String name, final String value) {
    Preconditions.checkNotNull(name);
    Preconditions.checkNotNull(value);
    Preconditions.checkArgument(!name.isEmpty());

    return new AttributeImplementation(name, value, Optional.<URI>absent());
}

From source file:ivory.smrf.model.builder.MRFBuilder.java

public static MRFBuilder get(RetrievalEnvironment env, Node model) throws ConfigurationException {
    Preconditions.checkNotNull(env);
    Preconditions.checkNotNull(model);//from  w  w  w . j  ava 2  s .c  o m

    // Get model type.
    String modelType = XMLTools.getAttributeValueOrThrowException(model, "type",
            "Model type must be specified!");

    // Build the builder.
    MRFBuilder builder = null;

    try {
        if ("Feature".equals(modelType)) {
            builder = new FeatureBasedMRFBuilder(env, model);
        } else if ("GreedyConstrained".equals(modelType)) {
            builder = new GreedyConstrainedMRFBuilder(env, model);
        } else if (modelType.equals("New")) {
            builder = new CascadeFeatureBasedMRFBuilder(env, model);
        } else {
            throw new ConfigurationException("Unrecognized model type: " + modelType);
        }
    } catch (IOException e) {
        throw new RetrievalException("Error getting MRFBuilder: " + e);
    }

    return builder;
}

From source file:org.metaborg.intellij.resources.FileNameUtils.java

/**
 * Gets the outer file name of the specified file name.
 * <p>/*  www . ja  v a 2s  . co  m*/
 * For example, if the specified file name is <code>zip:file:///dir/archive.zip!/document.txt</code>,
 * then the outer file name is <code>file:///dir/archive.zip</code>.
 *
 * @param fileName The file name.
 * @return The outer file name; or <code>null</code> when there is none.
 */
@Nullable
public static FileName getOuterFileName(final FileName fileName) {
    Preconditions.checkNotNull(fileName);

    if (fileName instanceof LayeredFileName) {
        return ((LayeredFileName) fileName).getOuterName();
    } else {
        return null;
    }
}

From source file:se.toxbee.sleepfighter.utils.math.Conversion.java

/**
 * Converts a boolean array to an integer.
 *
 * @param b the boolean array.//from   ww  w. j  ava2 s.  c om
 * @return the resultant integer.
 */
public static int boolArrayToInt(boolean[] b) {
    Preconditions.checkNotNull(b);

    int n = 0;
    for (int i = b.length - 1; i >= 0; --i) {
        n = (n << 1) + (b[i] ? 1 : 0);
    }
    return n;
}

From source file:cz.cuni.mff.ms.brodecva.botnicek.ide.check.words.model.builder.DefaultNormalWordBuilderFactory.java

/**
 * Vytvo tovrnu./*from   ww w.  j av  a 2 s. c  om*/
 * 
 * @param checker
 *            validtor
 * @return tovrna
 */
public static DefaultNormalWordBuilderFactory create(final Checker checker) {
    Preconditions.checkNotNull(checker);

    return new DefaultNormalWordBuilderFactory(checker);
}

From source file:com.google.devtools.build.skyframe.SchedulerException.java

/**
 * Returns a SchedulerException wrapping an expected error, e.g. an error describing an expected
 * build failure when trying to evaluate the given value, that should cause Skyframe to produce
 * useful error information to the user.
 *///w  ww . j  a  v  a 2s.  c o m
static SchedulerException ofError(ErrorInfo errorInfo, SkyKey failedValue) {
    Preconditions.checkNotNull(errorInfo);
    return new SchedulerException(errorInfo.getException(), errorInfo, failedValue);
}

From source file:com.google.enterprise.connector.db.diffing.DigestContentHolder.java

public static DigestContentHolder getInstance(byte[] contentBytes, MimeTypeDetector mimeTypeDetector) {
    Preconditions.checkNotNull(contentBytes);
    DigestContentHolder contentHolder = new DigestContentHolder(InputStreamFactories.newInstance(contentBytes),
            mimeTypeDetector.getMimeType(null, contentBytes), contentBytes.length);
    contentHolder.updateDigest(contentBytes);
    return contentHolder;
}

From source file:org.mifos.sdk.client.domain.commands.WithdrawRejectClientTransferCommand.java

/**
 * Sets the note with the reason, cannot be null or empty.
 * @param description the note with the reason
 * @return a new instance of {@link Builder}
 *//*from   w  ww .  j  a va 2  s  .c  o  m*/
public static Builder note(final String description) {
    Preconditions.checkNotNull(description);
    Preconditions.checkArgument(!description.isEmpty());

    return new Builder(description);
}

From source file:com.google.api.tools.framework.tools.util.OutputUtil.java

/**
 * Writes string content to a file./*from  w  ww.j  a  v a  2 s . c o m*/
 */
public static void writeToFile(File outputFile, String content) throws IOException {
    Preconditions.checkNotNull(outputFile);
    Preconditions.checkNotNull(content);

    try (BufferedWriter outWriter = Files.newWriter(outputFile, StandardCharsets.UTF_8)) {
        outWriter.write(content);
    }
}

From source file:com.jivesoftware.os.tasmo.id.TenantId.java

@JsonCreator
public TenantId(String tenantId) {
    Preconditions.checkNotNull(tenantId);
    tenantId = tenantId.trim();//from  ww w.  jav  a 2  s  .  c o m
    Preconditions.checkArgument(tenantId.length() > 0);
    this.tenantId = tenantId;
}