org.apache.commons.collections4.CollectionUtils.emptyCollection()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(1.8k)|赞(0)|评价(0)|浏览(211)

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

CollectionUtils.emptyCollection介绍

[英]Returns the immutable EMPTY_COLLECTION with generic type safety.
[中]返回具有泛型类型安全性的不可变空\u集合。

代码示例

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

/**
 * Returns an immutable empty collection if the argument is <code>null</code>,
 * or the argument itself otherwise.
 *
 * @param <T> the element type
 * @param collection the collection, possibly <code>null</code>
 * @return an empty collection if the argument is <code>null</code>
 */
public static <T> Collection<T> emptyIfNull(final Collection<T> collection) {
  return collection == null ? CollectionUtils.<T>emptyCollection() : collection;
}

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

public static Collection intersection(final Iterable a, final Iterable b) {
  Collection response;
  if (!IterableUtils.isEmpty(a) && (a instanceof ArrayList) && !IterableUtils.isEmpty(b) && (b instanceof ArrayList)) {
    //TODO this is a bit of a hack to allow the intersection of two collections of different types. This is primarily
    //used to facilitate some MVEL execution. We really should be fixing the MVEL to call a method that retrieves
    //a list of Strings, rather than a list of ValueAssignables.
    Object aVal = ((ArrayList) a).get(0);
    Object bVal = ((ArrayList) b).get(0);
    if (aVal instanceof ValueAssignable && bVal instanceof String) {
      response = valueAssignableIntersection(a, b);
    } else {
      response = CollectionUtils.intersection(a, b);
    }
  } else {
    if (a == null || b == null) {
      return CollectionUtils.emptyCollection();
    }
    response = CollectionUtils.intersection(a, b);
  }
  return response;
}

相关文章