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

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

Introduction

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

Prototype

@Nullable
public static String emptyToNull(@Nullable String string) 

Source Link

Document

Returns the given string if it is nonempty; null otherwise.

Usage

From source file:com.google.gerrit.sshd.commands.SetProjectCommand.java

@Override
protected void run() throws Failure {
    ConfigInput configInput = new ConfigInput();
    configInput.requireChangeId = requireChangeID;
    configInput.submitType = submitType;
    configInput.useContentMerge = contentMerge;
    configInput.useContributorAgreements = contributorAgreements;
    configInput.useSignedOffBy = signedOffBy;
    configInput.state = state;/*from w ww .ja v  a  2s  .  com*/
    configInput.maxObjectSizeLimit = maxObjectSizeLimit;
    // Description is different to other parameters, null won't result in
    // keeping the existing description, it would delete it.
    if (Strings.emptyToNull(projectDescription) != null) {
        configInput.description = projectDescription;
    } else {
        configInput.description = projectControl.getProject().getDescription();
    }

    try {
        putConfig.apply(new ProjectResource(projectControl), configInput);
    } catch (RestApiException e) {
        throw die(e);
    }
}

From source file:org.sosy_lab.cpachecker.cfa.types.c.CSimpleType.java

@Override
public String toASTString(String pDeclarator) {
    List<String> parts = new ArrayList<>();

    if (isConst()) {
        parts.add("const");
    }/*w  w  w  .  ja v a 2  s  .c om*/
    if (isVolatile()) {
        parts.add("volatile");
    }

    if (isUnsigned) {
        parts.add("unsigned");
    } else if (isSigned) {
        parts.add("signed");
    }

    if (isLongLong) {
        parts.add("long long");
    } else if (isLong) {
        parts.add("long");
    } else if (isShort) {
        parts.add("short");
    }

    if (isImaginary) {
        parts.add("_Imaginary");
    }
    if (isComplex) {
        parts.add("_Complex");
    }

    parts.add(Strings.emptyToNull(type.toASTString()));
    parts.add(Strings.emptyToNull(pDeclarator));

    return Joiner.on(' ').skipNulls().join(parts);
}

From source file:de.bund.bfr.knime.pmm.js.common.Indep.java

/**
 * Sets the unit of this {@link Indep}.//from  w  ww.  j  a va 2  s .  co  m
 * 
 * Empty strings are converted to null.
 * 
 * @param unit
 *            the category to be set
 */
public void setUnit(String unit) {
    this.unit = Strings.emptyToNull(unit);
}

From source file:io.druid.query.groupby.RowBasedValueMatcherFactory.java

private boolean doesMatch(final Object raw, final Predicate<String> stringPredicate,
        final DruidLongPredicate longPredicate) {
    if (raw == null) {
        return stringPredicate.apply(null);
    } else if (raw instanceof List) {
        final List theList = (List) raw;
        if (theList.isEmpty()) {
            return stringPredicate.apply(null);
        } else {/*from ww  w. j a  v  a 2s . c o m*/
            for (Object o : theList) {
                if (doesMatch(o, stringPredicate, longPredicate)) {
                    return true;
                }
            }

            return false;
        }
    } else if (raw instanceof Long || raw instanceof Integer) {
        return longPredicate.applyLong(((Number) raw).longValue());
    } else {
        return stringPredicate.apply(Strings.emptyToNull(raw.toString()));
    }
}

From source file:com.google.gerrit.server.account.externalids.ExternalId.java

public static ExternalId createWithPassword(Key key, Account.Id accountId, @Nullable String email,
        String plainPassword) {//from  w  ww.  ja va 2 s.  c  om
    plainPassword = Strings.emptyToNull(plainPassword);
    String hashedPassword = plainPassword != null ? HashedPassword.fromPassword(plainPassword).encode() : null;
    return create(key, accountId, email, hashedPassword);
}

From source file:net.es.nsi.pce.pf.PfUtils.java

private static Optional<String> getValue(StringAttrConstraint constraint) {
    if (constraint == null) {
        return Optional.absent();
    }/* w  ww  . j  a  v  a 2s .  com*/

    return Optional.fromNullable(Strings.emptyToNull(constraint.getValue()));
}

From source file:org.hopestarter.wallet.Configuration.java

public String getOwnName() {
    return Strings.emptyToNull(prefs.getString(PREFS_KEY_OWN_NAME, "").trim());
}

From source file:de.bund.bfr.knime.pmm.js.common.Misc.java

/**
 * Sets the unit of this {@link Misc}.//  w w w.  j av a  2  s.  com
 * 
 * Empty strings are converted to null.
 * 
 * @param unit the unit to be set
 */
public void setUnit(final String unit) {
    this.unit = Strings.emptyToNull(unit);
}

From source file:org.dcache.alarms.server.LogEntryServerWrapper.java

public void setEmailPassword(String emailPassword) {
    this.emailPassword = Strings.emptyToNull(emailPassword);
}

From source file:com.googlesource.gerrit.plugins.github.notification.WebhookServlet.java

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    if (Strings.emptyToNull(config.webhookUser) == null) {
        logger.error("No webhookUser defined: cannot process GitHub events");
        resp.sendError(SC_INTERNAL_SERVER_ERROR);
        return;/*  ww w.j  av  a  2s . c  o  m*/
    }

    WebhookEventHandler<?> handler = getWebhookHandler(req.getHeader("X-Github-Event"));
    if (handler == null) {
        resp.sendError(SC_NOT_FOUND);
        return;
    }

    try (BufferedReader reader = req.getReader()) {
        String body = Joiner.on("\n").join(CharStreams.readLines(reader));
        if (!validateSignature(req.getHeader("X-Hub-Signature"), body, req.getCharacterEncoding())) {
            logger.error("Signature mismatch to the payload");
            resp.sendError(SC_FORBIDDEN);
            return;
        }

        session.get().setUserAccountId(Account.Id.fromRef(config.webhookUser));
        GitHubLogin login = loginProvider.get(config.webhookUser);
        if (login == null || !login.isLoggedIn()) {
            logger.error("Cannot login to github as {}. {}.webhookUser is not correctly configured?",
                    config.webhookUser, GitHubConfig.CONF_SECTION);
            resp.setStatus(SC_INTERNAL_SERVER_ERROR);
            return;
        }
        requestScopedLoginProvider.get(req).login(login.getToken());

        if (callHander(handler, body)) {
            resp.setStatus(SC_NO_CONTENT);
        } else {
            resp.sendError(SC_INTERNAL_SERVER_ERROR);
        }
    }
}