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.devtools.build.xcode.plmerge.MergingArguments.java

/**
 * Build MergingArguments from a plmerge protobuf.
 *//*from   w ww.  j  a va2 s  .  c om*/
public MergingArguments(Control control) {
    ImmutableList.Builder<Path> sourceFilePathsBuilder = new Builder<>();
    for (String pathString : control.getSourceFileList()) {
        sourceFilePathsBuilder.add(fileSystem.getPath(pathString));
    }
    sourceFilePaths = sourceFilePathsBuilder.build();

    ImmutableList.Builder<Path> immutableSourceFilePathsBuilder = new Builder<>();
    for (String pathString : control.getImmutableSourceFileList()) {
        immutableSourceFilePathsBuilder.add(fileSystem.getPath(pathString));
    }
    immutableSourceFilePaths = immutableSourceFilePathsBuilder.build();

    outFile = control.getOutFile();
    variableSubstitutions = control.getVariableSubstitutionMap();

    primaryBundleId = Strings.emptyToNull(control.getPrimaryBundleId());
    fallbackBundleId = Strings.emptyToNull(control.getFallbackBundleId());
    executableName = Strings.emptyToNull(control.getExecutableName());
}

From source file:org.gradle.api.publish.ivy.internal.artifact.AbstractIvyArtifact.java

@Nullable
@Override
public String getClassifier() {
    return Strings.emptyToNull(classifier != null ? classifier : getDefaultClassifier());
}

From source file:org.n52.sos.util.Reference.java

public Reference setRole(String role) {
    this.role = Optional.fromNullable(Strings.emptyToNull(role));
    return this;
}

From source file:org.sonar.server.qualityprofile.RuleActivation.java

public RuleActivation setParameter(String key, @Nullable String value) {
    String sanitizedValue = Strings.emptyToNull(value);
    parameters.put(key, sanitizedValue);
    return this;
}

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

@Override
public Object apply(GroupResource resource, Input input) throws MethodNotAllowedException, AuthException,
        NoSuchGroupException, ResourceNotFoundException, OrmException {
    if (input == null) {
        input = new Input(); // Delete would set description to null.
    }/*from  w  w w. j  a  v  a2  s.  c  om*/

    if (resource.toAccountGroup() == null) {
        throw new MethodNotAllowedException();
    } else if (!resource.getControl().isOwner()) {
        throw new AuthException("Not group owner");
    }

    AccountGroup group = db.accountGroups().get(resource.toAccountGroup().getId());
    if (group == null) {
        throw new ResourceNotFoundException();
    }

    group.setDescription(Strings.emptyToNull(input.description));
    db.accountGroups().update(Collections.singleton(group));
    groupCache.evict(group);

    return Strings.isNullOrEmpty(input.description) ? Response.none() : input.description;
}

From source file:de.metas.ui.web.dashboard.json.JsonKPILayout.java

public JsonKPILayout(final KPI kpi, final JSONOptions jsonOpts) {
    final String adLanguage = jsonOpts.getAD_Language();

    // id = kpi.getId();
    // caption = kpi.getCaption(adLanguage);
    description = Strings.emptyToNull(kpi.getDescription(adLanguage));
    chartType = kpi.getChartType().toJson();

    pollIntervalSec = kpi.getPollIntervalSec();

    ////from www.  j a va 2 s  .  c  om
    // Group by field
    final KPIField groupByField = kpi.getGroupByFieldOrNull();
    this.groupByField = groupByField == null ? null : JsonKPIFieldLayout.field(groupByField, jsonOpts);

    final ImmutableList.Builder<JsonKPIFieldLayout> jsonFields = ImmutableList.builder();
    final boolean hasCompareOffset = kpi.hasCompareOffset();
    for (final KPIField kpiField : kpi.getFields()) {
        // Don't add the group by field to our fields list
        if (kpiField.isGroupBy()) {
            continue;
        }

        jsonFields.add(JsonKPIFieldLayout.field(kpiField, jsonOpts));

        if (hasCompareOffset && !kpiField.isGroupBy()) {
            jsonFields.add(JsonKPIFieldLayout.offsetField(kpiField, jsonOpts));
        }
    }
    fields = jsonFields.build();
}

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

public boolean authenticate(String username, String password) {
    try {//from w w w  .ja  va 2 s  .c  o  m
        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:ru.org.linux.comment.PreparedComment.java

public PreparedComment(Comment comment, ApiUserRef author, String processedMessage, @Nullable ReplyInfo reply,
        boolean deletable, boolean editable, String remark, @Nullable Userpic userpic,
        @Nullable ApiDeleteInfo deleteInfo, @Nullable EditSummary editSummary, @Nullable String postIP,
        @Nullable String userAgent) {
    this.deleteInfo = deleteInfo;
    this.editSummary = editSummary;
    this.postIP = postIP;
    this.userAgent = userAgent;
    this.id = comment.getId();
    this.author = author;
    this.processedMessage = processedMessage;
    this.reply = reply;
    this.deletable = deletable;
    this.editable = editable;
    this.remark = remark;
    this.userpic = userpic;

    String encodedTitle = Strings.emptyToNull(comment.getTitle().trim());

    if (encodedTitle != null) {
        title = StringEscapeUtils.unescapeHtml4(encodedTitle);
    } else {/*from www.  j  ava 2  s  .c  o  m*/
        title = null;
    }

    deleted = comment.isDeleted();
    postdate = comment.getPostdate();
}

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

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

    if (isConst()) {
        parts.add("const");
    }//from  w w  w. j a v  a  2 s. c  o m
    if (isVolatile()) {
        parts.add("volatile");
    }

    parts.add("void");
    parts.add(Strings.emptyToNull(pDeclarator));

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

From source file:org.apache.james.transport.mailets.utils.MimeMessageUtils.java

@VisibleForTesting
Optional<String> buildNewSubject(String subjectPrefix, String originalSubject, String subject)
        throws MessagingException {
    String nullablePrefix = Strings.emptyToNull(subjectPrefix);
    if (nullablePrefix == null && subject == null) {
        return Optional.absent();
    }/*from   w ww . j  a v  a  2s. c om*/
    if (nullablePrefix == null) {
        return Optional.of(subject);
    }
    String chosenSubject = chooseSubject(subject, originalSubject);
    return prefixSubject(chosenSubject, nullablePrefix);
}