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.github.vbauer.yta.service.fraction.impl.DetectionApiImpl.java

/**
 * {@inheritDoc}/*w w w  .  j  ava 2s  . co m*/
 */
@Nonnull
@Override
public Optional<Language> detect(@Nullable final String text, @Nullable final TextFormat format) {
    final Map<String, Object> params = ImmutableMap.<String, Object>builder()
            .put(ATTR_TEXT, Strings.nullToEmpty(text)).put(ATTR_FORMAT, TextFormat.getOrDefault(format).code())
            .build();

    final LanguageInfo data = callMethod(LanguageInfo.class, METHOD_DETECT, params);
    ApiStatus.check(data.code());

    return Preconditions.checkNotNull(LanguageConverter.INSTANCE.convert(data));
}

From source file:org.killbill.commons.skeleton.modules.JerseyBaseServerModule.java

public JerseyBaseServerModule(
        final Map<String, ArrayList<Entry<Class<? extends Filter>, Map<String, String>>>> filters,
        final Map<String, ArrayList<Entry<Class<? extends Filter>, Map<String, String>>>> filtersRegex,
        final Map<String, Class<? extends HttpServlet>> servlets,
        final Map<String, Class<? extends HttpServlet>> servletsRegex,
        final Map<String, Class<? extends HttpServlet>> jaxrsServlets,
        final Map<String, Class<? extends HttpServlet>> jaxrsServletsRegex, final String jaxrsUriPattern,
        final Collection<String> jaxrsResources, final List<String> jerseyFilters,
        final Map<String, String> jerseyParams) {
    super(filters, filtersRegex, servlets, servletsRegex, jaxrsServlets, jaxrsServletsRegex, jaxrsUriPattern,
            jaxrsResources);//from  w  w w  .  ja  v a2  s  .c o  m

    String manuallySpecifiedRequestFilters = Strings
            .nullToEmpty(jerseyParams.remove(JERSEY_CONTAINER_REQUEST_FILTERS));
    String manuallySpecifiedResponseFilters = Strings
            .nullToEmpty(jerseyParams.remove(JERSEY_CONTAINER_RESPONSE_FILTERS));
    if (!jerseyFilters.isEmpty()) {
        if (!manuallySpecifiedRequestFilters.isEmpty()) {
            manuallySpecifiedRequestFilters += ";";
        }
        if (!manuallySpecifiedResponseFilters.isEmpty()) {
            manuallySpecifiedResponseFilters += ";";
        }
    }
    final String containerRequestFilters = manuallySpecifiedRequestFilters + joiner.join(jerseyFilters);
    final String containerResponseFilters = manuallySpecifiedResponseFilters
            + joiner.join(Lists.reverse(jerseyFilters));

    this.jerseyParams = new ImmutableMap.Builder<String, String>();
    if (!containerRequestFilters.isEmpty()) {
        this.jerseyParams.put(JERSEY_CONTAINER_REQUEST_FILTERS, containerRequestFilters);
    }
    if (!containerResponseFilters.isEmpty()) {
        this.jerseyParams.put(JERSEY_CONTAINER_RESPONSE_FILTERS, containerResponseFilters);
    }

    // The LoggingFilter will log the body by default, which breaks StreamingOutput
    final String disableEntityLogging = Objects
            .firstNonNull(Strings.emptyToNull(jerseyParams.remove(JERSEY_DISABLE_ENTITYLOGGING)), "true");
    this.jerseyParams.put(JERSEY_DISABLE_ENTITYLOGGING, disableEntityLogging).putAll(jerseyParams);
}

From source file:ec.tss.TsCollection.java

TsCollection(@Nullable String name, @Nonnull TsMoniker moniker) {
    m_name = Strings.nullToEmpty(name);
    m_moniker = moniker;/*w ww . j av  a 2 s. c  om*/
    m_metadata = null;
    m_ts = new ArrayList<>();
    m_info = m_moniker.getSource() == null ? TsInformationType.UserDefined : TsInformationType.None;
    m_set = null;
    m_invalidDataCause = null;
}

From source file:io.macgyver.core.auth.UserManager.java

public boolean authenticate(String username, String password) {
    try {//from ww  w .  j  av  a 2s  .c om
        String q = "match (u:User) where u.username={username} return u.scryptHash";
        ObjectNode n = new ObjectMapper().createObjectNode();
        n.put("username", username);
        JsonNode userNode = neo4j.execCypher(q, "username", username).toBlocking().firstOrDefault(null);
        if (userNode != null) {

            String hashValue = Strings.emptyToNull(userNode.asText());
            if (hashValue == null) {
                return false;
            }
            try {
                return SCryptUtil.check(password, Strings.nullToEmpty(hashValue));
            } catch (IllegalArgumentException e) {
                // if the hash is invalid, we'll get an
                // IllegalArgumentException
                // This could happen if the hashed password was set to
                // something to prevent login
                // no need to log a whole stack trace for this
                logger.info("auth error: " + e.toString());
                return false;
            }

        } else {
            return false;
        }
    }

    catch (Exception e) {
        logger.warn("auth error", e);
        return false;
    }

}

From source file:io.druid.segment.filter.ExtractionFilter.java

private List<Filter> makeFilters(BitmapIndexSelector selector) {
    Indexed<String> allDimVals = selector.getDimensionValues(dimension);
    final List<Filter> filters = Lists.newArrayList();
    if (allDimVals == null) {
        allDimVals = new Indexed<String>() {
            @Override/*www. ja va2s  .c o m*/
            public Iterator<String> iterator() {
                return null;
            }

            @Override
            public Class<? extends String> getClazz() {
                return null;
            }

            @Override
            public int size() {
                return 1;
            }

            @Override
            public String get(int index) {
                return null;
            }

            @Override
            public int indexOf(String value) {
                return 0;
            }
        };
    }

    for (int i = 0; i < allDimVals.size(); i++) {
        String dimVal = allDimVals.get(i);
        if (value.equals(Strings.nullToEmpty(fn.apply(dimVal)))) {
            filters.add(new SelectorFilter(dimension, dimVal));
        }
    }

    return filters;
}

From source file:net.monofraps.gradlebukkit.extensions.Bukkit.java

public String getArtifactSlug() {
    String artSlug = Strings.nullToEmpty(artifactSlug);
    if (artSlug.isEmpty()) {
        artSlug = "latest";
    }//from   www .ja va  2 s. c om

    if (!getChannel().isEmpty()) {
        artSlug += "-" + getChannel();
    }

    return artSlug;
}

From source file:com.streamsets.datacollector.cluster.YARNStatusParser.java

public String parseStatus(Collection<String> lines) {
    for (String line : lines) {
        for (Pattern pattern : PATTERNS) {
            Matcher matcher = pattern.matcher(line);
            if (matcher.matches()) {
                String input = matcher.group(1);
                String output = Strings.nullToEmpty(STATE_MAP.get(input));
                if (!output.isEmpty()) {
                    return output;
                }// w  ww  .j av  a 2 s  .co m
            }
        }
    }
    String msg = "Could not match any YARN status";
    LOG.error(msg + ":" + Joiner.on("\n").join(lines));
    throw new IllegalStateException(msg + ". See logs.");
}

From source file:org.sonar.core.issue.FieldDiffs.java

public static FieldDiffs parse(@Nullable String s) {
    FieldDiffs diffs = new FieldDiffs();
    if (isNullOrEmpty(s)) {
        return diffs;
    }/*from   w  w w. j  a  va2  s . co  m*/
    Iterable<String> fields = FIELDS_SPLITTER.split(s);
    for (String field : fields) {
        String[] keyValues = field.split("=");
        if (keyValues.length == 2) {
            String[] values = keyValues[1].split("\\|");
            String oldValue = "";
            String newValue = "";
            if (values.length == 1) {
                newValue = Strings.nullToEmpty(values[0]);
            } else if (values.length == 2) {
                oldValue = Strings.nullToEmpty(values[0]);
                newValue = Strings.nullToEmpty(values[1]);
            }
            diffs.setDiff(keyValues[0], oldValue, newValue);
        } else {
            diffs.setDiff(keyValues[0], "", "");
        }
    }
    return diffs;
}

From source file:org.obm.sync.book.Website.java

@Override
public int hashCode() {
    return Objects.hashCode(Strings.nullToEmpty(label).toLowerCase(), url);
}

From source file:com.googlesource.gerrit.plugins.github.wizard.RepositoriesListController.java

@Override
public void doAction(IdentifiedUser user, GitHubLogin hubLogin, HttpServletRequest req,
        HttpServletResponse resp, ControllerErrors errors) throws ServletException, IOException {
    String organisation = req.getParameter("organisation");

    JsonArray jsonRepos = new JsonArray();
    int numRepos = 0;
    PagedIterator<GHRepository> repoIter = getRepositories(hubLogin, organisation).iterator();

    while (repoIter.hasNext() && numRepos < config.repositoryListLimit) {
        GHRepository ghRepository = repoIter.next();
        JsonObject repository = new JsonObject();
        String projectName = organisation + "/" + ghRepository.getName();
        if (projects.get(Project.NameKey.parse(projectName)) == null) {
            repository.add("name", new JsonPrimitive(ghRepository.getName()));
            repository.add("organisation", new JsonPrimitive(organisation));
            repository.add("description",
                    new JsonPrimitive(Strings.nullToEmpty(ghRepository.getDescription())));
            repository.add("private", new JsonPrimitive(ghRepository.isPrivate()));
            jsonRepos.add(repository);/* ww  w  .  j av  a  2 s  .  c  o m*/
            numRepos++;
        }
    }

    resp.getWriter().println(jsonRepos.toString());
}