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:com.google.appinventor.common.utils.FilenameUtils.java

/**
 * Returns the extension of a filename./*from  w  ww.ja v a  2 s.com*/
 *
 * @param filename  filename to get extension of
 * @return  extension of filename
 */
public static String getExtension(String filename) {
    Preconditions.checkNotNull(filename);

    // Separate filename from rest of pathname
    filename = filename.substring(filename.lastIndexOf('/') + 1);

    // Extract extension
    int index = filename.lastIndexOf('.');
    return index == -1 ? "" : filename.substring(index + 1);
}

From source file:com.yahoo.yqlplus.api.index.IndexName.java

public static IndexName of(String... cols) {
    Preconditions.checkNotNull(cols);
    return of(Arrays.asList(cols));
}

From source file:com.turn.splicer.tsdbutils.TsQuerySerializer.java

public static TsQuery deserializeFromJson(String jsonContent) {
    Preconditions.checkNotNull(jsonContent);
    Preconditions.checkArgument(!jsonContent.isEmpty(), "Incoming data was null or empty");

    return JSON.parseToObject(jsonContent, TsQuery.class);
}

From source file:org.mifos.sdk.internal.ServerResponseUtil.java

/**
 * Parses the server response to extract the useful message.
 * @param response the server response/*from   ww  w.ja  v  a2  s.c  om*/
 * @return the error message
 */
public static String parseResponse(final Response response) {
    Preconditions.checkNotNull(response);

    try {
        final InputStream stream = response.getBody().in();
        final InputStreamReader streamReader = new InputStreamReader(stream);
        final JsonObject responseJSON = new Gson().fromJson(streamReader, JsonObject.class);
        final JsonObject message = responseJSON.get("errors").getAsJsonArray().get(0).getAsJsonObject();
        return message.get("developerMessage").getAsString();
    } catch (IOException e) {
        throw new IllegalStateException(e.getMessage());
    }
}

From source file:org.janusgraph.util.encoding.StringEncoding.java

public static boolean isAsciiString(String input) {
    Preconditions.checkNotNull(input);
    for (int i = 0; i < input.length(); i++) {
        int c = input.charAt(i);
        if (c > 127 || c <= 0)
            return false;
    }// w  ww  .j a va2  s .  co m
    return true;
}

From source file:com.facebook.buck.java.abi.Walkers.java

public static Walker getWalkerFor(Path path) {
    Preconditions.checkNotNull(path);

    if (Files.isDirectory(path)) {
        return new DirectoryWalker(path);
    } else {//from  w  ww .jav a2s  .co m
        return new ZipWalker(path);
    }
}

From source file:org.coinj.scrypt.ScryptAlg.java

public static byte[] scryptDigest(byte[] input) {
    Preconditions.checkNotNull(input);
    try {//from   w w w.ja v a  2s. c o m
        return SCrypt.scrypt(input, input, 1024, 1, 1, 32);
    } catch (Exception e) {
        throw new RuntimeException(e); // can't happen
    }
}

From source file:org.opendaylight.iotdm.onem2m.core.utils.JsonUtils.java

/**
 * Puts the given key-value pair in the given JSON object.
 *
 * @param jsonObject The JSON object (must not be {@code null}).
 * @param key The key (must not be {@code null}).
 * @param value The value./*from ww  w .  java2 s . co  m*/
 * @return The JSON object.
 */
public static JSONObject put(JSONObject jsonObject, String key, Object value) {
    Preconditions.checkNotNull(key);
    try {
        jsonObject.put(key, value);
    } catch (JSONException e) {
        // This only happens if the key is null
    }
    return jsonObject;
}

From source file:edu.byu.nlp.util.ColumnMajorMatrices.java

public static void normalizeRows(double[] weights, int numRows) {
    Preconditions.checkNotNull(weights);
    Preconditions.checkArgument(weights.length % numRows == 0);

    int rowLength = weights.length / numRows;
    double[] rowSums = new double[numRows];
    int index = 0;
    for (int col = 0; col < rowLength; col++) {
        for (int row = 0; row < numRows; row++) {
            rowSums[row] += weights[index++];
        }/*from www .  j  a v  a 2s .  c o m*/
    }

    index = 0;
    for (int col = 0; col < rowLength; col++) {
        for (int row = 0; row < rowSums.length; row++) {
            weights[index++] /= rowSums[row];
        }
    }
}

From source file:pl.tools.UrlBuilder.java

public static URL from(String arg) {
    Preconditions.checkNotNull(arg);

    try {//  w  w w  . ja va2  s.c  o m
        return new URL(arg);
    } catch (MalformedURLException e) {
        throw new IllegalArgumentException("Invalid url specified: " + arg, e);
    }
}