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.google.gerrit.server.account.PutStatus.java

public Response<String> apply(IdentifiedUser user, Input input)
        throws ResourceNotFoundException, OrmException, IOException {
    if (input == null) {
        input = new Input();
    }//from  w  ww .j  a va 2  s. co  m

    String newStatus = input.status;
    Account a = dbProvider.get().accounts().atomicUpdate(user.getAccountId(), new AtomicUpdate<Account>() {
        @Override
        public Account update(Account a) {
            a.setStatus(Strings.nullToEmpty(newStatus));
            return a;
        }
    });
    if (a == null) {
        throw new ResourceNotFoundException("account not found");
    }
    byIdCache.evict(a.getId());
    return Strings.isNullOrEmpty(a.getStatus()) ? Response.none() : Response.ok(a.getStatus());
}

From source file:com.commercehub.bamboo.plugins.gitlab.GitLabWebRepositoryViewer.java

@Override
public void setWebRepositoryUrl(String webRepositoryUrl) {
    this.webRepositoryUrl = Strings.nullToEmpty(webRepositoryUrl);
}

From source file:org.mitre.jwt.signer.AbstractJwtSigner.java

@Override
public boolean verify(String jwtString) throws NoSuchAlgorithmException {
    // split on the dots
    List<String> parts = Lists.newArrayList(Splitter.on(".").split(jwtString));

    if (parts.size() != 3) {
        throw new IllegalArgumentException("Invalid JWT format.");
    }/*from  w w w .  ja va 2s . c  o m*/

    String h64 = parts.get(0);
    String c64 = parts.get(1);
    String s64 = parts.get(2);

    String expectedSignature = generateSignature(h64 + "." + c64);

    return Strings.nullToEmpty(s64).equals(Strings.nullToEmpty(expectedSignature));

}

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

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

From source file:com.zimbra.cs.mailbox.Document.java

public String getDescription() {
    return Strings.nullToEmpty(description);
}

From source file:com.b2international.snowowl.datastore.cdo.CDOCommitInfoUtils.java

/**
 * Sugar for getting the UUID from the commit info.
 * <br>Same as {@code #getUuid(CDOCommitInfo#getComment())}.
 * @see #getUuid(String)/*from ww  w . ja  va  2 s.c  o m*/
 */
public static String getUuid(final CDOCommitInfo commitInfo) {
    Preconditions.checkNotNull(commitInfo, "Commit info argument cannot be null.");
    if (commitInfo instanceof ICDOCommitInfoWithUuid) {
        return ((ICDOCommitInfoWithUuid) commitInfo).getUuid();
    }
    return getUuid(Strings.nullToEmpty(commitInfo.getComment()));
}

From source file:io.janusproject.kernel.bic.LoggingSkill.java

@Override
public void error(Object message, Throwable exception) {
    if (this.logger.isLoggable(Level.SEVERE)) {
        String m = Strings.nullToEmpty(message == null ? null : message.toString());
        if (exception != null) {
            this.logger.log(Level.SEVERE, m, exception);
        } else {/*from  w w w .j ava2  s  .  c  o m*/
            this.logger.log(Level.SEVERE, m);
        }
    }
}

From source file:org.sosy_lab.cpachecker.util.predicates.mathsat5.Mathsat5InterpolatingProver.java

@Override
public BooleanFormula getInterpolant(List<Integer> formulasOfA) throws SolverException {
    Preconditions.checkState(curEnv != 0);

    int[] groupsOfA = new int[formulasOfA.size()];
    int i = 0;// w  w w . j a  v  a2s .co  m
    for (Integer f : formulasOfA) {
        groupsOfA[i++] = f;
    }

    long itp;
    try {
        itp = msat_get_interpolant(curEnv, groupsOfA);
    } catch (IllegalArgumentException e) {
        String msg = Strings.nullToEmpty(e.getMessage());
        if (msg.contains("impossible to build a suitable congruence graph")
                || msg.contains("splitting of AB-mixed terms not supported")) {
            // This is not a bug in CPAchecker, but a problem of MathSAT which happens during interpolation
            throw new SolverException(e.getMessage(), e);
        }
        throw e;
    }

    if (!useSharedEnv) {
        itp = msat_make_copy_from(mgr.getEnvironment(), itp, curEnv);
    }
    return mgr.encapsulateBooleanFormula(itp);
}

From source file:com.android.tools.idea.npw.template.GenerateIconsStep.java

@Override
protected void onEntering() {
    TemplateHandle templateHandle = getModel().getTemplateHandle();
    String iconNameExpression = templateHandle.getMetadata().getIconName();
    String iconName = null;//from ww  w  .  j a v  a2  s. c o m
    if (iconNameExpression != null && !iconNameExpression.isEmpty()) {
        StringEvaluator evaluator = new StringEvaluator();
        iconName = evaluator.evaluate(iconNameExpression, getModel().getTemplateValues());
    }

    myGenerateIconsPanel.setOutputName(Strings.nullToEmpty(iconName));
}

From source file:org.graylog.plugins.metrics.console.MetricsConsoleReporterConfiguration.java

public PrintStream getOutputStream() {
    final String streamName = Strings.nullToEmpty(outputStream).toLowerCase(Locale.ENGLISH);
    switch (streamName) {
    case "stderr":
    case "err":
        return System.err;
    case "stdout":
    case "out":
    default:/* w w w. j  a  v  a  2  s.co m*/
        return System.out;
    }
}