本文整理了Java中com.google.common.base.Strings.isNullOrEmpty()
方法的一些代码示例,展示了Strings.isNullOrEmpty()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Strings.isNullOrEmpty()
方法的具体详情如下:
包路径:com.google.common.base.Strings
类名称:Strings
方法名:isNullOrEmpty
[英]Returns true if the given string is null or is the empty string.
Consider normalizing your string references with #nullToEmpty. If you do, you can use String#isEmpty() instead of this method, and you won't need special null-safe forms of methods like String#toUpperCase either. Or, if you'd like to normalize "in the other direction," converting empty strings to null, you can use #emptyToNull.
[中]如果给定字符串为null或为空字符串,则返回true。
考虑用y0 null to空对字符串引用进行规范化。如果这样做,可以使用String#isEmpty()而不是这个方法,而且也不需要像String#toUpperCase这样的特殊空安全形式的方法。或者,如果希望“在另一个方向”进行规范化,将空字符串转换为null,可以使用#emptyToNull。
代码示例来源:origin: prestodb/presto
private void setTableName(String tableName)
{
checkArgument(!isNullOrEmpty(tableName), "tableName is null or empty string");
this.tableName = tableName;
}
代码示例来源:origin: apache/incubator-shardingsphere
/**
* Get logic schema.
*
* @param schemaName schema name
* @return sharding schema
*/
public LogicSchema getLogicSchema(final String schemaName) {
return Strings.isNullOrEmpty(schemaName) ? null : logicSchemas.get(schemaName);
}
代码示例来源:origin: ctripcorp/apollo
private String assembleInstanceKey(String appId, String cluster, String ip, String datacenter) {
List<String> keyParts = Lists.newArrayList(appId, cluster, ip);
if (!Strings.isNullOrEmpty(datacenter)) {
keyParts.add(datacenter);
}
return STRING_JOINER.join(keyParts);
}
代码示例来源:origin: SonarSource/sonarqube
void addMainClass(String pluginKey, @Nullable String mainClass) {
if (!Strings.isNullOrEmpty(mainClass)) {
mainClassesByPluginKey.put(pluginKey, mainClass);
}
}
代码示例来源:origin: ctripcorp/apollo
private Map<String, ApolloConfigNotification> filterNotifications(String appId,
List<ApolloConfigNotification> notifications) {
Map<String, ApolloConfigNotification> filteredNotifications = Maps.newHashMap();
for (ApolloConfigNotification notification : notifications) {
if (Strings.isNullOrEmpty(notification.getNamespaceName())) {
continue;
}
//strip out .properties suffix
String originalNamespace = namespaceUtil.filterNamespaceName(notification.getNamespaceName());
notification.setNamespaceName(originalNamespace);
//fix the character case issue, such as FX.apollo <-> fx.apollo
String normalizedNamespace = namespaceUtil.normalizeNamespace(appId, originalNamespace);
// in case client side namespace name has character case issue and has difference notification ids
// such as FX.apollo = 1 but fx.apollo = 2, we should let FX.apollo have the chance to update its notification id
// which means we should record FX.apollo = 1 here and ignore fx.apollo = 2
if (filteredNotifications.containsKey(normalizedNamespace) &&
filteredNotifications.get(normalizedNamespace).getNotificationId() < notification.getNotificationId()) {
continue;
}
filteredNotifications.put(normalizedNamespace, notification);
}
return filteredNotifications;
}
代码示例来源:origin: SonarSource/sonarqube
private static String transition(Map<String, Object> properties) {
String param = (String) properties.get(TRANSITION_PARAMETER);
checkArgument(!isNullOrEmpty(param), "Missing parameter : 'transition'");
return param;
}
代码示例来源:origin: ctripcorp/apollo
public List<AppNamespace> findByAppIdAndNamespaces(String appId, Set<String> namespaceNames) {
Preconditions.checkArgument(!Strings.isNullOrEmpty(appId), "appId must not be null");
if (namespaceNames == null || namespaceNames.isEmpty()) {
return Collections.emptyList();
}
List<AppNamespace> result = Lists.newArrayList();
for (String namespaceName : namespaceNames) {
AppNamespace appNamespace = appNamespaceCache.get(STRING_JOINER.join(appId, namespaceName));
if (appNamespace != null) {
result.add(appNamespace);
}
}
return result;
}
代码示例来源:origin: SonarSource/sonarqube
private DefaultHeaders setValue(String name, @Nullable String value) {
checkArgument(!isNullOrEmpty(name));
if (value == null) {
keyValues.remove(name);
} else {
keyValues.put(name, value);
}
return this;
}
代码示例来源:origin: apache/incubator-shardingsphere
/**
* Get logic schema.
*
* @param schemaName schema name
* @return sharding schema
*/
public LogicSchema getLogicSchema(final String schemaName) {
return Strings.isNullOrEmpty(schemaName) ? null : logicSchemas.get(schemaName);
}
代码示例来源:origin: ctripcorp/apollo
private String assembleKey(String appId, String cluster, String namespace, String dataCenter) {
List<String> keyParts = Lists.newArrayList(appId, cluster, namespace);
if (!Strings.isNullOrEmpty(dataCenter)) {
keyParts.add(dataCenter);
}
return keyParts.stream().collect(Collectors.joining(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR));
}
代码示例来源:origin: elasticjob/elastic-job-lite
private Map<String, Object> getQueryParameters(final UriInfo info, final String[] params) {
final Map<String, Object> result = new HashMap<>();
for (String each : params) {
if (!Strings.isNullOrEmpty(info.getQueryParameters().getFirst(each))) {
result.put(each, info.getQueryParameters().getFirst(each));
}
}
return result;
}
}
代码示例来源:origin: ctripcorp/apollo
private void updateRemoteNotifications(List<ApolloConfigNotification> deltaNotifications) {
for (ApolloConfigNotification notification : deltaNotifications) {
if (Strings.isNullOrEmpty(notification.getNamespaceName())) {
continue;
}
if (notification.getMessages() == null || notification.getMessages().isEmpty()) {
continue;
}
ApolloNotificationMessages localRemoteMessages =
m_remoteNotificationMessages.get(notification.getNamespaceName());
if (localRemoteMessages == null) {
localRemoteMessages = new ApolloNotificationMessages();
m_remoteNotificationMessages.put(notification.getNamespaceName(), localRemoteMessages);
}
localRemoteMessages.mergeFrom(notification.getMessages());
}
}
代码示例来源:origin: SonarSource/sonarqube
private static String verifySeverityParameter(Map<String, Object> properties) {
String param = (String) properties.get(SEVERITY_PARAMETER);
checkArgument(!isNullOrEmpty(param), "Missing parameter : '%s'", SEVERITY_PARAMETER);
return param;
}
}
代码示例来源:origin: SonarSource/sonarqube
private static List<IssuePattern> loadPatterns(String propertyKey, Configuration settings) {
List<IssuePattern> patterns = new ArrayList<>();
String patternConf = settings.get(propertyKey).orElse("");
for (String id : Splitter.on(",").omitEmptyStrings().split(patternConf)) {
String propPrefix = propertyKey + "." + id + ".";
String componentPathPattern = settings.get(propPrefix + RESOURCE_KEY).orElse(null);
checkArgument(!isNullOrEmpty(componentPathPattern), format("File path pattern cannot be empty. Please check '%s' settings", propertyKey));
String ruleKeyPattern = settings.get(propPrefix + RULE_KEY).orElse(null);
checkArgument(!isNullOrEmpty(ruleKeyPattern), format("Rule key pattern cannot be empty. Please check '%s' settings", propertyKey));
patterns.add(new IssuePattern(componentPathPattern, ruleKeyPattern));
}
return patterns;
}
代码示例来源:origin: prestodb/presto
public MongoConnectorFactory(String name)
{
checkArgument(!isNullOrEmpty(name), "name is null or empty");
this.name = name;
}
代码示例来源:origin: Graylog2/graylog2-server
public boolean stringIsSet(String key) {
return !isNullOrEmpty(strings.get(key));
}
代码示例来源:origin: ctripcorp/apollo
String assembleCacheKey(ConfigFileOutputFormat outputFormat, String appId, String clusterName,
String namespace,
String dataCenter) {
List<String> keyParts =
Lists.newArrayList(outputFormat.getValue(), appId, clusterName, namespace);
if (!Strings.isNullOrEmpty(dataCenter)) {
keyParts.add(dataCenter);
}
return STRING_JOINER.join(keyParts);
}
代码示例来源:origin: Graylog2/graylog2-server
@VisibleForTesting
static Map<String, String> parseHeaders(String headerString) {
if (isNullOrEmpty(headerString)) {
return Collections.emptyMap();
}
final Map<String, String> headers = Maps.newHashMap();
for (String headerPart : headerString.trim().split(",")) {
final String[] parts = headerPart.trim().split(":");
if (parts.length == 2) {
headers.put(parts[0].trim(), parts[1].trim());
}
}
return headers;
}
代码示例来源:origin: SonarSource/sonarqube
private static void checkActionExtension(@Nullable String actionExtension) {
if (isNullOrEmpty(actionExtension)) {
return;
}
checkArgument(SUPPORTED_MEDIA_TYPES_BY_URL_SUFFIX.get(actionExtension.toLowerCase(Locale.ENGLISH)) != null, "Unknown action extension: %s", actionExtension);
}
代码示例来源:origin: prestodb/presto
private void setType(String type)
{
checkArgument(!isNullOrEmpty(type), "type is null or empty string");
this.type = type;
}
内容来源于网络,如有侵权,请联系作者删除!