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.b2international.commons.http.ExtendedLocale.java

public ExtendedLocale(String language, String country, String languageRefSetId) {
    this.language = Strings.nullToEmpty(language).toLowerCase(Locale.ENGLISH);
    this.country = Strings.nullToEmpty(country).toLowerCase(Locale.ENGLISH);
    this.languageRefSetId = Strings.nullToEmpty(languageRefSetId);
}

From source file:org.arakhne.afc.testtools.XbaseInlineTestUtil.java

/** Assert that the inline annotation contains all the formal parameters.
 *
 * <p>The parameters will be replaced in the expected string by {@code $1}, {@code $2}, etc.
 *
 * @param type the type./*from  w  w  w  .ja  v a 2 s  .  c o  m*/
 * @param methodName the method name.
 * @param parameters the list of parameter types.
 */
public static void assertInlineParameterUsage(Class<?> type, String methodName, Class<?>... parameters) {
    final Inline annotation = getInlineAnnotation(type, methodName, parameters);
    if (annotation == null) {
        fail("@Inline annotation not found"); //$NON-NLS-1$
        return;
    }
    final String value = Strings.nullToEmpty(annotation.value());
    for (int i = 1; i <= parameters.length; ++i) {
        if (!value.contains("$" + i)) { //$NON-NLS-1$
            fail("@Inline value does not contains the string \"$" + i + "\""); //$NON-NLS-1$ //$NON-NLS-2$
        }
    }
}

From source file:eu.numberfour.n4js.utils.StatusHelper.java

/**
 * Creates a new error status with the {@link Throwable#getMessage() message} of the given cause.
 *///ww  w.  j  a va 2 s.com
public IStatus createError(final Throwable t) {
    return createError(Strings.nullToEmpty(t.getMessage()), t);
}

From source file:com.jadarstudios.developercapes.standalone.DevCapesStandalone.java

@EventHandler
public void preLoad(FMLPreInitializationEvent event) {
    this.logger = event.getModLog();
    this.modId = event.getModMetadata().modId;

    InputStream is = getClass().getResourceAsStream("/capeInfo.json");
    InputStreamReader reader = new InputStreamReader(is);
    try {//w  ww . j a v a2 s  .  com
        Gson gson = new Gson();

        HashMap map = gson.fromJson(reader, HashMap.class);

        Object urlStringObject = map.get("capeConfigUrl");
        if (urlStringObject != null && (urlStringObject instanceof String)) {
            capeConfigUrl = Strings.nullToEmpty((String) urlStringObject);
        } else {
            throw new JsonParseException("Could not find key 'capeConfigUrl'");
        }
    } catch (JsonParseException e) {
        logger.error("Failed to parse capeInfo.json. This means you could have a corrupt mod jar.");
        e.printStackTrace();
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }

}

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

public CDOCommitInfoWithUuid(final CDOCommitInfo commitInfo) {
    this.delegate = Preconditions.checkNotNull(commitInfo, "Commit info argument cannot be null.");

    if (commitInfo instanceof ICDOCommitInfoWithUuid) {
        uuid = ((ICDOCommitInfoWithUuid) commitInfo).getUuid();
        modifiedComment = commitInfo.getComment(); // already modified
    } else {//  ww w .  j a  v  a2s  . co  m
        uuid = CDOCommitInfoUtils.getUuid(commitInfo);
        modifiedComment = CDOCommitInfoUtils.removeUuidPrefix(Strings.nullToEmpty(commitInfo.getComment()));
    }

}

From source file:org.opendaylight.aaa.impl.shiro.tokenauthrealm.auth.ClaimBuilder.java

public ClaimBuilder setUserId(String userId) {
    this.userId = Strings.nullToEmpty(userId).trim();
    return this;
}

From source file:clocker.docker.location.strategy.basic.HostnamePlacementStrategy.java

@Override
public boolean apply(DockerHostLocation input) {
    String constraint = Preconditions.checkNotNull(config().get(HOSTNAME_PATTERN), "pattern");
    String hostname = Strings.nullToEmpty(input.getMachine().getHostname());
    boolean match = hostname.matches(constraint);
    LOG.debug("Hostname {} {} {}", new Object[] { hostname, match ? "matches" : "not", constraint });

    return match;
}

From source file:org.apache.sentry.policy.common.CommonPrivilege.java

public CommonPrivilege(String privilegeStr) {
    privilegeStr = Strings.nullToEmpty(privilegeStr).trim();
    if (privilegeStr.isEmpty()) {
        throw new IllegalArgumentException("Privilege string cannot be null or empty.");
    }//from w w  w. j  ava 2  s.co m
    List<KeyValue> parts = Lists.newArrayList();
    for (String authorizable : SentryConstants.AUTHORIZABLE_SPLITTER.trimResults().split(privilegeStr)) {
        if (authorizable.isEmpty()) {
            throw new IllegalArgumentException("Privilege '" + privilegeStr + "' has an empty section");
        }
        parts.add(new KeyValue(authorizable));
    }
    if (parts.isEmpty()) {
        throw new AssertionError("Should never occur: " + privilegeStr);
    }
    this.parts = ImmutableList.copyOf(parts);
}

From source file:fr.jcgay.maven.plugin.buildplan.display.AbstractTableDescriptor.java

private static int safeLength(String string) {
    return Strings.nullToEmpty(string).length();
}

From source file:org.apache.sqoop.submission.spark.SqoopSparkClientManager.java

public void addResources(String addedFiles) {
    for (String addedFile : CSV_SPLITTER.split(Strings.nullToEmpty(addedFiles))) {
        if (!localFiles.contains(addedFile)) {
            localFiles.add(addedFile);/*from   www  .ja  v a  2s  . c o  m*/
            context.addFile(addedFile);
        }
    }
}