本文整理了Java中org.apache.commons.collections4.CollectionUtils.filter()
方法的一些代码示例,展示了CollectionUtils.filter()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CollectionUtils.filter()
方法的具体详情如下:
包路径:org.apache.commons.collections4.CollectionUtils
类名称:CollectionUtils
方法名:filter
[英]Filter the collection by applying a Predicate to each element. If the predicate returns false, remove the element.
If the input collection or predicate is null, there is no change made.
[中]通过对每个元素应用谓词来筛选集合。如果谓词返回false,则删除元素。
如果输入集合或谓词为null,则不会进行任何更改。
代码示例来源:origin: gocd/gocd
private ArrayList<PluginFileDetails> findUpdatedPlugins(Set<PluginFileDetails> currentPluginFiles, Set<PluginFileDetails> knownPluginFileDetails) {
final ArrayList<PluginFileDetails> currentPlugins = new ArrayList<>(currentPluginFiles);
final ArrayList<PluginFileDetails> knownPlugins = new ArrayList<>(knownPluginFileDetails);
CollectionUtils.filter(knownPlugins, object -> {
PluginFileDetails knownPlugin = (PluginFileDetails) object;
int i = currentPlugins.indexOf(knownPlugin);
if (i == -1) {
return false;
}
PluginFileDetails plugin = currentPlugins.get(i);
return plugin.doesTimeStampDiffer(knownPlugin);
});
return knownPlugins;
}
代码示例来源:origin: gocd/gocd
public void filter(String filterCriteria) {
if (StringUtils.isBlank(filterCriteria)) {
return;
}
final Map<String, String> filters = filters(filterCriteria);
if (filters.isEmpty()) {
return;
}
CollectionUtils.filter(this, agent -> {
boolean finalResult = false;
for (Map.Entry<String, String> entry : filters.entrySet()) {
AgentFilters filter = AgentFilters.valueOf(entry.getKey().toUpperCase());
finalResult = finalResult || filter.matches(agent, entry.getValue());
}
return finalResult;
});
}
代码示例来源:origin: org.apache.commons/commons-collections4
/**
* Filter the collection by applying a Predicate to each element. If the
* predicate returns true, remove the element.
* <p>
* This is equivalent to <pre>filter(collection, PredicateUtils.notPredicate(predicate))</pre>
* if predicate is != null.
* <p>
* If the input collection or predicate is null, there is no change made.
*
* @param <T> the type of object the {@link Iterable} contains
* @param collection the collection to get the input from, may be null
* @param predicate the predicate to use as a filter, may be null
* @return true if the collection is modified by this call, false otherwise.
*/
public static <T> boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate) {
return filter(collection, predicate == null ? null : PredicateUtils.notPredicate(predicate));
}
代码示例来源:origin: org.apache.commons/commons-collections4
/**
* Factory method to create an ordered set using the supplied list to retain order.
* <p>
* A <code>HashSet</code> is used for the set behaviour.
* <p>
* NOTE: If the list contains duplicates, the duplicates are removed,
* altering the specified list.
*
* @param <E> the element type
* @param list the list to decorate, must not be null
* @return a new ordered set
* @throws NullPointerException if list is null
* @since 4.0
*/
public static <E> ListOrderedSet<E> listOrderedSet(final List<E> list) {
if (list == null) {
throw new NullPointerException("List must not be null");
}
CollectionUtils.filter(list, UniquePredicate.uniquePredicate());
final Set<E> set = new HashSet<>(list);
return new ListOrderedSet<>(set, list);
}
代码示例来源:origin: info.magnolia/magnolia-module-standard-templating-kit
/**
* Filters out items (nodes) which do not meet this condition: minDate <= itemDate && itemDate < maxDate.
*
* @param itemsList List of nodes.
* @param minDate Minimal date of the interval.
* @param maxDate Maximal date of the interval.
* @param datePropertyName Name of property in which is date stored.
* @param useCreationDate If true, then will look to MetaData for creation date and if exists, will use it as a date if no date found in property datePropertyName.
*/
public static void filterDateContentList(List<Node> itemsList, final Calendar minDate, final Calendar maxDate, final String datePropertyName, final boolean useCreationDate) {
CollectionUtils.filter(itemsList, new Predicate() {
@Override
public boolean evaluate(Object object) {
Node node = (Node) object;
Calendar date = resolveDate(node, datePropertyName, useCreationDate, Calendar.getInstance());
// INSMR-447: Increase milliseconds by one. Otherwise event will not be shown if date==minDate.
if (date.getTimeInMillis() == minDate.getTimeInMillis()) {
date.add(Calendar.SECOND, 1);
}
return date.after(minDate) && date.before(maxDate);
}
});
}
代码示例来源:origin: org.jbehave/jbehave-maven-plugin
private Set<Artifact> resourceArtifacts() {
Set<Artifact> artifacts = allArtifacts();
CollectionUtils.filter(artifacts, new Predicate<Artifact>() {
public boolean evaluate(Artifact artifact) {
return allowedBy("artifactId", artifact.getArtifactId(), resourceArtifactIds)
&& allowedBy("type", artifact.getType(), resourceTypes);
}
});
return artifacts;
}
代码示例来源:origin: tjg1/nori
/**
* Remove images not in the given set of {@link Image.SafeSearchRating} from this SearchResult.
*
* @param safeSearchRatings SafeSearch ratings to remove.
*/
public void filter(final Image.SafeSearchRating... safeSearchRatings) {
// Don't waste time filtering against an empty array.
if (safeSearchRatings == null || safeSearchRatings.length == 0) {
return;
}
// Concert filtered rating array to List
final List<Image.SafeSearchRating> ratingList = Arrays.asList(safeSearchRatings);
// Remove images containing filtered ratings.
CollectionUtils.filter(images, new Predicate<Image>() {
@Override
public boolean evaluate(Image image) {
return ratingList.contains(image.safeSearchRating);
}
});
reorderImagePageOffsets();
}
代码示例来源: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: Jimmy-Shi/bean-query
/**
* Execute this Query. If query from a null or empty collection, an empty list
* will be returned.
*
* @return
*/
public List<T> execute() {
if (CollectionUtils.isEmpty(from)) {
logger.info("Querying from an empty collection, returning empty list.");
return Collections.emptyList();
}
List copied = new ArrayList(this.from);
logger.info("Start apply predicate [{}] to collection with [{}] items.", predicate, copied.size());
CollectionUtils.filter(copied, this.predicate);
logger.info("Done filtering collection, filtered result size is [{}]", copied.size());
if (null != this.comparator && copied.size()>1) {
Comparator actualComparator = this.descSorting ? comparator.desc() : comparator.asc();
logger.info("Start to sort the filtered collection with comparator [{}]", actualComparator);
Collections.sort(copied, actualComparator);
logger.info("Done sorting the filtered collection.");
}
logger.info("Start to slect from filtered collection with selector [{}].", selector);
List<T> select = this.selector.select(copied);
logger.info("Done select from filtered collection.");
return select;
}
代码示例来源:origin: info.magnolia/magnolia-core
@Override
public Object merge(List sources) {
CollectionUtils.filter(sources, NotNullPredicate.INSTANCE);
if (sources.isEmpty()) {
return null;
}
if (sources.size() == 1 || isSimpleType(sources.get(0).getClass()) || !isMergeable(sources.get(0).getClass())) {
return sources.get(0);
}
if (sources.get(0) instanceof Collection) {
return mergeCollections(sources);
}
if (sources.get(0) instanceof Map) {
return mergeMaps(sources);
}
return mergeBean(sources);
}
代码示例来源:origin: com.haulmont.reports/reports-core
CollectionUtils.filter(filteredParams, predicate);
if (filteredParams.size() == 1) {
return metadata.getClass(filteredParams.get(0).getEntityMetaClass());
代码示例来源:origin: info.magnolia/magnolia-core
@Override
public Collection<Content> getChildren(final ContentFilter filter, final String namePattern, Comparator<Content> orderCriteria) {
// copy
final Collection<MockNode> children = ((MockNode) node).getChildren().values();
final Collection<Content> contentChildren = new ArrayList<Content>();
for (MockNode current : children) {
contentChildren.add(wrapAsContent(current));
}
final Predicate filterPredicate = new Predicate() {
@Override
public boolean evaluate(Object object) {
return filter.accept((Content) object);
}
};
CollectionUtils.filter(contentChildren, filterPredicate);
if (namePattern != null) {
CollectionUtils.filter(contentChildren, new NamePatternFilter(namePattern));
}
return contentChildren;
}
内容来源于网络,如有侵权,请联系作者删除!