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

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

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

CollectionUtils.isSubCollection介绍

[英]Returns true iff a is a sub-collection of b, that is, iff the cardinality of e in a is less than or equal to the cardinality of e in b, for each element e in a.
[中]返回true如果a是b的子集合,也就是说,对于a中的每个元素e,如果a中e的基数小于或等于b中e的基数。

代码示例

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

@Override
public void putAll(final Map<? extends K, ? extends V> mapToCopy) {
  if (CollectionUtils.isSubCollection(mapToCopy.keySet(), keySet())) {
    throw new IllegalArgumentException("Cannot put new key/value pair - Map is fixed size");
  }
  map.putAll(mapToCopy);
}

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

/**
 * Returns {@code true} iff <i>a</i> is a <i>proper</i> sub-collection of <i>b</i>,
 * that is, iff the cardinality of <i>e</i> in <i>a</i> is less
 * than or equal to the cardinality of <i>e</i> in <i>b</i>,
 * for each element <i>e</i> in <i>a</i>, and there is at least one
 * element <i>f</i> such that the cardinality of <i>f</i> in <i>b</i>
 * is strictly greater than the cardinality of <i>f</i> in <i>a</i>.
 * <p>
 * The implementation assumes
 * <ul>
 *    <li><code>a.size()</code> and <code>b.size()</code> represent the
 *    total cardinality of <i>a</i> and <i>b</i>, resp. </li>
 *    <li><code>a.size() &lt; Integer.MAXVALUE</code></li>
 * </ul>
 *
 * @param a  the first (sub?) collection, must not be null
 * @param b  the second (super?) collection, must not be null
 * @return <code>true</code> iff <i>a</i> is a <i>proper</i> sub-collection of <i>b</i>
 * @see #isSubCollection
 * @see Collection#containsAll
 */
public static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b) {
  return a.size() < b.size() && CollectionUtils.isSubCollection(a, b);
}

代码示例来源:origin: Evolveum/midpoint

/**
 * If M2 has a source of X, and M1 has a target of X, then M1 must be placed before M2; we want also to detect cycles.
 *
 * So let's stratify mappings according to their dependencies.
 */
private List<FocalMappingSpec> sortMappingsByDependencies(List<FocalMappingSpec> mappings) {
  // map.get(X) = { Y1 ... Yn } means that mapping X depends on output of mappings Y1 ... Yn
  // using indices instead of actual mappings because of equality issues
  Map<Integer, Set<Integer>> dependencyMap = createDependencyMap(mappings);
  LOGGER.trace("sortMappingsByDependencies: dependencyMap: {}", dependencyMap);
  List<Integer> processed = new ArrayList<>();
  List<Integer> toProcess = Stream.iterate(0, t -> t+1).limit(mappings.size()).collect(Collectors.toList());		// not a set: to preserve original order
  while (!toProcess.isEmpty()) {
    LOGGER.trace("sortMappingsByDependencies: toProcess: {}, processed: {}", toProcess, processed);
    Integer available = toProcess.stream()
        .filter(i -> CollectionUtils.isSubCollection(dependencyMap.get(i), processed))	// cannot depend on yet-unprocessed mappings
        .findFirst().orElse(null);
    if (available == null) {
      LOGGER.warn("Cannot sort mappings according to dependencies, there is a cycle. Processing in the original order: {}", mappings);
      return mappings;
    }
    processed.add(available);
    toProcess.remove(available);
  }
  LOGGER.trace("sortMappingsByDependencies: final ordering: {}", processed);
  return processed.stream().map(i -> mappings.get(i)).collect(Collectors.toList());
}

代码示例来源:origin: info.magnolia/magnolia-core

/**
 * Returns:
 * +1 if all mandatory dispatchers are present and no additional unsupported dispatcher is present, or this filter class isn't registered.
 * 0  if all mandatory dispatchers are present but additional unsupported dispatchers are present.
 * -1  if not all mandatory dispatchers are present.
 */
public int checkFilterDispatchersConfiguration(String filterClass, List mandatoryDispatchers, List optionalDispatchers) {
  final Element filterEl = getFilterElement(filterClass);
  if (filterEl != null) {
    final String filterName = filterEl.getTextNormalize();
    final String filterMappingXPathExpr = "/webxml:web-app/webxml:filter-mapping[webxml:filter-name='" + filterName + "']/webxml:dispatcher";
    final List dispatchersEl = getElementsFromXPath(filterMappingXPathExpr);
    final List registeredDispatchers = new ArrayList();
    final Iterator it = dispatchersEl.iterator();
    while (it.hasNext()) {
      final Element dispatcherEl = (Element) it.next();
      registeredDispatchers.add(dispatcherEl.getTextNormalize());
    }
    registeredDispatchers.removeAll(optionalDispatchers);
    if (CollectionUtils.isEqualCollection(mandatoryDispatchers, registeredDispatchers)) {
      return 1;
    } else if (CollectionUtils.isSubCollection(mandatoryDispatchers, registeredDispatchers)) {
      return 0;
    } else {
      return -1;
    }
  }
  return 1;
}

相关文章