Example usage for com.google.common.base Objects firstNonNull

List of usage examples for com.google.common.base Objects firstNonNull

Introduction

In this page you can find the example usage for com.google.common.base Objects firstNonNull.

Prototype

@CheckReturnValue
@Deprecated
public static <T> T firstNonNull(@Nullable T first, @Nullable T second) 

Source Link

Document

Returns the first of two given parameters that is not null , if either is, or otherwise throws a NullPointerException .

Usage

From source file:org.obm.push.spushnik.Main.java

public static void main(String... args) throws Exception {
    start(Objects.firstNonNull(VMArgumentsUtils.integerArgumentValue("spushnikPort"), DEFAULT_SERVER_PORT))
            .join();//from  w  w w .j  a v a2s  . c o  m
}

From source file:co.cask.cdap.shell.CLIMain.java

public static void main(String[] args) throws Exception {
    String hostname = Objects.firstNonNull(System.getenv(Constants.EV_HOSTNAME), "localhost");

    CLIConfig config = new CLIConfig(hostname);
    CLIMain shell = new CLIMain(config);

    if (args.length == 0) {
        shell.startShellMode(System.out);
    } else {//ww  w. jav  a 2 s.com
        shell.processArgs(args, System.out);
    }
}

From source file:com.google.u2f.gaedemo.storage.SecretKeys.java

public static void generate() {
    SecretKeys keys = Objects.firstNonNull(ofy().load().type(SecretKeys.class).id("singleton").now(),
            new SecretKeys());
    keys.generateNewKeys();//from   w ww.  j av a2 s.  c o m
    ofy().save().entity(keys).now();
}

From source file:com.google.api.explorer.client.base.NameHelper.java

/**
 * Generate the title for the specified title and name.
 *
 * @param title Title to directly return or {@code null}.
 * @param name Name which should be turned into a title if the title is null.
 * @return Printable title.//from   w  w  w . j a  v  a  2  s  . co  m
 */
public static String generateDisplayTitle(@Nullable String title, String name) {
    return Objects.firstNonNull(title, Preconditions.checkNotNull(name) + " API");
}

From source file:com.opengamma.core.LinkUtils.java

/**
 * Gets the best representative object from the specified link.
 * <p>//from   w  w  w. j  av  a2s  .c o  m
 * This will return either the object identifier or the external bundle, which may be empty.
 * 
 * @param link  the link, not null
 * @return the best representative object, not null
 */
public static Object best(Link<?> link) {
    ArgumentChecker.notNull(link, "link");
    ObjectId objectId = link.getObjectId();
    ExternalIdBundle bundle = link.getExternalId();
    return Objects.firstNonNull(objectId, bundle);
}

From source file:co.cask.cdap.common.lang.ClassLoaders.java

/**
 * Loads the class with the given class name with the given classloader. If it is {@code null},
 * load the class with the ClassLoader of the caller object.
 *
 * @param className Name of the class to load.
 * @param classLoader Classloader for loading the class. It could be {@code null}.
 * @param caller The object who call this method.
 * @return The loaded class.// www  .  j a  v a  2s . c o  m
 * @throws ClassNotFoundException If failed to load the given class.
 */
public static Class<?> loadClass(String className, @Nullable ClassLoader classLoader, Object caller)
        throws ClassNotFoundException {
    ClassLoader cl = Objects.firstNonNull(classLoader, caller.getClass().getClassLoader());
    return cl.loadClass(className);
}

From source file:co.cask.cdap.data2.dataset2.DatasetDefinitionRegistries.java

public static void register(String moduleClassName, @Nullable ClassLoader classLoader,
        DatasetDefinitionRegistry registry)
        throws ClassNotFoundException, IllegalAccessException, InstantiationException, TypeConflictException {

    ClassLoader systemClassLoader = DatasetDefinitionRegistries.class.getClassLoader();

    // Either uses the given classloader or the system one
    ClassLoader moduleClassLoader = Objects.firstNonNull(classLoader, systemClassLoader);

    Class<? extends DatasetModule> moduleClass;
    try {//  w  w w .j a va  2  s.  com
        moduleClass = loadClass(moduleClassLoader, moduleClassName);
    } catch (ClassNotFoundException e) {
        // If failed to load from the given classloader (if not null), try to load it from system classloader
        if (classLoader == null || classLoader.equals(systemClassLoader)) {
            throw e;
        }
        try {
            moduleClass = loadClass(systemClassLoader, moduleClassName);
        } catch (ClassNotFoundException e2) {
            e.addSuppressed(e2);
            throw e;
        }
    }

    DatasetModule module = DatasetModules.getDatasetModule(moduleClass);
    module.register(registry);
}

From source file:com.google.jenkins.plugins.metadata.scm.JenkinsUtils.java

/**
 * Similar to Jenkins#getExtensionList() but return empty collection in case
 * running without Jenkins./*  w w  w  .  j  a  va2  s  . c om*/
 */
public static <T extends ExtensionPoint> List<T> getExtensionList(Class<T> klass) {
    checkNotNull(klass);

    Jenkins jenkins = Jenkins.getInstance();
    if (jenkins == null) {
        return ImmutableList.<T>of();
    } else {
        return Objects.firstNonNull(jenkins.getExtensionList(klass), ImmutableList.<T>of());
    }
}

From source file:fr.xebia.cloud.cloudinit.FreemarkerUtils.java

/**
 * //from  w w w. jav a 2s.  c o  m
 * @param rootMap
 *            root node of the freemarker datamodel.
 * @param templatePath
 *            classpath of the template
 * @return generated file
 */
@SuppressWarnings("unchecked")
@Nonnull
public static String generate(@Nullable Map<String, Object> rootMap, @Nonnull String templatePath) {
    Preconditions.checkNotNull(templatePath, "'templatePath' can NOT be null");
    rootMap = (Map<String, Object>) Objects.firstNonNull(rootMap, Collections.emptyMap());

    try {
        Configuration cfg = new Configuration();
        cfg.setClassForTemplateLoading(FreemarkerUtils.class, "/");

        Template template = cfg.getTemplate(templatePath);
        Writer out = new StringWriter();
        template.process(rootMap, out);
        return out.toString();
    } catch (IOException e) {
        throw Throwables.propagate(e);
    } catch (TemplateException e) {
        throw Throwables.propagate(e);
    }
}

From source file:com.cloudbees.mail.FreemarkerUtils.java

/**
 * @param rootMap      root node of the freemarker datamodel.
 * @param templatePath classpath classpath path of the template (e.g. "/my-template.ftl")
 * @return generated file/*from  www  .  j a v  a 2s.  c o  m*/
 */
@SuppressWarnings("unchecked")
@Nonnull
public static String generate(@Nullable Map<String, ? extends Object> rootMap, @Nonnull String templatePath) {
    Preconditions.checkNotNull(templatePath, "'templatePath' can NOT be null");
    rootMap = (Map<String, Object>) Objects.firstNonNull(rootMap, Collections.emptyMap());

    try {
        Configuration cfg = new Configuration();
        cfg.setClassForTemplateLoading(FreemarkerUtils.class, "/");

        Template template = cfg.getTemplate(templatePath);
        Writer out = new StringWriter();
        template.process(rootMap, out);
        return out.toString();
    } catch (IOException e) {
        throw Throwables.propagate(e);
    } catch (TemplateException e) {
        throw Throwables.propagate(e);
    }
}