Example usage for org.apache.commons.lang3 StringUtils defaultIfEmpty

List of usage examples for org.apache.commons.lang3 StringUtils defaultIfEmpty

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils defaultIfEmpty.

Prototype

public static <T extends CharSequence> T defaultIfEmpty(final T str, final T defaultStr) 

Source Link

Document

Returns either the passed in CharSequence, or if the CharSequence is empty or null , the value of defaultStr .

 StringUtils.defaultIfEmpty(null, "NULL")  = "NULL" StringUtils.defaultIfEmpty("", "NULL")    = "NULL" StringUtils.defaultIfEmpty(" ", "NULL")   = " " StringUtils.defaultIfEmpty("bat", "NULL") = "bat" StringUtils.defaultIfEmpty("", null)      = null 

Usage

From source file:org.ligoj.app.plugin.vm.aws.VmAwsSnapshotResource.java

/**
 * Check the given snapshot matches to the criteria : name, id, or one of its volume id.
 *///from w ww.  j a v  a2  s.c  o  m
private boolean matches(final Snapshot snapshot, final String criteria) {
    return StringUtils.containsIgnoreCase(StringUtils.defaultIfEmpty(snapshot.getName(), ""), criteria)
            || StringUtils.containsIgnoreCase(snapshot.getId(), criteria) || snapshot.getVolumes().stream()
                    .anyMatch(v -> StringUtils.containsIgnoreCase(v.getId(), criteria));
}

From source file:org.ligoj.app.plugin.vm.aws.VmAwsSnapshotResource.java

/**
 * Parse <code>DescribeImagesResponse</code> response to {@link Snapshot} list.
 *
 * @param amisAsXml// w ww  . j  ava2  s .com
 *            AMI descriptions as XML.
 * @return The parsed AMI as {@link Snapshot}.
 */
private List<Snapshot> toAmis(final String amisAsXml)
        throws XPathExpressionException, SAXException, IOException, ParserConfigurationException {
    final NodeList items = xml.getXpath(
            StringUtils.defaultIfEmpty(amisAsXml,
                    "<DescribeImagesResponse><imagesSet></imagesSet></DescribeImagesResponse>"),
            "/DescribeImagesResponse/imagesSet/item");
    return IntStream.range(0, items.getLength()).mapToObj(items::item).map(n -> toAmi((Element) n))
            .collect(Collectors.toList());
}

From source file:org.mariotaku.twidere.adapter.ComposeAutoCompleteAdapter.java

@Override
public CharSequence convertToString(final Cursor cursor) {
    switch (StringUtils.defaultIfEmpty(cursor.getString(mTypeIdx), "")) {
    case Suggestions.AutoComplete.TYPE_HASHTAGS: {
        return '#' + cursor.getString(mValueIdx);
    }//from ww w .  j  a va  2 s  .co m
    case Suggestions.AutoComplete.TYPE_USERS: {
        return '@' + cursor.getString(mValueIdx);
    }
    }
    return cursor.getString(mValueIdx);
}

From source file:org.mifosplatform.infrastructure.sms.domain.SmsMessage.java

public Map<String, Object> update(final JsonCommand command) {

    final Map<String, Object> actualChanges = new LinkedHashMap<String, Object>(1);

    if (command.isChangeInStringParameterNamed(SmsApiConstants.messageParamName, this.message)) {
        final String newValue = command.stringValueOfParameterNamed(SmsApiConstants.messageParamName);
        actualChanges.put(SmsApiConstants.messageParamName, newValue);
        this.message = StringUtils.defaultIfEmpty(newValue, null);
    }/*from www .  j a  v a 2 s .c o m*/

    return actualChanges;
}

From source file:org.neo4j.index.population.LucenePartitionedIndexStressTesting.java

private static String getEnvVariable(String propertyName, String defaultValue) {
    String value = System.getenv(propertyName);
    return StringUtils.defaultIfEmpty(value, defaultValue);
}

From source file:org.phenotips.tools.FormConditionalSubsection.java

@Override
public String display(DisplayMode mode, String[] fieldNames) {
    String displayedElements = super.display(mode, fieldNames);
    if (StringUtils.isBlank(displayedElements) && !this.yesSelected && !this.noSelected) {
        return "";
    }/*from  www  . ja v a2  s  .c o  m*/
    if (DisplayMode.Edit.equals(mode)) {
        return "<div class='section'>" + this.titleYesNoPicker.display(mode, fieldNames)
                + "<div class='dropdown invisible " + this.type + "'><div>" + displayedElements
                + "</div></div></div>";
    } else {
        String title = this.titleYesNoPicker.display(mode, fieldNames);
        return "<div class='section" + (StringUtils.isEmpty(title) ? " value-checked" : "") + "'>"
                + StringUtils.defaultIfEmpty(title, XMLUtils.escapeElementContent(this.title))
                + "</div><div class='subsection " + this.type + "'>" + displayedElements + "</div>";
    }
}

From source file:org.protempa.dest.table.PropositionColumnSpec.java

protected String[] columnNames(String prefix) {
    List<String> results = new ArrayList<>();
    if (this.outputConfig.showId()) {
        results.add(//from  w ww. ja v  a 2s  .  co  m
                StringUtils.defaultIfEmpty(outputConfig.getIdHeading(), this.columnNamePrefixOverride + "_id"));
    }
    if (this.outputConfig.showValue()) {
        results.add(StringUtils.defaultIfEmpty(outputConfig.getValueHeading(),
                this.columnNamePrefixOverride + "_value"));
    }
    if (this.outputConfig.showDisplayName()) {
        results.add(StringUtils.defaultIfEmpty(outputConfig.getDisplayNameHeading(),
                this.columnNamePrefixOverride + "_displayName"));
    }
    if (this.outputConfig.showAbbrevDisplayName()) {
        results.add(StringUtils.defaultIfEmpty(outputConfig.getAbbrevDisplayNameHeading(),
                this.columnNamePrefixOverride + "_abbrevDisplayName"));
    }
    if (this.outputConfig.showStartOrTimestamp()) {
        results.add(StringUtils.defaultIfEmpty(outputConfig.getStartOrTimestampHeading(),
                this.columnNamePrefixOverride + "_startOrTimeStamp"));
    }
    if (this.outputConfig.showFinish()) {
        results.add(StringUtils.defaultIfEmpty(outputConfig.getFinishHeading(),
                this.columnNamePrefixOverride + "_finish"));
    }
    if (this.outputConfig.showLength()) {
        results.add(StringUtils.defaultIfEmpty(outputConfig.getLengthHeading(),
                this.columnNamePrefixOverride + "_length"));
    }
    for (String heading : this.propertyNames) {
        results.add(this.columnNamePrefixOverride + "." + heading);
    }
    return results.toArray(new String[results.size()]);
}

From source file:org.siphon.d2js.DispatchServlet.java

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    request.setCharacterEncoding("utf-8");
    request.setAttribute("org.apache.catalina.ASYNC_SUPPORTED", true);
    AsyncContext asyncContext = request.startAsync(request, response);
    D2jsRunner d2jsRunner = this.getD2jsRunner();
    String method = StringUtils.defaultIfEmpty(request.getParameter("_m"), "fetch");

    try {//from   www .  j a  va2 s .c o  m
        d2jsRunner.run((HttpServletRequest) asyncContext.getRequest(),
                (HttpServletResponse) asyncContext.getResponse(), method);
    } finally {
        asyncContext.complete();
    }
}

From source file:org.siphon.d2js.DispatchServlet.java

protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    request.setCharacterEncoding("utf-8");
    request.setAttribute("org.apache.catalina.ASYNC_SUPPORTED", true);
    AsyncContext asyncContext = request.startAsync(request, response);
    D2jsRunner d2jsRunner = this.getD2jsRunner();
    String method = StringUtils.defaultIfEmpty(request.getParameter("_m"), "create");
    try {/*from ww  w.  j a  v a 2  s .  co  m*/
        d2jsRunner.run((HttpServletRequest) asyncContext.getRequest(),
                (HttpServletResponse) asyncContext.getResponse(), method);
    } finally {
        asyncContext.complete();
    }
}

From source file:org.siphon.db2js.DispatchServlet.java

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    request.setCharacterEncoding("utf-8");
    DbjsRunner dbjsRunner = this.getDbjsRunner();
    dbjsRunner.run(request, response, StringUtils.defaultIfEmpty(request.getParameter("_m"), "fetch"));
}