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.aurora.common.inject.Bindings.java

/**
 * Equivalent to calling {@code requireBinding(binder, Key.get(required))}.
 *//*from   w w  w.j  a  v  a 2  s.co m*/
public static void requireBinding(Binder binder, Class<?> required) {
    requireBinding(binder, Key.get(Preconditions.checkNotNull(required)));
}

From source file:com.dangdang.config.service.easyzk.support.spring.ZookeeperSourceFactory.java

public static PropertySources create(ConfigFactory configFactory, String... nodes) {
    Preconditions.checkNotNull(configFactory);
    Preconditions.checkNotNull(nodes);/*from w  ww.jav a2s.co  m*/
    ConfigNode[] configNodes = new ConfigNode[nodes.length];
    for (int i = 0; i < nodes.length; i++) {
        configNodes[i] = configFactory.getConfigNode(nodes[i]);
    }

    return create(configNodes);
}

From source file:com.facebook.buck.util.MoreMaps.java

public static <K1, K2, V> ImmutableMap<K2, V> transformKeys(Map<K1, V> map,
        Function<? super K1, K2> transformer) {
    ImmutableMap.Builder<K2, V> transformedMap = ImmutableMap.builder();
    for (Map.Entry<K1, V> ent : map.entrySet()) {
        transformedMap.put(Preconditions.checkNotNull(transformer.apply(ent.getKey())), ent.getValue());
    }/*from   w w w .  ja  v a2  s  .c  o m*/
    return transformedMap.build();
}

From source file:cz.cuni.mff.ms.brodecva.botnicek.ide.utils.data.Tables.java

/**
 * Pevede reprezentace tabulky.//w  w w  .  j  ava 2  s. com
 * 
 * @param tableMap
 *            tabulka ve form dvojitho zobrazen
 * @return tabulka
 */
public static <R, C, V> Table<R, C, V> toImmutableTable(
        final Map<? extends R, ? extends Map<? extends C, ? extends V>> tableMap) {
    Preconditions.checkNotNull(tableMap);

    final Builder<R, C, V> builder = ImmutableTable.builder();

    final Set<? extends Entry<? extends R, ? extends Map<? extends C, ? extends V>>> rowEntries = tableMap
            .entrySet();
    for (final Entry<? extends R, ? extends Map<? extends C, ? extends V>> rowEntry : rowEntries) {
        final R rowKey = rowEntry.getKey();

        final Map<? extends C, ? extends V> row = rowEntry.getValue();
        final Set<? extends Entry<? extends C, ? extends V>> cellEntries = row.entrySet();
        for (final Entry<? extends C, ? extends V> cellEntry : cellEntries) {
            final C columnKey = cellEntry.getKey();
            final V value = cellEntry.getValue();

            builder.put(rowKey, columnKey, value);
        }
    }

    return builder.build();
}

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

public static InternetAddress[] convert(Collection<MailAddress> recipients) {
    Preconditions.checkNotNull(recipients);
    return recipients.stream().map(MailAddress::toInternetAddress).toArray(InternetAddress[]::new);
}

From source file:ezbake.common.openshift.OpenShiftUtil.java

public static String getRepoDir() {
    return Preconditions.checkNotNull(System.getenv(OPENSHIFT_REPO_DIR));
}

From source file:org.trancecode.io.Paths.java

public static String getName(final String path) {
    Preconditions.checkNotNull(path);
    return path.replaceAll("/+$", "").replaceAll(".*/", "");
}

From source file:minium.internal.Paths.java

public static List<URL> toURLs(String urlPath) {
    Preconditions.checkNotNull(urlPath);

    ClassLoader loader = firstNonNull(Thread.currentThread().getContextClassLoader(),
            Paths.class.getClassLoader());

    if (urlPath.startsWith(CLASSPATH_PROTOCOL)) {
        String path = urlPath.substring(CLASSPATH_PROTOCOL.length());
        return singletonOrEmpty(loader.getResource(path));
    } else if (urlPath.startsWith(CLASSPATH_WILDCARD_PROTOCOL)) {
        String path = urlPath.substring(CLASSPATH_WILDCARD_PROTOCOL.length());
        try {/*  ww  w.j a  v  a2  s.  com*/
            return Collections.list(loader.getResources(path));
        } catch (IOException e) {
            return singletonOrEmpty(loader.getResource(path));
        }
    } else {
        try {
            return singletonOrEmpty(new URL(urlPath));
        } catch (MalformedURLException e) {
            // let's assume it's a local file
            File file = new File(urlPath);
            Preconditions.checkArgument(file.exists(), "File %s does not exist", file);
            Preconditions.checkArgument(file.isFile(), "%s is not a file", file);

            try {
                return singletonOrEmpty(file.toURI().toURL());
            } catch (MalformedURLException e1) {
                throw Throwables.propagate(e1);
            }
        }
    }
}

From source file:org.opendaylight.tcpmd5.nio.MD5ChannelOptions.java

static MD5ChannelOptions create(final KeyAccessFactory keyAccessFactory, final NetworkChannel ch) {
    final KeyAccess access = keyAccessFactory.getKeyAccess(Preconditions.checkNotNull(ch));
    return new MD5ChannelOptions(ch, access);
}

From source file:org.apache.apex.malhar.lib.utils.serde.ArraySerde.java

/**
 * Serializer and Deserializer need different constructor, so use static factory method to wrap.
 * The ArraySerde returned by newSerializer can only used for serialization
 *//*  ww w.  java 2s  .  c  o m*/
public static <T> ArraySerde<T> newSerializer(Serde<T> itemSerde) {
    return new ArraySerde<T>(Preconditions.checkNotNull(itemSerde));
}