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.testing.security.firingrange.tests.reflected.Parameter.java

@Override
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String echoedParam = Strings.nullToEmpty(request.getParameter(ECHOED_PARAM));
    String template = Templates.getTemplate(request, getClass());
    Responses.sendXssed(response, Templates.replacePayload(template, echoedParam));
}

From source file:com.google.testing.security.firingrange.tests.remoteinclude.Parameter.java

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String echoedParam = Strings.nullToEmpty(request.getParameter(ECHOED_PARAM));
    if (!echoedParam.startsWith("http")) {
        Responses.sendError(response, "Invalid URL", 400);
    } else {/*from  ww  w . j  a v a 2  s .  co  m*/
        echoedParam = echoedParam.replace("\"", "&quot");
        String template = Templates.getTemplate("parameter.tmpl", getClass());
        Responses.sendXssed(response, Templates.replacePayload(template, echoedParam));
    }
}

From source file:org.graylog.plugins.metrics.ganglia.converters.UDPAddressingModeConverter.java

@Override
public GMetric.UDPAddressingMode convertFrom(String value) {
    try {/*from  w  w  w .  j  a  v  a2s . c om*/
        return GMetric.UDPAddressingMode.valueOf(Strings.nullToEmpty(value).toUpperCase(Locale.ENGLISH));
    } catch (IllegalArgumentException e) {
        throw new ParameterException("Couldn't convert value \"" + value + "\" to UDP addressing mode.", e);
    }
}

From source file:com.google.testing.security.firingrange.tests.reflected.Url.java

@Override
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String echoedParam = Strings.nullToEmpty(request.getParameter(ECHOED_PARAM));
    try {/*ww w . ja  v  a  2s.  co m*/
        URI inputUri = URI.create(echoedParam);
        String template = Templates.getTemplate(request, getClass());
        Responses.sendXssed(response, Templates.replacePayload(template, inputUri.toString()));
    } catch (IllegalArgumentException e) {
        Responses.sendError(response, "Cannot parse request param", 400);
    }
}

From source file:com.googlesource.gerrit.plugins.its.base.workflow.AddStandardComment.java

private String getCommentChangeEvent(String action, String prefix, Map<String, String> map) {
    String ret = "";
    String changeNumber = Strings.nullToEmpty(map.get("changeNumber"));
    if (!changeNumber.isEmpty()) {
        changeNumber += " ";
    }/*w  ww.  java  2  s  .c o  m*/
    ret += "Change " + changeNumber + action;
    String submitter = getValueFromMap(map, prefix, "Name", "Username");
    if (!submitter.isEmpty()) {
        ret += " by " + submitter;
    }
    String subject = Strings.nullToEmpty(map.get("subject"));
    if (!subject.isEmpty()) {
        ret += ":\n" + subject;
    }
    String reason = Strings.nullToEmpty(map.get("reason"));
    if (!reason.isEmpty()) {
        ret += "\n\nReason:\n" + reason;
    }
    String url = Strings.nullToEmpty(map.get("formatChangeUrl"));
    if (!url.isEmpty()) {
        ret += "\n\n" + url;
    }
    return ret;
}

From source file:com.google.gerrit.acceptance.rest.project.ProjectAssert.java

public static void assertProjectInfo(Project project, ProjectInfo info) {
    if (info.name != null) {
        // 'name' is not set if returned in a map
        assertEquals(project.getName(), info.name);
    }//from  ww w  . j av a 2 s  . com
    assertEquals(project.getName(), Url.decode(info.id));
    Project.NameKey parentName = project.getParent(new Project.NameKey("All-Projects"));
    assertEquals(parentName != null ? parentName.get() : null, info.parent);
    assertEquals(project.getDescription(), Strings.nullToEmpty(info.description));
}

From source file:com.facebook.buck.android.BuckEventAndroidLogger.java

@Override
public void error(Throwable throwable, String errorFormat, Object... args) {
    eventBus.post(ThrowableLogEvent.create(throwable, Strings.nullToEmpty(errorFormat), args));
}

From source file:com.opengamma.strata.examples.regression.TradeReportRegressionTestUtils.java

private static List<String> toLines(String asciiTable) {
    return Arrays.asList(asciiTable.split("\\r?\\n")).stream()
            .filter(line -> !Strings.nullToEmpty(line).trim().isEmpty()).collect(Collectors.toList());
}

From source file:eu.numberfour.n4js.product.N4ProductActivator.java

/**
 * Logs the given message and throwable to the platform log.
 *
 * @param message//  w w w.  java 2s .c  o  m
 *            A high level UI message describing when the problem happened.
 * @param t
 *            The throwable from where the problem actually occurred.
 */
public static void log(final String message, final Throwable t) {
    getDefault().getLog().log(new Status(ERROR, PLUGIN_ID, Strings.nullToEmpty(message), t));
}

From source file:io.druid.query.lookup.LookupConfig.java

/**
 * @param snapshotWorkingDir working directory to store lookups snapshot file, passing null or empty string will disable the snapshot utility
 *///from   w w  w  . j  ava2s. c om
@JsonCreator
public LookupConfig(@JsonProperty("snapshotWorkingDir") String snapshotWorkingDir) {
    this.snapshotWorkingDir = Strings.nullToEmpty(snapshotWorkingDir);
}