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

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

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

StringUtils.isEmpty介绍

[英]Checks if a CharSequence is empty ("") or null.

StringUtils.isEmpty(null)      = true 
StringUtils.isEmpty("")        = true 
StringUtils.isEmpty(" ")       = false 
StringUtils.isEmpty("bob")     = false 
StringUtils.isEmpty("  bob  ") = false

NOTE: This method changed in Lang version 2.0. It no longer trims the CharSequence. That functionality is available in isBlank().
[中]检查CharSequence是空(“”)还是空。

StringUtils.isEmpty(null)      = true 
StringUtils.isEmpty("")        = true 
StringUtils.isEmpty(" ")       = false 
StringUtils.isEmpty("bob")     = false 
StringUtils.isEmpty("  bob  ") = false

注意:此方法在Lang版本2.0中更改。它不再修剪字符序列。该功能在isBlank()中可用。

代码示例

代码示例来源:origin: weibocom/motan

public void addParameter(String name, String value) {
  if (StringUtils.isEmpty(name) || StringUtils.isEmpty(value)) {
    return;
  }
  parameters.put(name, value);
}

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

public T getPluginInfo(String pluginId) {
  if (isEmpty(pluginId)) {
    return null;
  }
  return pluginInfos.get(pluginId);
}

代码示例来源:origin: knightliao/disconf

/**
 * @param source
 * @param token
 *
 * @return
 */
public static List<String> parseStringToStringList(String source,
                          String token) {
  if (StringUtils.isBlank(source) || StringUtils.isEmpty(token)) {
    return null;
  }
  List<String> result = new ArrayList<String>();
  String[] units = source.split(token);
  for (String unit : units) {
    result.add(unit);
  }
  return result;
}

代码示例来源:origin: alibaba/nacos

public void valid() {
    if (!name.matches(DOMAIN_NAME_SYNTAX)) {
      throw new IllegalArgumentException("dom name can only have these characters: 0-9a-zA-Z-._:, current: " + name);
    }

    Map<String, List<String>> map = new HashMap<>(clusterMap.size());
    for (Cluster cluster : clusterMap.values()) {
      if (StringUtils.isEmpty(cluster.getSyncKey())) {
        continue;
      }
      List<String> list = map.get(cluster.getSyncKey());
      if (list == null) {
        list = new ArrayList<>();
        map.put(cluster.getSyncKey(), list);
      }

      list.add(cluster.getName());
      cluster.valid();
    }

    for (Map.Entry<String, List<String>> entry : map.entrySet()) {
      List<String> list = entry.getValue();
      if (list.size() > 1) {
        String msg = "clusters' config can not be the same: " + list;
        Loggers.SRV_LOG.warn(msg);
        throw new IllegalArgumentException(msg);
      }
    }
  }
}

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

@Override
public LinkedList<BackupMetadata> locate(String snapshotDate) {
  if (StringUtils.isEmpty(snapshotDate)) return null;
  // See if in memory
  if (backupMetadataMap.containsKey(snapshotDate)) return backupMetadataMap.get(snapshotDate);
  LinkedList<BackupMetadata> metadataLinkedList = fetch(snapshotDate);
  // Save the result in local cache so we don't hit data store/file.
  backupMetadataMap.put(snapshotDate, metadataLinkedList);
  return metadataLinkedList;
}

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

AgentBootstrapperBackwardCompatibility backwardCompatibility = backwardCompatibility(context);
String startupArgsString = env.get(AGENT_STARTUP_ARGS);
List<String> commandSnippets = new ArrayList<>();
commandSnippets.add(javaCmd());
if (!isEmpty(startupArgsString)) {
  String[] startupArgs = startupArgsString.split(" ");
  for (String startupArg : startupArgs) {
    String decodedStartupArg = startupArg.trim().replace("%20", " ");
    if (!isEmpty(decodedStartupArg)) {
      commandSnippets.add(decodedStartupArg);
extraProperties.forEach((key, value) -> commandSnippets.add(property(key, value)));
commandSnippets.add(property(GoConstants.AGENT_PLUGINS_MD5, agentPluginsZipMd5));

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

@Override
  public List<AbstractModule> getAdditionalModules() {

    String additionalModuleClasses = getProperty(ADDITIONAL_MODULES_PROPERTY_NAME, null);

    List<AbstractModule> modules = new LinkedList<>();

    if (!StringUtils.isEmpty(additionalModuleClasses)) {
      try {
        String[] classes = additionalModuleClasses.split(",");
        for (String clazz : classes) {
          Object moduleObj = Class.forName(clazz).newInstance();
          if (moduleObj instanceof AbstractModule) {
            AbstractModule abstractModule = (AbstractModule) moduleObj;
            modules.add(abstractModule);
          } else {
            logger.error(clazz + " does not implement " + AbstractModule.class.getName() + ", skipping...");
          }
        }
      } catch (Exception e) {
        logger.warn(e.getMessage(), e);
      }
    }

    return modules;
  }
}

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

for (JsonNode eventNode : eventsNode) {
  JsonNode eventValueNode = eventNode.get(PROPERTY_EVENTLISTENER_EVENT);
  if (eventValueNode != null && !eventValueNode.isNull() && StringUtils.isNotEmpty(eventValueNode.asText())) {
    if (eventsBuilder.length() > 0) {
      eventsBuilder.append(",");
    if ("error".equalsIgnoreCase(rethrowTypeNode.asText())) {
      String errorCode = getValueAsString("errorcode", listenerNode);
      if (StringUtils.isNotEmpty(errorCode)) {
        listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_THROW_ERROR_EVENT);
        listener.setImplementation(errorCode);
      if (StringUtils.isNotEmpty(messageName)) {
        listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_THROW_MESSAGE_EVENT);
        listener.setImplementation(messageName);
  if (StringUtils.isEmpty(listener.getImplementation())) {
    continue;
  if (StringUtils.isEmpty(listener.getImplementation())) {
    continue;
process.getEventListeners().add(listener);

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

LOG.error("No HiveServer2 instances are running in HA mode");
 System.err.println("No HiveServer2 instances are running in HA mode");
 System.exit(-1);
 LOG.error("Cannot find any HiveServer2 instance with workerIdentity: " + workerIdentity);
 System.err.println("Cannot find any HiveServer2 instance with workerIdentity: " + workerIdentity);
 System.exit(-1);
 LOG.error("Only one HiveServer2 instance running in thefail cluster. Cannot failover: " + workerIdentity);
 System.err.println("Only one HiveServer2 instance running in the cluster. Cannot failover: " + workerIdentity);
 System.exit(-1);
String webPort = targetInstance.getProperties().get(ConfVars.HIVE_SERVER2_WEBUI_PORT.varname);
if (StringUtils.isEmpty(webPort)) {
 LOG.error("Unable to determine web port for instance: " + workerIdentity);
 System.err.println("Unable to determine web port for instance: " + workerIdentity);

代码示例来源:origin: alibaba/nacos

Map<String, String> tmpParams = new HashMap<>(16);
for (Map.Entry<String, String[]> entry : request.getParameterMap().entrySet()) {
  tmpParams.put(entry.getKey(), entry.getValue()[0]);
  String limitedUrls = WebUtils.required(request, "limitedUrls");
  if (!StringUtils.isEmpty(limitedUrls)) {
    String[] entries = limitedUrls.split(",");
    for (int i = 0; i < entries.length; i++) {
      if (StringUtils.isEmpty(limitedUrl)) {
        throw new IllegalArgumentException("url can not be empty, url: " + limitedUrl);
      limitedUrlMap.put(limitedUrl, statusCode);
  String enable = WebUtils.required(request, "enableStandalone");
  if (!StringUtils.isNotEmpty(enable)) {
    Switch.setEnableStandalone(Boolean.parseBoolean(enable));

代码示例来源:origin: alibaba/nacos

domObj.setEnableClientBeat(eanbleClientBeat);
if (StringUtils.isNotEmpty(serviceMetadataJson)) {
  domObj.setMetadata(JSON.parseObject(serviceMetadataJson, new TypeReference<Map<String, String>>() {
  }));
if (StringUtils.isNotEmpty(envAndSite) && StringUtils.isNotEmpty(disabledSites)) {
  throw new IllegalArgumentException("envAndSite and disabledSites are not allowed both not empty.");
if (!StringUtils.isEmpty(clusters)) {
    domObj.getClusterMap().put(cluster.getName(), cluster);
  domObj.getClusterMap().put(clusterName, cluster);

代码示例来源:origin: knightliao/disconf

/**
 * 对于一个 get/is 方法,返回其相对应的Field
 */
public static Field getFieldFromMethod(Method method, Field[] expectedFields, DisConfigTypeEnum disConfigTypeEnum) {
  String fieldName;
  if (disConfigTypeEnum.equals(DisConfigTypeEnum.FILE)) {
    DisconfFileItem disconfFileItem = method.getAnnotation(DisconfFileItem.class);
    // 根据用户设定的注解来获取
    fieldName = disconfFileItem.associateField();
  } else {
    DisconfItem disItem = method.getAnnotation(DisconfItem.class);
    // 根据用户设定的注解来获取
    fieldName = disItem.associateField();
  }
  //
  // 如果用户未设定注解,则猜其名字
  //
  if (StringUtils.isEmpty(fieldName)) {
    // 从方法名 获取其 Field 名
    fieldName = ClassUtils.getFieldNameByGetMethodName(method.getName());
  }
  // 确认此Field名是正确的
  for (Field field : expectedFields) {
    if (field.getName().equals(fieldName)) {
      return field;
    }
  }
  LOGGER.error(method.toString() + " cannot get its related field name. ");
  return null;
}

代码示例来源:origin: alibaba/nacos

if (!StringUtils.isEmpty(owners)) {
  dom.setOwners(Arrays.asList(owners.split(",")));
if (!StringUtils.isEmpty(token)) {
  dom.setToken(token);
if (!StringUtils.isEmpty(enableClientBeat)) {
  dom.setEnableClientBeat(Boolean.parseBoolean(enableClientBeat));
if (!StringUtils.isEmpty(protectThreshold)) {
  dom.setProtectThreshold(Float.parseFloat(protectThreshold));
if (!StringUtils.isEmpty(sitegroup) || !StringUtils.isEmpty(setSiteGroupForce)) {
  Cluster cluster
    = dom.getClusterMap().get(WebUtils.optional(request, "cluster", UtilsAndCommons.DEFAULT_CLUSTER_NAME));
  if (cluster == null) {
    throw new IllegalStateException("cluster not found");
if (!StringUtils.isEmpty(cktype)) {
  Cluster cluster
    = dom.getClusterMap().get(WebUtils.optional(request, "cluster", UtilsAndCommons.DEFAULT_CLUSTER_NAME));
  if (cluster == null) {
    throw new IllegalStateException("cluster not found");
if (!StringUtils.isEmpty(defIPPort)) {
  Cluster cluster
    = dom.getClusterMap().get(WebUtils.optional(request, "cluster", UtilsAndCommons.DEFAULT_CLUSTER_NAME));
  if (cluster == null) {
    throw new IllegalStateException("cluster not found");

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

String externalId = getValue("externalId", payloadJSON);
if(externalId == null || "".equals(externalId)) {
  logger.error("No external Id found in the payload {}", payload);
  queue.ack(Arrays.asList(msg));
  return;
if(workflowId == null || "".equals(workflowId)) {
  logger.error("No workflow id found in the message. {}", payload);
  queue.ack(Arrays.asList(msg));
  return;
if (StringUtils.isNotEmpty(taskId)) {
  taskOptional = workflow.getTasks().stream().filter(task -> !task.getStatus().isTerminal() && task.getTaskId().equals(taskId)).findFirst();
} else if(StringUtils.isEmpty(taskRefName)) {
  logger.error("No taskRefName found in the message. If there is only one WAIT task, will mark it as completed. {}", payload);
  taskOptional = workflow.getTasks().stream().filter(task -> !task.getStatus().isTerminal() && task.getTaskType().equals(Wait.NAME)).findFirst();
} else {

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

protected static String findMatchingExceptionMapping(Exception e, List<MapExceptionEntry> exceptionMap) {
 String defaultExceptionMapping = null;
 for (MapExceptionEntry me : exceptionMap) {
  String exceptionClass = me.getClassName();
  String errorCode = me.getErrorCode();
  // save the first mapping with no exception class as default map
  if (StringUtils.isNotEmpty(errorCode) && StringUtils.isEmpty(exceptionClass) && defaultExceptionMapping == null) {
   defaultExceptionMapping = errorCode;
   continue;
  }
  // ignore if error code or class are not defined
  if (StringUtils.isEmpty(errorCode) || StringUtils.isEmpty(exceptionClass)) {
   continue;
  }
  if (e.getClass().getName().equals(exceptionClass)) {
   return errorCode;
  }
  if (me.isAndChildren()) {
   Class<?> exceptionClassClass = ReflectUtil.loadClass(exceptionClass);
   if (exceptionClassClass.isAssignableFrom(e.getClass())) {
    return errorCode;
   }
  }
 }
 return defaultExceptionMapping;
}

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

String jobId = info.get(MR_JOB_ID);
  if (jobId.startsWith("job_")) {
    info.put(YARN_APP_ID, jobId.replace("job_", "application_"));
if (info.containsKey(YARN_APP_ID) && !StringUtils.isEmpty(config.getJobTrackingURLPattern())) {
  String pattern = config.getJobTrackingURLPattern();
  try {
    String newTrackingURL = String.format(Locale.ROOT, pattern, info.get(YARN_APP_ID));
    info.put(YARN_APP_URL, newTrackingURL);
  } catch (IllegalFormatException ife) {
    logger.error("Illegal tracking url pattern: " + config.getJobTrackingURLPattern());
  executableDao.updateJobOutput(output);
} catch (PersistentException e) {
  logger.error("error update job info, id:" + id + "  info:" + info.toString());
  throw new RuntimeException(e);

代码示例来源:origin: knightliao/disconf

/**
 * @param source
 * @param token
 *
 * @return
 */
public static List<Long> parseStringToLongList(String source, String token) {
  if (StringUtils.isBlank(source) || StringUtils.isEmpty(token)) {
    return null;
  }
  List<Long> result = new ArrayList<Long>();
  String[] units = source.split(token);
  for (String unit : units) {
    result.add(Long.valueOf(unit));
  }
  return result;
}

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

public static boolean isEmpty(Object attributes) {
    return attributes == null || StringUtils.isEmpty((String) ((Map)attributes).get(MQL));
  }
}

代码示例来源:origin: alibaba/nacos

public static void setPushCacheMillis(String dom, Long cacheMillis) {
  if (StringUtils.isEmpty(dom)) {
    Switch.dom.defaultPushCacheMillis = cacheMillis;
  } else {
    Switch.dom.pushCacheMillisMap.put(dom, cacheMillis);
  }
}

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

public String[] getEmbeddedPropertyNames(TblColRef column) {
  final String colName = column.getName().toLowerCase(Locale.ROOT);
  String[] names = nameMap.get(colName);
  if (names == null) {
    String comment = column.getColumnDesc().getComment(); // use comment to parse the structure
    if (!StringUtils.isEmpty(comment) && comment.contains(EMBEDDED_PROPERTY_SEPARATOR)) {
      names = comment.toLowerCase(Locale.ROOT).split("\\" + EMBEDDED_PROPERTY_SEPARATOR);
      nameMap.put(colName, names);
    } else if (colName.contains(separator)) { // deprecated, just be compitable for old version
      names = colName.toLowerCase(Locale.ROOT).split(separator);
      nameMap.put(colName, names);
    }
  }
  return names;
}

相关文章

StringUtils类方法