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:org.apache.james.backends.cassandra.init.CassandraNodeIpAndPort.java

public static CassandraNodeIpAndPort parseConfString(String ipAndPort) {
    Preconditions.checkNotNull(ipAndPort);
    Preconditions.checkArgument(!ipAndPort.isEmpty());

    List<String> parts = Splitter.on(':').trimResults().splitToList(ipAndPort);

    if (parts.size() < 1 || parts.size() > 2) {
        throw new IllegalArgumentException(ipAndPort + " is not a valid cassandra node");
    }//from w  ww .j  av  a2s .  c  om

    String ip = parts.get(0);
    int port = getPortFromConfPart(parts);

    return new CassandraNodeIpAndPort(ip, port);
}

From source file:edu.zipcloud.cloudstreetmarket.core.util.TransactionUtil.java

public static BigDecimal getPriceInUserCurrency(Quote quote, UserActivityType transactionType, int quantity,
        User user, @Nullable CurrencyExchange currencyExchange) {
    Preconditions.checkNotNull(transactionType);
    Preconditions.checkNotNull(user);//from  w ww  . j  ava 2  s. c  o  m
    Preconditions.checkNotNull(quote);
    Preconditions.checkArgument(quote instanceof StockQuote, "Quote type not supported yet");
    Preconditions.checkArgument(
            transactionType.equals(UserActivityType.BUY) || transactionType.equals(UserActivityType.SELL));

    StockQuote stockQuote = (StockQuote) quote;

    BigDecimal priceInUserCurrency;
    if (user.getCurrency().equals(stockQuote.getSupportedCurrency())) {
        priceInUserCurrency = BigDecimal.valueOf(
                (transactionType.equals(transactionType.BUY) ? stockQuote.getBid() : stockQuote.getAsk())
                        * quantity);
    } else {
        Preconditions.checkNotNull(currencyExchange);
        Preconditions.checkArgument(currencyExchange.getDailyLatestValue() != null);
        Preconditions.checkArgument(currencyExchange.getDailyLatestValue().doubleValue() > 0);

        priceInUserCurrency = currencyExchange.getDailyLatestValue().multiply(BigDecimal.valueOf(
                (transactionType.equals(transactionType.BUY) ? stockQuote.getBid() : stockQuote.getAsk())
                        * quantity));
    }
    return priceInUserCurrency;
}

From source file:org.apache.james.transport.mailets.remoteDelivery.InternetAddressConverter.java

public static InternetAddress[] convert(Collection<MailAddress> recipients) {
    Preconditions.checkNotNull(recipients);
    return FluentIterable.from(recipients).transform(new Function<MailAddress, InternetAddress>() {
        @Override//from   w w  w  .j  ava2  s. c o m
        public InternetAddress apply(MailAddress input) {
            return input.toInternetAddress();
        }
    }).toArray(InternetAddress.class);
}

From source file:com.google.cloud.dataflow.examples.complete.game.injector.InjectorUtils.java

/**
 * Builds a new Pubsub client and returns it.
 *///from   ww  w.ja  v a  2s.  co m
public static Pubsub getClient(final HttpTransport httpTransport, final JsonFactory jsonFactory)
        throws IOException {
    Preconditions.checkNotNull(httpTransport);
    Preconditions.checkNotNull(jsonFactory);
    GoogleCredential credential = GoogleCredential.getApplicationDefault(httpTransport, jsonFactory);
    if (credential.createScopedRequired()) {
        credential = credential.createScoped(PubsubScopes.all());
    }
    if (credential.getClientAuthentication() != null) {
        System.out.println("\n***Warning! You are not using service account credentials to "
                + "authenticate.\nYou need to use service account credentials for this example,"
                + "\nsince user-level credentials do not have enough pubsub quota,\nand so you will run "
                + "out of PubSub quota very quickly.\nSee "
                + "https://developers.google.com/identity/protocols/application-default-credentials.");
        System.exit(1);
    }
    HttpRequestInitializer initializer = new RetryHttpInitializerWrapper(credential);
    return new Pubsub.Builder(httpTransport, jsonFactory, initializer).setApplicationName(APP_NAME).build();
}

From source file:com.davidbracewell.ml.classification.linear.LibLinearModel.java

public static Feature[] toFeature(Instance vector) {
    int[] keys = VectorMath.nonZeroIndexes(Preconditions.checkNotNull(vector));
    Feature[] feature = new Feature[keys.length];
    for (int i = 0; i < keys.length; i++) {
        int fi = keys[i];
        feature[i] = new FeatureNode(fi + 1, vector.get(fi));
    }/* w w  w . j  av a2  s .co  m*/
    return feature;
}

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

/**
 * Vytvo tovrnu./*  ww  w.  j a  va2 s.  co m*/
 * 
 * @param checker
 *            validtor
 * @return tovrna
 */
public static DefaultMixedPatternBuilderFactory create(final MixedPatternChecker checker) {
    Preconditions.checkNotNull(checker);

    return new DefaultMixedPatternBuilderFactory(checker);
}