Example usage for com.google.common.base Strings nullToEmpty

List of usage examples for com.google.common.base Strings nullToEmpty

Introduction

In this page you can find the example usage for com.google.common.base Strings nullToEmpty.

Prototype

public static String nullToEmpty(@Nullable String string) 

Source Link

Document

Returns the given string if it is non-null; the empty string otherwise.

Usage

From source file:com.zimbra.cs.db.HSQLDB.java

/**
 * Populates ZIMBRA and MBOXGROUP1 schema.
 * @param zimbraServerDir the directory that contains the ZimbraServer project
 * @throws Exception/*  w  w  w .j  a v  a2 s  .c o m*/
 */
public static void createDatabase(String zimbraServerDir, boolean isOctopus) throws Exception {
    zimbraServerDir = Strings.nullToEmpty(zimbraServerDir);
    PreparedStatement stmt = null;
    ResultSet rs = null;
    DbConnection conn = DbPool.getConnection();
    try {
        stmt = conn.prepareStatement("SELECT COUNT(*) FROM information_schema.schemata WHERE schema_name = ?");
        stmt.setString(1, "ZIMBRA");
        rs = stmt.executeQuery();
        if (rs.next() && rs.getInt(1) > 0) {
            return; // already exists
        }
        execute(conn, zimbraServerDir + "src/db/hsqldb/db.sql");
        execute(conn, zimbraServerDir + "src/db/hsqldb/create_database.sql");
        if (isOctopus) {
            execute(conn, "src/db/hsqldb/create_octopus_tables.sql");
        }
    } finally {
        DbPool.closeResults(rs);
        DbPool.quietCloseStatement(stmt);
        DbPool.quietClose(conn);
    }
}

From source file:org.obiba.onyx.quartz.core.engine.questionnaire.question.Attributes.java

/**
 * @param namespace//from w ww  . j  ava 2s  .co  m
 * @param name
 * @param value
 * @param locale
 * @return
 */
private static Attribute buildAttribute(String namespace, String name, String value, Locale locale) {
    Attribute.Builder attributeBuilder = Attribute.Builder.newAttribute();
    attributeBuilder.withNamespace(Strings.emptyToNull(namespace));
    attributeBuilder.withName(name);
    attributeBuilder.withValue(Strings.nullToEmpty(value));
    attributeBuilder.withLocale(locale);
    Attribute attribute = attributeBuilder.build();
    return attribute;
}

From source file:org.glowroot.agent.model.ErrorMessage.java

public static ErrorMessage create(@Nullable String message, java.lang. /*@Nullable*/ Throwable t,
        AtomicInteger transactionThrowableFrameCount) {
    if (t == null) {
        return ImmutableErrorMessage.of(Strings.nullToEmpty(message), null);
    } else {/*from  w w  w .  j a  v a2  s  .  co  m*/
        // "root cause" exception message is generally much more useful than generic wrapper
        // message from log statement
        return ImmutableErrorMessage.of(Throwables.getBestMessage(t),
                buildThrowableInfo(t, null, transactionThrowableFrameCount, 0));
    }
}

From source file:pzalejko.iot.hardware.home.core.service.configuration.DefaultApplicationConfiguration.java

public DefaultApplicationConfiguration(Properties properties) {
    checkNotNull(properties);//from   w ww.  ja  v a2s.  c  om

    final String value = Strings.nullToEmpty(properties.getProperty(SHUTDOWN_KEY));
    checkArgument(!value.isEmpty());

    shutDownDelay = Integer.parseInt(value);
}

From source file:scoutdoc.main.check.CheckstyleFileWriter.java

public static void write(List<Check> list, PrintWriter w) {
    w.println(XML_VERSION);//from   w  w  w  .  j  av a  2s  .  c  o m
    w.println(CHECKSTYLE_OPEN);

    Multimap<String, Check> multimap = ArrayListMultimap.create();

    for (Check check : list) {
        String filePath = PageUtility.toFile(check.getPage()).getAbsolutePath();
        multimap.put(filePath, check);
    }

    for (String file : multimap.keySet()) {
        w.println("<file name=\"" + file + "\">");
        for (Check check : multimap.get(file)) {
            w.print("<error");
            w.print(" line=\"" + check.getLine() + "\"");
            w.print(" column=\"" + check.getColumn() + "\"");
            w.print(" severity=\"" + Objects.firstNonNull(check.getSeverity(), "") + "\"");
            w.print(" message=\"" + Strings.nullToEmpty(check.getMessage()) + "\"");
            w.print(" source=\"" + Strings.nullToEmpty(check.getSource()) + "\"");
            w.println("/>");
        }
        w.println(FILE_CLOSE);
    }
    w.println(CHECKSTYLE_CLOSE);
}

From source file:de.compeople.commons.net.proxy.win32.ProxySelectorPACUtils.java

/**
 * @param pacFindProxyForUrlResult/*  www  .  ja v a  2  s .co  m*/
 * @return
 */
public static List<Proxy> getProxies(String pacFindProxyForUrlResult) {
    if (Strings.nullToEmpty(pacFindProxyForUrlResult).trim().length() == 0) {
        return ProxySelectorUtils.getProxyListDirectAccessOnly();
    }

    final List<Proxy> result = new ArrayList<Proxy>();
    final Scanner scanner = new Scanner(pacFindProxyForUrlResult);
    scanner.useDelimiter(";");
    while (scanner.hasNext()) {
        final String pacProxy = scanner.next().trim();
        final Proxy proxy = getProxy(pacProxy);
        if (proxy != null) {
            result.add(proxy);
        }
    }

    return result;
}

From source file:org.gbif.ws.server.filter.RequestHeaderParamUpdateFilter.java

private static void processLanguage(HttpRequestContext request) {
    String language = Strings.nullToEmpty(request.getQueryParameters().getFirst("language")).trim();
    if (!language.isEmpty()) {
        // overwrite http language
        request.getRequestHeaders().putSingle(HttpHeaders.ACCEPT_LANGUAGE, language.toLowerCase());
    }/*from   w w  w . j a v  a2 s  .  c o m*/
}

From source file:com.google.gerrit.httpd.plugins.ContextMapper.java

ContextMapper(String contextPath) {
    base = Strings.nullToEmpty(contextPath) + PLUGINS_PREFIX;
    authorizedBase = Strings.nullToEmpty(contextPath) + AUTHORIZED_PREFIX;
}

From source file:ph.devcon.android.util.Util.java

public static String nullToEmpty(String s) {
    return Strings.nullToEmpty(s);
}

From source file:com.google.gerrit.server.group.GetDescription.java

@Override
public String apply(GroupResource resource) throws MethodNotAllowedException {
    AccountGroup group = resource.toAccountGroup();
    if (group == null) {
        throw new MethodNotAllowedException();
    }/*from   w w w.j ava  2  s.c  o  m*/
    return Strings.nullToEmpty(group.getDescription());
}