org.apache.commons.lang3.StringUtils.trimToNull()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(11.0k)|赞(0)|评价(0)|浏览(127)

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

StringUtils.trimToNull介绍

[英]Removes control characters (char <= 32) from both ends of this String returning null if the String is empty ("") after the trim or if it is null.

The String is trimmed using String#trim(). Trim removes start and end characters <= 32. To strip whitespace use #stripToNull(String).

StringUtils.trimToNull(null)          = null 
StringUtils.trimToNull("")            = null 
StringUtils.trimToNull("     ")       = null 
StringUtils.trimToNull("abc")         = "abc" 
StringUtils.trimToNull("    abc    ") = "abc"

[中]从该字符串的两端删除控制字符(char<=32),如果修剪后的字符串为空(“”)或为空,则返回null。
使用字符串#trim()修剪字符串。Trim删除起始字符和结束字符<=32。要去除空白,请使用#stripToNull(字符串)。

StringUtils.trimToNull(null)          = null 
StringUtils.trimToNull("")            = null 
StringUtils.trimToNull("     ")       = null 
StringUtils.trimToNull("abc")         = "abc" 
StringUtils.trimToNull("    abc    ") = "abc"

代码示例

代码示例来源:origin: gocd/gocd

public void setName(String name) {
  this.name = StringUtils.trimToNull(name);
}

代码示例来源:origin: gocd/gocd

public void setName(String name) {
  this.name = StringUtils.trimToNull(name);
}

代码示例来源:origin: gocd/gocd

public String getName() {
  return StringUtils.trimToNull(name);
}

代码示例来源:origin: gocd/gocd

public String getName() {
  return StringUtils.trimToNull(name);
}

代码示例来源:origin: rest-assured/rest-assured

private XmlPathConfig(JAXBObjectMapperFactory jaxbObjectMapperFactory, XmlParserType defaultParserType,
           XmlPathObjectDeserializer defaultDeserializer, String charset, Map<String, Boolean> features,
           Map<String, String> declaredNamespaces, Map<String, Object> properties, boolean validating,
           boolean namespaceAware, boolean allowDocTypeDeclaration) {
  charset = StringUtils.trimToNull(charset);
  if (charset == null) throw new IllegalArgumentException("Charset cannot be empty");
  this.charset = charset;
  this.defaultDeserializer = defaultDeserializer;
  this.defaultParserType = defaultParserType;
  this.jaxbObjectMapperFactory = jaxbObjectMapperFactory;
  this.features = features;
  this.declaredNamespaces = declaredNamespaces;
  this.properties = properties;
  this.validating = validating;
  this.namespaceAware = namespaceAware;
  this.allowDocTypeDeclaration = allowDocTypeDeclaration;
}

代码示例来源:origin: rest-assured/rest-assured

private XmlPathConfig(JAXBObjectMapperFactory jaxbObjectMapperFactory, XmlParserType defaultParserType,
           XmlPathObjectDeserializer defaultDeserializer, String charset, Map<String, Boolean> features,
           Map<String, String> declaredNamespaces, Map<String, Object> properties, boolean validating,
           boolean namespaceAware, boolean allowDocTypeDeclaration) {
  charset = StringUtils.trimToNull(charset);
  if (charset == null) throw new IllegalArgumentException("Charset cannot be empty");
  this.charset = charset;
  this.defaultDeserializer = defaultDeserializer;
  this.defaultParserType = defaultParserType;
  this.jaxbObjectMapperFactory = jaxbObjectMapperFactory;
  this.features = features;
  this.declaredNamespaces = declaredNamespaces;
  this.properties = properties;
  this.validating = validating;
  this.namespaceAware = namespaceAware;
  this.allowDocTypeDeclaration = allowDocTypeDeclaration;
}

代码示例来源:origin: rest-assured/rest-assured

private JsonPathConfig(NumberReturnType numberReturnType, JsonParserType parserType, GsonObjectMapperFactory gsonObjectMapperFactory,
            Jackson1ObjectMapperFactory jackson1ObjectMapperFactory, Jackson2ObjectMapperFactory jackson2ObjectMapperFactory,
            JsonPathObjectDeserializer defaultDeserializer, String charset) {
  if (numberReturnType == null) throw new IllegalArgumentException("numberReturnType cannot be null");
  charset = StringUtils.trimToNull(charset);
  if (charset == null) throw new IllegalArgumentException("Charset cannot be empty");
  this.charset = charset;
  this.numberReturnType = numberReturnType;
  this.defaultDeserializer = defaultDeserializer;
  this.defaultParserType = parserType;
  this.gsonObjectMapperFactory = gsonObjectMapperFactory;
  this.jackson1ObjectMapperFactory = jackson1ObjectMapperFactory;
  this.jackson2ObjectMapperFactory = jackson2ObjectMapperFactory;
}

代码示例来源:origin: rest-assured/rest-assured

private JsonPathConfig(NumberReturnType numberReturnType, JsonParserType parserType, GsonObjectMapperFactory gsonObjectMapperFactory,
            Jackson1ObjectMapperFactory jackson1ObjectMapperFactory, Jackson2ObjectMapperFactory jackson2ObjectMapperFactory,
            JsonPathObjectDeserializer defaultDeserializer, String charset) {
  if (numberReturnType == null) throw new IllegalArgumentException("numberReturnType cannot be null");
  charset = StringUtils.trimToNull(charset);
  if (charset == null) throw new IllegalArgumentException("Charset cannot be empty");
  this.charset = charset;
  this.numberReturnType = numberReturnType;
  this.defaultDeserializer = defaultDeserializer;
  this.defaultParserType = parserType;
  this.gsonObjectMapperFactory = gsonObjectMapperFactory;
  this.jackson1ObjectMapperFactory = jackson1ObjectMapperFactory;
  this.jackson2ObjectMapperFactory = jackson2ObjectMapperFactory;
}

代码示例来源:origin: rest-assured/rest-assured

private MultiPartConfig(String defaultControlName, String defaultFileName, String defaultSubtype, String defaultBoundary,
            String defaultCharset, boolean isUserConfigured) {
  this.defaultControlName = defaultControlName;
  this.defaultBoundary = defaultBoundary;
  this.defaultFileName = StringUtils.trimToNull(defaultFileName);
  this.defaultSubtype = StringUtils.trimToNull(defaultSubtype);
  this.defaultCharset = StringUtils.trimToNull(defaultCharset);
  AssertParameter.notNull(this.defaultControlName, "Default control name");
  AssertParameter.notNull(this.defaultSubtype, "Default subtype");
  this.isUserConfigured = isUserConfigured;
}

代码示例来源:origin: rest-assured/rest-assured

private ProxySpecification(String host, int port, String scheme, String username, String password) {
  this.host = StringUtils.trimToNull(host);
  this.scheme = StringUtils.trimToNull(scheme);
  AssertParameter.notNull(this.host, "Proxy host");
  AssertParameter.notNull(this.scheme, "Proxy scheme");
  if (port < 1) {
    if (scheme.equalsIgnoreCase(HTTP)) {
      port = DEFAULT_HTTP_PORT;
    } else if (scheme.equalsIgnoreCase(HTTPS)) {
      port = DEFAULT_HTTPS_PORT;
    } else {
      throw new IllegalArgumentException("Cannot determine proxy port");
    }
  }
  this.username = StringUtils.trimToNull(username);
  this.password = StringUtils.trimToNull(password);
  this.port = port;
}

代码示例来源:origin: rest-assured/rest-assured

public boolean matches(String contentType) {
    String expectedContentType = StringUtils.trimToNull(contentType);
    if (expectedContentType == null) {
      return false;
    }

    for (String supportedContentType : getContentTypeStrings()) {
      if (supportedContentType.equalsIgnoreCase(expectedContentType)) {
        return true;
      }
    }
    return false;
  }
}

代码示例来源:origin: swagger-api/swagger-core

protected String nameForClass(Class<?> cls, Set<Options> options) {
  if (options.contains(Options.SKIP_API_MODEL)) {
    return cls.getSimpleName();
  }
  io.swagger.v3.oas.annotations.media.Schema mp = AnnotationsUtils.getSchemaDeclaredAnnotation(cls);
  final String modelName = mp == null ? null : StringUtils.trimToNull(mp.name());
  return modelName == null ? cls.getSimpleName() : modelName;
}

代码示例来源:origin: rest-assured/rest-assured

private HttpMethod toValidHttpMethod(String method) {
  String httpMethodAsString = notNull(trimToNull(method), "HTTP Method");
  HttpMethod httpMethod = HttpMethod.resolve(httpMethodAsString.toUpperCase());
  if (httpMethod == null) {
    throw new IllegalArgumentException("HTTP method '" + method + "' is not supported by WebTestClient");
  }
  return httpMethod;
}

代码示例来源:origin: rest-assured/rest-assured

private HttpMethod toValidHttpMethod(String method) {
    String httpMethodAsString = notNull(trimToNull(method), "HTTP Method");
    HttpMethod httpMethod = HttpMethod.resolve(httpMethodAsString.toUpperCase());
    if (httpMethod == null) {
      throw new IllegalArgumentException("HTTP method '" + method + "' is not supported by MockMvc");
    }
    return httpMethod;
  }
}

代码示例来源:origin: gocd/gocd

public Resources(String commaSeparatedResources) {
  final String[] resourceArray = commaSeparatedResources.split(",");
  for (String resource : resourceArray) {
    final String name = StringUtils.trimToNull(resource);
    if (name == null) {
      continue;
    }
    add(new Resource(name));
  }
}

代码示例来源:origin: org.apache.commons/commons-lang3

@Test
public void testTrimToNull() {
  assertEquals(FOO, StringUtils.trimToNull(FOO + "  "));
  assertEquals(FOO, StringUtils.trimToNull(" " + FOO + "  "));
  assertEquals(FOO, StringUtils.trimToNull(" " + FOO));
  assertEquals(FOO, StringUtils.trimToNull(FOO + ""));
  assertNull(StringUtils.trimToNull(" \t\r\n\b "));
  assertNull(StringUtils.trimToNull(StringUtilsTest.TRIMMABLE));
  assertEquals(StringUtilsTest.NON_TRIMMABLE, StringUtils.trimToNull(StringUtilsTest.NON_TRIMMABLE));
  assertNull(StringUtils.trimToNull(""));
  assertNull(StringUtils.trimToNull(null));
}

代码示例来源:origin: swagger-api/swagger-core

@Override
  protected String nameForClass(Class<?> cls, Set<Options> options) {
    String className = cls.getName().startsWith("java.") ? cls.getSimpleName() : cls.getName();
    if (options.contains(Options.SKIP_API_MODEL)) {
      return className;
    }
    final io.swagger.v3.oas.annotations.media.Schema model = cls.getAnnotation(io.swagger.v3.oas.annotations.media.Schema.class);
    final String modelName = model == null ? null : StringUtils.trimToNull(model.name());
    return modelName == null ? className : modelName;
  }
}

代码示例来源:origin: apache/geode

void generateDefaultPropertiesFile(final String targetFileName) throws IOException {
  String fileName = StringUtils.trimToNull(targetFileName);
  if (fileName == null) {
   fileName = getDefaultFileName();
  }

  DistributionConfig config = DistributionConfigImpl.createDefaultInstance();
  config.toFile(new File(fileName));
 }
}

代码示例来源:origin: swagger-api/swagger-core

final String cleanName = StringUtils.trimToNull(name);
final String useName;
if (!isEmpty(cleanName) && !cleanName.equals(property.getName())) {
  useName = null;
final String cleanNS = StringUtils.trimToNull(ns);
final String useNS;
if (!isEmpty(cleanNS)) {

代码示例来源:origin: liuyangming/ByteTCC

private void invokeAfterRecvResponse(ClientHttpResponse httpResponse, boolean serverFlag) throws IOException {
  SpringCloudBeanRegistry beanRegistry = SpringCloudBeanRegistry.getInstance();
  CompensableBeanFactory beanFactory = beanRegistry.getBeanFactory();
  TransactionInterceptor transactionInterceptor = beanFactory.getTransactionInterceptor();
  HttpHeaders respHeaders = httpResponse.getHeaders();
  String respTransactionStr = respHeaders.getFirst(HEADER_TRANCACTION_KEY);
  String respPropagationStr = respHeaders.getFirst(HEADER_PROPAGATION_KEY);
  String transactionText = StringUtils.trimToNull(respTransactionStr);
  byte[] byteArray = StringUtils.isBlank(transactionText) ? null : Base64.getDecoder().decode(transactionText);
  TransactionContext serverContext = byteArray == null || byteArray.length == 0 //
      ? null : (TransactionContext) SerializeUtils.deserializeObject(byteArray);
  TransactionResponseImpl txResp = new TransactionResponseImpl();
  txResp.setTransactionContext(serverContext);
  RemoteCoordinator serverCoordinator = beanRegistry.getConsumeCoordinator(respPropagationStr);
  txResp.setSourceTransactionCoordinator(serverCoordinator);
  txResp.setParticipantDelistFlag(serverFlag ? false : true);
  transactionInterceptor.afterReceiveResponse(txResp);
}

相关文章

微信公众号

最新文章

更多

StringUtils类方法