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

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

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

StringUtils.defaultIfBlank介绍

[英]Returns either the passed in CharSequence, or if the CharSequence is whitespace, empty ("") or null, the value of defaultStr.

Whitespace is defined by Character#isWhitespace(char).

StringUtils.defaultIfBlank(null, "NULL")  = "NULL" 
StringUtils.defaultIfBlank("", "NULL")    = "NULL" 
StringUtils.defaultIfBlank(" ", "NULL")   = "NULL" 
StringUtils.defaultIfBlank("bat", "NULL") = "bat" 
StringUtils.defaultIfBlank("", null)      = null

[中]返回传入的CharSequence,或者如果CharSequence为空白、空(“”)或null,则返回defaultStr的值。
空格由字符#isWhitespace(char)定义。

StringUtils.defaultIfBlank(null, "NULL")  = "NULL" 
StringUtils.defaultIfBlank("", "NULL")    = "NULL" 
StringUtils.defaultIfBlank(" ", "NULL")   = "NULL" 
StringUtils.defaultIfBlank("bat", "NULL") = "bat" 
StringUtils.defaultIfBlank("", null)      = null

代码示例

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

public CacheServerDetails(final String bindAddress, final int port) {
 this.bindAddress = StringUtils.defaultIfBlank(bindAddress, "*");
 this.port = port;
}

代码示例来源:origin: Netflix/conductor

void recordRedisDaoPayloadSize(String action, int size, String taskType, String workflowType) {
    Monitors.recordDaoPayloadSize(DAO_NAME, action, StringUtils.defaultIfBlank(taskType,""), StringUtils.defaultIfBlank(workflowType,""), size);
  }
}

代码示例来源:origin: Netflix/conductor

void recordCassandraDaoPayloadSize(String action, int size, String taskType, String workflowType) {
  Monitors.recordDaoPayloadSize(DAO_NAME, action, StringUtils.defaultIfBlank(taskType, ""), StringUtils.defaultIfBlank(workflowType, ""), size);
}

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

/**
 * Gets the name of the log file used to log information about this Server.
 *
 * @return a String value indicating the name of this Server's log file.
 */
@Override
public String getLogFileName() {
 return defaultIfBlank(getMemberName(), DEFAULT_SERVER_LOG_NAME).concat(DEFAULT_SERVER_LOG_EXT);
}

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

/**
 * Gets the name of this member (this Server) in the GemFire distributed system as determined by
 * the 'name' GemFire property.
 *
 * @return a String indicating the name of the member (this Server) in the GemFire distributed
 *         system.
 */
@Override
public String getMemberName() {
 return defaultIfBlank(this.memberName, super.getMemberName());
}

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

/**
 * Gets the name of this member (this Locator) in the GemFire distributed system and determined by
 * the 'name' GemFire property.
 *
 * @return a String indicating the name of the member (this Locator) in the GemFire distributed
 *         system.
 */
@Override
public String getMemberName() {
 return defaultIfBlank(this.memberName, super.getMemberName());
}

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

/**
 * Gets the working directory pathname in which the Locator will be ran. If the directory is
 * unspecified, then working directory defaults to the current directory.
 *
 * @return a String indicating the working directory pathname.
 * @see #setWorkingDirectory(String)
 */
public String getWorkingDirectory() {
 return tryGetCanonicalPathElseGetAbsolutePath(
   new File(defaultIfBlank(this.workingDirectory, DEFAULT_WORKING_DIRECTORY)));
}

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

/**
 * Gets the name of the log file used to log information about this Locator.
 *
 * @return a String value indicating the name of this Locator's log file.
 */
@Override
public String getLogFileName() {
 return defaultIfBlank(getMemberName(), DEFAULT_LOCATOR_LOG_NAME)
   .concat(DEFAULT_LOCATOR_LOG_EXT);
}

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

/**
 * Gets the working directory pathname in which the Server will be ran. If the directory is
 * unspecified, then working directory defaults to the current directory.
 *
 * @return a String indicating the working directory pathname.
 * @see #setWorkingDirectory(String)
 */
public String getWorkingDirectory() {
 return tryGetCanonicalPathElseGetAbsolutePath(
   new File(defaultIfBlank(this.workingDirectory, DEFAULT_WORKING_DIRECTORY)));
}

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

protected String getDiskStoreName(final GatewaySender gateway) {
 return StringUtils.defaultIfBlank(gateway.getDiskStoreName(),
   DiskStoreDetails.DEFAULT_DISK_STORE_NAME);
}

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

protected String getDiskStoreName(final AsyncEventQueue queue) {
 return StringUtils.defaultIfBlank(queue.getDiskStoreName(),
   DiskStoreDetails.DEFAULT_DISK_STORE_NAME);
}

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

@Test
public void testDefaultIfBlank_CharBuffers() {
  assertEquals("NULL", StringUtils.defaultIfBlank(CharBuffer.wrap(""), CharBuffer.wrap("NULL")).toString());
  assertEquals("NULL", StringUtils.defaultIfBlank(CharBuffer.wrap(" "), CharBuffer.wrap("NULL")).toString());
  assertEquals("abc", StringUtils.defaultIfBlank(CharBuffer.wrap("abc"), CharBuffer.wrap("NULL")).toString());
  assertNull(StringUtils.defaultIfBlank(CharBuffer.wrap(""), null));
  // Tests compatibility for the API return type
  final CharBuffer s = StringUtils.defaultIfBlank(CharBuffer.wrap("abc"), CharBuffer.wrap("NULL"));
  assertEquals("abc", s.toString());
}

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

@Test
public void testDefaultIfBlank_StringBuffers() {
  assertEquals("NULL", StringUtils.defaultIfBlank(new StringBuffer(""), new StringBuffer("NULL")).toString());
  assertEquals("NULL", StringUtils.defaultIfBlank(new StringBuffer(" "), new StringBuffer("NULL")).toString());
  assertEquals("abc", StringUtils.defaultIfBlank(new StringBuffer("abc"), new StringBuffer("NULL")).toString());
  assertNull(StringUtils.defaultIfBlank(new StringBuffer(""), null));
  // Tests compatibility for the API return type
  final StringBuffer s = StringUtils.defaultIfBlank(new StringBuffer("abc"), new StringBuffer("NULL"));
  assertEquals("abc", s.toString());
}

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

@Test
public void testDefaultIfBlank_StringBuilders() {
  assertEquals("NULL", StringUtils.defaultIfBlank(new StringBuilder(""), new StringBuilder("NULL")).toString());
  assertEquals("NULL", StringUtils.defaultIfBlank(new StringBuilder(" "), new StringBuilder("NULL")).toString());
  assertEquals("abc", StringUtils.defaultIfBlank(new StringBuilder("abc"), new StringBuilder("NULL")).toString());
  assertNull(StringUtils.defaultIfBlank(new StringBuilder(""), null));
  // Tests compatibility for the API return type
  final StringBuilder s = StringUtils.defaultIfBlank(new StringBuilder("abc"), new StringBuilder("NULL"));
  assertEquals("abc", s.toString());
}

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

protected String getDiskStoreName(final Region region) {
 return StringUtils.defaultIfBlank(region.getAttributes().getDiskStoreName(),
   DiskStoreDetails.DEFAULT_DISK_STORE_NAME);
}

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

@Test
public void testDefaultIfBlank_StringString() {
  assertEquals("NULL", StringUtils.defaultIfBlank(null, "NULL"));
  assertEquals("NULL", StringUtils.defaultIfBlank("", "NULL"));
  assertEquals("NULL", StringUtils.defaultIfBlank(" ", "NULL"));
  assertEquals("abc", StringUtils.defaultIfBlank("abc", "NULL"));
  assertNull(StringUtils.defaultIfBlank("", null));
  // Tests compatibility for the API return type
  final String s = StringUtils.defaultIfBlank("abc", "NULL");
  assertEquals("abc", s);
}

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

@Override
public List<Command> getHighWatermarkMetadata(String schema, String entity, String watermarkColumn,
  List<Predicate> predicateList) throws HighWatermarkException {
 log.debug("Build query to get high watermark");
 List<Command> commands = new ArrayList<>();
 String columnProjection = "max(" + Utils.getCoalesceColumnNames(watermarkColumn) + ")";
 String watermarkFilter = StringUtils.defaultIfBlank(this.concatPredicates(predicateList), EMPTY_CONDITION);
 String query = this.getExtractSql();
 query = query.replace(this.getOutputColumnProjection(), columnProjection)
   .replace(ConfigurationKeys.DEFAULT_SOURCE_QUERYBASED_WATERMARK_PREDICATE_SYMBOL, watermarkFilter);
 commands.add(getCommand(query, JdbcCommand.JdbcCommandType.QUERY));
 return commands;
}

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

protected String getDiskStoreName(final CacheServer cacheServer) {
 return (cacheServer.getClientSubscriptionConfig() == null ? null
   : StringUtils.defaultIfBlank(cacheServer.getClientSubscriptionConfig().getDiskStoreName(),
     DiskStoreDetails.DEFAULT_DISK_STORE_NAME));
}

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

protected void setPdxSerializationDetails(final InternalCache cache, final DiskStore diskStore,
  final DiskStoreDetails diskStoreDetails) {
 if (cache.getPdxPersistent()) {
  String diskStoreName = StringUtils.defaultIfBlank(cache.getPdxDiskStore(),
    DiskStoreDetails.DEFAULT_DISK_STORE_NAME);
  diskStoreDetails.setPdxSerializationMetaDataStored(
    ObjectUtils.equals(diskStoreName, diskStore.getName()));
 }
}

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

private void setRegionDetails(final Region<?, ?> region, final DiskStore diskStore,
  final DiskStoreDetails diskStoreDetails) {
 if (isUsingDiskStore(region, diskStore)) {
  String regionFullPath = region.getFullPath();
  DiskStoreDetails.RegionDetails regionDetails = new DiskStoreDetails.RegionDetails(
    regionFullPath, StringUtils.defaultIfBlank(region.getName(), regionFullPath));
  regionDetails.setOverflowToDisk(isOverflowToDisk(region));
  regionDetails.setPersistent(isPersistent(region));
  diskStoreDetails.add(regionDetails);
 }
 for (Region<?, ?> subregion : region.subregions(false)) {
  setRegionDetails(subregion, diskStore, diskStoreDetails); // depth-first, recursive strategy
 }
}

相关文章

微信公众号

最新文章

更多

StringUtils类方法