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:ivory.smrf.model.builder.ExpressionGenerator.java

@SuppressWarnings("unchecked")
public static ExpressionGenerator create(String type, Node domNode) throws ConfigurationException {
    Preconditions.checkNotNull(type);
    Preconditions.checkNotNull(domNode);

    try {/*from   w  w  w  . j av a 2 s. c o m*/
        Class<? extends ExpressionGenerator> clz = (Class<? extends ExpressionGenerator>) Class.forName(type);
        ExpressionGenerator f = clz.newInstance();
        f.configure(domNode);

        return f;
    } catch (Exception e) {
        throw new ConfigurationException("Unable to instantiate ExpressionGenerator \"" + type + "\"!", e);
    }
}

From source file:org.ros.message.MessageDeclaration.java

public static MessageDeclaration of(String type, String definition) {
    Preconditions.checkNotNull(type);
    Preconditions.checkNotNull(definition);
    return new MessageDeclaration(MessageIdentifier.of(type), definition);
}

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

static LabelSelector fromString(String raw) {
    Preconditions.checkNotNull(raw);
    Preconditions.checkState(!raw.isEmpty());

    boolean isInclusive = true;
    if (raw.charAt(0) == '!') {
        isInclusive = false;//from w ww .  j  a  va 2 s. c  o  m
        raw = raw.substring(1);
    }

    ImmutableSet.Builder<Label> labelBuilder = new ImmutableSet.Builder<>();
    Iterable<String> labelStrings = splitter.split(raw);
    for (String labelString : labelStrings) {
        BuckConfig.validateLabelName(labelString);
        labelBuilder.add(new Label(labelString));
    }

    return new LabelSelector(isInclusive, labelBuilder.build());
}

From source file:org.projectbuendia.client.utils.LexicographicVersion.java

/** Returns an instance of {@link LexicographicVersion} parsed from the specified string. */
public static LexicographicVersion parse(String raw) {
    Preconditions.checkNotNull(raw);
    Preconditions.checkArgument(!raw.equals(""));

    String[] stringParts = raw.split("\\.");
    int[] parts = new int[stringParts.length];
    for (int i = 0; i < stringParts.length; i++) {
        try {// ww  w .j  a  va2s  .c o m
            parts[i] = Integer.parseInt(stringParts[i]);
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException("'" + raw + "' is not a valid version string.", e);
        }
    }

    return new LexicographicVersion(raw, parts);
}

From source file:com.spotify.helios.client.ClientCertificatePath.java

private static Path checkExists(Path path) {
    Preconditions.checkNotNull(path);
    Preconditions.checkArgument(path.toFile().canRead(), path + " does not exist or cannot be read");
    return path;// w  ww .  j a  v  a2s . c  om
}

From source file:se.curity.examples.oauth.AuthenticatedUser.java

public static AuthenticatedUser fromMap(Map<String, Object> tokenData) {
    Preconditions.checkNotNull(tokenData.get("sub"));
    String sub = (String) tokenData.get("sub");
    @Nullable/*from   ww  w  .  j av a 2s  . co m*/
    String scope = (String) tokenData.get("scope");

    return new AuthenticatedUser(sub, scope);
}

From source file:org.sosy_lab.cpachecker.cpa.coverage.CoverageState.java

public static CoverageState getSingleton() {
    Preconditions.checkNotNull(instance);
    return instance;
}

From source file:com.google.collide.shared.grok.PositionTranslator.java

private static List<Integer> calculateNewlineOffsets(String fileContents) {
    Preconditions.checkNotNull(fileContents);
    List<Integer> newlineOffsets = Lists.newArrayList();
    for (int i = -1; (i = fileContents.indexOf('\n', i + 1)) >= 0;) {
        newlineOffsets.add(i);//w ww.j  av  a 2s  . c om
    }

    return newlineOffsets;
}

From source file:com.google.template.soy.conformance.ConformanceInput.java

public static ConformanceInput create(SoyFileSetNode soyTree,
        ImmutableList<SlicedRawTextNode> slicedRawTextNodes) {
    return new AutoValue_ConformanceInput(Preconditions.checkNotNull(soyTree),
            Preconditions.checkNotNull(slicedRawTextNodes));
}

From source file:com.facebook.buck.rules.keys.config.impl.BuckBinaryHashProvider.java

/**
 * Returns Buck binary hash/*from  w  ww . j a va  2 s.com*/
 *
 * <p>The Buck binary hash key is generated during build time and reflects changes in Buck code
 * that can affect the content of build artifacts.
 */
public static String getBuckBinaryHash() {
    if (buckBinaryHash == null) {
        buckBinaryHash = Preconditions.checkNotNull(System.getProperty("buck.binary_hash"));
    }
    return buckBinaryHash;
}