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.facebook.buck.rules.IndividualTestEvent.java

public static Finished finished(Iterable<String> targets, TestResults results) {
    return new Finished(targets.hashCode(), Preconditions.checkNotNull(results));
}

From source file:com.google.gerrit.common.RawInputUtil.java

public static RawInput create(final byte[] bytes, final String contentType) {
    Preconditions.checkNotNull(bytes);
    Preconditions.checkArgument(bytes.length > 0);
    return new RawInput() {
        @Override// w  w  w .  jav a2  s  .  c  o m
        public InputStream getInputStream() throws IOException {
            return new ByteArrayInputStream(bytes);
        }

        @Override
        public String getContentType() {
            return contentType;
        }

        @Override
        public long getContentLength() {
            return bytes.length;
        }
    };
}

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

public static IntegerExp of(String v) {
    Preconditions.checkNotNull(v);
    if ((v.length() >= 1) && (v.charAt(0) == '+')) {
        v = v.substring(1);/*from w w  w.j a v a  2  s .c  om*/
    }
    return new IntegerExp(Long.parseLong(v));
}

From source file:com.facebook.buck.cli.CommandHelper.java

public static void printJSON(CommandRunnerParams params, Multimap<String, QueryTarget> targetsAndResults)
        throws IOException {
    Multimap<String, String> targetsAndResultsNames = Multimaps.transformValues(targetsAndResults,
            input -> Preconditions.checkNotNull(input.toString()));
    params.getObjectMapper().writeValue(params.getConsole().getStdOut(), targetsAndResultsNames.asMap());
}

From source file:com.google.copybara.git.GitAuthorParser.java

/**
 * Parses a Git author {@code string} into an {@link Author}.
 *///from w  ww.  j  a v  a2  s . co  m
static Author parse(String author) {
    Preconditions.checkNotNull(author);
    Matcher matcher = AUTHOR_PATTERN.matcher(author);
    Preconditions.checkArgument(matcher.matches(), "Invalid author '%s'. Must be in the form of 'Name <email>'",
            author);
    return new Author(matcher.group(1).trim(), matcher.group(2).trim());
}

From source file:com.google.copybara.authoring.AuthorParser.java

/**
 * Parses a Git author {@code string} into an {@link Author}.
 *//*from  w  w w.ja  va 2  s.c  om*/
public static Author parse(String author) throws InvalidAuthorException {
    Preconditions.checkNotNull(author);
    Matcher matcher = AUTHOR_PATTERN.matcher(author);
    if (!matcher.matches()) {
        throw new InvalidAuthorException(
                String.format("Invalid author '%s'. Must be in the form of 'Name <email>'", author));
    }
    return new Author(matcher.group(1).trim(), matcher.group(2).trim());
}

From source file:harp.util.FileUtil.java

/**
 * Find a file with the given base name, searching upward from the given starting directory.
 *
 * @param filename the base filename to look for
 * @param startingPath the starting directory to search upward from
 *
 * @return an {@code Optional} containing the Path of the file if found, or an empty Optional
 *     otherwise//from  www  . j a  va  2 s.c  o  m
 */
public static Optional<Path> findUpward(String filename, Path startingPath) {
    Preconditions.checkNotNull(filename);
    Preconditions.checkArgument(!filename.contains(File.separator));
    Preconditions.checkArgument(Files.isDirectory(startingPath));
    Path possibleRootDir = startingPath;
    while (possibleRootDir != null) {
        Path possiblePath = possibleRootDir.resolve(filename);
        if (Files.isRegularFile(possiblePath)) {
            return Optional.of(possiblePath);
        } else {
            possibleRootDir = possibleRootDir.getParent();
        }
    }
    return Optional.absent();
}

From source file:com.minlia.cloud.framework.common.util.SearchCommonUtil.java

public static List<Triple<String, ClientOperation, String>> parseQueryString(final String queryString) {
    Preconditions.checkNotNull(queryString);
    Preconditions.checkState(queryString.matches("((id~?=[0-9]+)?,?)*((name~?=[0-9a-zA-Z\\-_/*]+),?)*"));

    final List<Triple<String, ClientOperation, String>> tuplesList = Lists.newArrayList();
    final String[] tuples = queryString.split(QueryConstants.SEPARATOR);
    for (final String tuple : tuples) {
        final String[] keyAndValue = tuple.split(QueryConstants.OP);
        Preconditions.checkState(keyAndValue.length == 2);
        tuplesList.add(createConstraintFromUriParam(keyAndValue[0], keyAndValue[1]));
    }/*from   w  w w.j a v a 2s . c o m*/

    return tuplesList;
}

From source file:io.github.msdk.util.MsScanUtil.java

/**
 * <p>//from www .j  av a  2s.c  o  m
 * clone.
 * </p>
 *
 * @param newStore
 *            a {@link io.github.msdk.datamodel.datastore.DataPointStore}
 *            object.
 * @param scan
 *            a {@link io.github.msdk.datamodel.rawdata.MsScan} object.
 * @param copyDataPoints
 *            a {@link java.lang.Boolean} object.
 * @return a {@link io.github.msdk.datamodel.rawdata.MsScan} object.
 */
@Nonnull
static public MsScan clone(@Nonnull DataPointStore newStore, @Nonnull MsScan scan,
        @Nonnull Boolean copyDataPoints) {

    Preconditions.checkNotNull(newStore);
    Preconditions.checkNotNull(scan);
    Preconditions.checkNotNull(copyDataPoints);

    MsScan newScan = MSDKObjectBuilder.getMsScan(newStore, scan.getScanNumber(), scan.getMsFunction());

    newScan.setPolarity(scan.getPolarity());
    newScan.setMsScanType(scan.getMsScanType());
    newScan.setScanningRange(scan.getScanningRange());
    newScan.setChromatographyInfo(scan.getChromatographyInfo());
    newScan.setSourceInducedFragmentation(scan.getSourceInducedFragmentation());
    newScan.getIsolations().addAll(scan.getIsolations());

    if (copyDataPoints) {
        double mzValues[] = scan.getMzValues();
        float intensityValues[] = scan.getIntensityValues();
        newScan.setDataPoints(mzValues, intensityValues, scan.getNumberOfDataPoints());
    }

    return newScan;
}

From source file:com.jjm.android.googleplaces.util.ApiKeys.java

/**
 * Add an api key./*from  www .  j  av  a2s  .  com*/
 * @param id an id that can be used to retreive the api key.
 * @param apiKey the api key.
 */
public static void addApiKey(String id, String apiKey) {
    sApiKeys.put(Preconditions.checkNotNull(id), Preconditions.checkNotNull(apiKey));
}