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

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

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

CollectionUtils.removeAll介绍

[英]Removes all elements in remove from collection. That is, this method returns a collection containing all the elements in collection that are not in remove. The cardinality of an element e in the returned collection is the same as the cardinality of e in collection unless remove contains e, in which case the cardinality is zero. This method is useful if you do not wish to modify the collection c and thus cannot call collection.removeAll(remove).

Moreover this method uses an Equator instead of Object#equals(Object) to determine the equality of the elements in collection and remove. Hence this method is useful in cases where the equals behavior of an object needs to be modified without changing the object itself.
[中]从collection中删除remove中的所有元素。也就是说,此方法返回一个集合,其中包含collection中不在remove中的所有元素。返回集合中的元素e的基数与collection中的e的基数相同,除非remove包含e,在这种情况下,基数为零。如果您不希望修改集合c,因此无法调用collection.removeAll(remove),则此方法非常有用。
此外,该方法使用赤道代替对象#equals(Object)来确定collectionremove中元素的相等性。因此,在需要修改对象的equals行为而不更改对象本身的情况下,此方法非常有用。

代码示例

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

CollectionUtils.removeAll(columnfamilies, excludeCFFilter);

代码示例来源:origin: nuls-io/nuls

public static void checkClass(Map<String, ClassCode> classCodes) {
  Set<String> allClass = allClass(classCodes);
  Set<String> classCodeNames = classCodes.values().stream().map(classCode -> classCode.name).collect(Collectors.toSet());
  Collection<String> classes = CollectionUtils.removeAll(allClass, classCodeNames);
  Collection<String> classes1 = CollectionUtils.removeAll(classes, Arrays.asList(ProgramConstants.SDK_CLASS_NAMES));
  Collection<String> classes2 = CollectionUtils.removeAll(classes1, Arrays.asList(ProgramConstants.CONTRACT_USED_CLASS_NAMES));
  Collection<String> classes3 = CollectionUtils.removeAll(classes2, Arrays.asList(ProgramConstants.CONTRACT_LAZY_USED_CLASS_NAMES));
  if (classes3.size() > 0) {
    throw new RuntimeException(String.format("can't use classes: %s", Joiner.on(", ").join(classes3)));
  }
}

代码示例来源:origin: org.ligoj.api/plugin-core

/**
 * Check the given parameters do not overrides a valued parameter.
 */
private void checkOverrides(final List<String> acceptedParameters, final List<String> parameters) {
  final Collection<String> overrides = CollectionUtils.removeAll(parameters, acceptedParameters);
  if (!overrides.isEmpty()) {
    // A non acceptable parameter. An attempt to override a secured data?
    throw ValidationJsonException.newValidationJsonException("not-accepted-parameter",
        overrides.iterator().next());
  }
}

代码示例来源:origin: tjg1/nori

/**
 * Remove images with the given set of {@link Tag}s from this SearchResult.
 *
 * @param tags Tags to remove.
 */
public void filter(final Tag... tags) {
 // Don't waste time filtering against an empty array.
 if (tags == null || tags.length == 0) {
  return;
 }
 // Don't filter tags searched for by the user.
 final Collection<Tag> tagList = CollectionUtils.removeAll(Arrays.asList(tags), Arrays.asList(query));
 // Remove images containing filtered tags.
 CollectionUtils.filter(images, new Predicate<Image>() {
  @Override
  public boolean evaluate(Image image) {
   return !CollectionUtils.containsAny(Arrays.asList(image.tags), tagList);
  }
 });
 reorderImagePageOffsets();
}

代码示例来源:origin: org.ligoj.api/plugin-core

/**
 * Update the given node parameter values. The old not updated values are deleted.
 * 
 * @param values
 *            the parameter values to persist.
 * @param node
 *            The related node.
 */
public void update(final List<ParameterValueCreateVo> values, final Node node) {
  // Build the old parameter values
  final List<ParameterValue> oldList = repository.getParameterValues(node.getId());
  final Map<String, ParameterValue> oldMap = oldList.stream()
      .collect(Collectors.toMap(v -> v.getParameter().getId(), Function.identity()));
  // Build the target parameter values
  final Set<String> newParam = values.stream().map(v -> saveOrUpdate(oldMap, v)).filter(Objects::nonNull)
      .peek(v -> v.setNode(node)).map(repository::saveAndFlush).map(v -> v.getParameter().getId())
      .collect(Collectors.toSet());
  // Delete the existing but not provided values
  CollectionUtils.removeAll(oldMap.keySet(), newParam).stream().map(oldMap::get).forEach(repository::delete);
  cacheManager.getCache("node-parameters").evict(node.getId());
}

代码示例来源:origin: com.haulmont.cuba/cuba-web

@Override
public void ungroupByColumns(String... columnIds) {
  checkNotNullArgument(columnIds);
  if (uselessGrouping(columnIds)) {
    return;
  }
  Object[] remainingGroups = CollectionUtils
      .removeAll(component.getGroupProperties(), collectPropertiesByColumns(columnIds))
      .toArray();
  groupBy(remainingGroups);
}

相关文章