com.google.common.base.Strings类的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(5.2k)|赞(0)|评价(0)|浏览(572)

本文整理了Java中com.google.common.base.Strings类的一些代码示例,展示了Strings类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Strings类的具体详情如下:
包路径:com.google.common.base.Strings
类名称:Strings

Strings介绍

[英]Static utility methods pertaining to String or CharSequence instances.
[中]与字符串或CharSequence实例有关的静态实用程序方法。

代码示例

代码示例来源:origin: ctripcorp/apollo

public InstanceConfigAuditModel(String appId, String clusterName, String dataCenter, String
  clientIp, String configAppId, String configClusterName, String configNamespace, String
                  releaseKey) {
 this.offerTime = new Date();
 this.appId = appId;
 this.clusterName = clusterName;
 this.dataCenter = Strings.isNullOrEmpty(dataCenter) ? "" : dataCenter;
 this.ip = clientIp;
 this.configAppId = configAppId;
 this.configClusterName = configClusterName;
 this.configNamespace = configNamespace;
 this.releaseKey = releaseKey;
}

代码示例来源:origin: ctripcorp/apollo

public static boolean isBlank(String str) {
 return Strings.nullToEmpty(str).trim().isEmpty();
}

代码示例来源:origin: prestodb/presto

private static String trimEmptyToNull(String value)
{
  return emptyToNull(nullToEmpty(value).trim());
}

代码示例来源:origin: prestodb/presto

private static String indentString(int indent)
  {
    return Strings.repeat(INDENT, indent);
  }
}

代码示例来源:origin: apache/incubator-druid

@Nullable
public static String emptyToNullIfNeeded(@Nullable String value)
{
 //CHECKSTYLE.OFF: Regexp
 return replaceWithDefault() ? Strings.emptyToNull(value) : value;
 //CHECKSTYLE.ON: Regexp
}

代码示例来源:origin: prestodb/presto

private static String indentString(int indent)
{
  return Strings.repeat("    ", indent);
}

代码示例来源:origin: google/guava

public void testEmptyToNull() {
 assertNull(Strings.emptyToNull(null));
 assertNull(Strings.emptyToNull(""));
 assertEquals("a", Strings.emptyToNull("a"));
}

代码示例来源:origin: prestodb/presto

private void setTableName(String tableName)
{
  checkArgument(!isNullOrEmpty(tableName), "tableName is null or empty string");
  this.tableName = tableName;
}

代码示例来源:origin: prestodb/presto

public static Set<String> parseClientTags(String clientTagsString)
{
  Splitter splitter = Splitter.on(',').trimResults().omitEmptyStrings();
  return ImmutableSet.copyOf(splitter.split(nullToEmpty(clientTagsString)));
}

代码示例来源:origin: prestodb/presto

public PrestoNode(String nodeIdentifier, URI httpUri, NodeVersion nodeVersion, boolean coordinator)
{
  nodeIdentifier = emptyToNull(nullToEmpty(nodeIdentifier).trim());
  this.nodeIdentifier = requireNonNull(nodeIdentifier, "nodeIdentifier is null or empty");
  this.httpUri = requireNonNull(httpUri, "httpUri is null");
  this.nodeVersion = requireNonNull(nodeVersion, "nodeVersion is null");
  this.coordinator = coordinator;
}

代码示例来源:origin: prestodb/presto

private void print(Integer indentLevel, String value)
  {
    out.println(Strings.repeat(INDENT, indentLevel) + value);
  }
}

代码示例来源:origin: prestodb/presto

public static Column fromMetastoreApiFieldSchema(FieldSchema fieldSchema)
{
  return new Column(fieldSchema.getName(), HiveType.valueOf(fieldSchema.getType()), Optional.ofNullable(emptyToNull(fieldSchema.getComment())));
}

代码示例来源:origin: prestodb/presto

public MongoConnectorFactory(String name)
{
  checkArgument(!isNullOrEmpty(name), "name is null or empty");
  this.name = name;
}

代码示例来源:origin: prestodb/presto

private Set<String> parseClientTags(HttpServletRequest servletRequest)
{
  Splitter splitter = Splitter.on(',').trimResults().omitEmptyStrings();
  return ImmutableSet.copyOf(splitter.split(nullToEmpty(servletRequest.getHeader(PRESTO_CLIENT_TAGS))));
}

代码示例来源:origin: prestodb/presto

public static Optional<String> defaultCredentialCachePath()
  {
    String value = nullToEmpty(System.getenv("KRB5CCNAME"));
    if (value.startsWith(FILE_PREFIX)) {
      value = value.substring(FILE_PREFIX.length());
    }
    return Optional.ofNullable(emptyToNull(value));
  }
}

代码示例来源:origin: prestodb/presto

private void appendLine(String template, Object... arguments)
  {
    result.append(repeat("\t", level)).append(format(template + "\n", arguments));
  }
}

代码示例来源:origin: prestodb/presto

private void setType(String type)
{
  checkArgument(!isNullOrEmpty(type), "type is null or empty string");
  this.type = type;
}

代码示例来源:origin: prestodb/presto

private Set<String> parseClientCapabilities(HttpServletRequest servletRequest)
{
  Splitter splitter = Splitter.on(',').trimResults().omitEmptyStrings();
  return ImmutableSet.copyOf(splitter.split(nullToEmpty(servletRequest.getHeader(PRESTO_CLIENT_CAPABILITIES))));
}

代码示例来源:origin: prestodb/presto

public static String preprocessQuery(Optional<String> catalog, Optional<String> schema, String query)
    throws QueryPreprocessorException
{
  Duration timeout = DEFAULT_PREPROCESSOR_TIMEOUT;
  String timeoutEnvironment = nullToEmpty(System.getenv(ENV_PREPROCESSOR_TIMEOUT)).trim();
  if (!timeoutEnvironment.isEmpty()) {
    timeout = Duration.valueOf(timeoutEnvironment);
  }
  String preprocessorCommand = System.getenv(ENV_PREPROCESSOR);
  if (emptyToNull(preprocessorCommand) == null) {
    return query;
  }
  return preprocessQuery(catalog, schema, query, ImmutableList.of("/bin/sh", "-c", preprocessorCommand), timeout);
}

代码示例来源:origin: prestodb/presto

private static String align(String s, int maxWidth, int padding, boolean right)
{
  int width = consoleWidth(s);
  checkState(width <= maxWidth, "string width is greater than max width");
  String large = repeat(" ", (maxWidth - width) + padding);
  String small = repeat(" ", padding);
  return right ? (large + s + small) : (small + s + large);
}

相关文章