本文整理了Java中org.apache.commons.collections4.CollectionUtils.subtract()
方法的一些代码示例,展示了CollectionUtils.subtract()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CollectionUtils.subtract()
方法的具体详情如下:
包路径:org.apache.commons.collections4.CollectionUtils
类名称:CollectionUtils
方法名:subtract
[英]Returns a new Collection containing a - b. The cardinality of each element e in the returned Collectionwill be the cardinality of e in a minus the cardinality of e in b, or zero, whichever is greater.
[中]返回一个包含a-b的新集合。返回集合中每个元素e的基数将是a中e的基数减去b中e的基数,或零,以较大者为准。
代码示例来源:origin: gocd/gocd
private void scheduleRecentlyAddedMaterialsForUpdate() {
Collection<Material> materialsBeforeConfigChange = dependencyMaterials.values();
this.dependencyMaterials = dependencyMaterials();
Collection<Material> materialsAfterConfigChange = dependencyMaterials.values();
Collection newMaterials = CollectionUtils.subtract(materialsAfterConfigChange, materialsBeforeConfigChange);
for (Object material : newMaterials) {
updateMaterial((Material) material);
}
}
代码示例来源:origin: org.apache.commons/commons-collections4
/**
* Returns a new {@link Collection} containing {@code <i>a</i> - <i>b</i>}.
* The cardinality of each element <i>e</i> in the returned {@link Collection}
* will be the cardinality of <i>e</i> in <i>a</i> minus the cardinality
* of <i>e</i> in <i>b</i>, or zero, whichever is greater.
*
* @param a the collection to subtract from, must not be null
* @param b the collection to subtract, must not be null
* @param <O> the generic type that is able to represent the types contained
* in both input collections.
* @return a new collection with the results
* @see Collection#removeAll
*/
public static <O> Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b) {
final Predicate<O> p = TruePredicate.truePredicate();
return subtract(a, b, p);
}
代码示例来源:origin: gocd/gocd
public boolean shouldBeIgnoredByFilterIn(MaterialConfig materialConfig) {
if (materialConfig.filter().shouldNeverIgnore()) {
return false;
}
Set<ModifiedFile> allFiles = getAllFiles(this);
Set<ModifiedFile> ignoredFiles = new HashSet<>();
for (ModifiedFile file : allFiles) {
appyIgnoreFilter(materialConfig, file, ignoredFiles);
}
LOG.debug("Checking ignore filters for {}", materialConfig);
LOG.debug("Ignored files: {}", ignoredFiles);
LOG.debug("Changed files: {}", CollectionUtils.subtract(allFiles, ignoredFiles));
if (materialConfig.isInvertFilter()) {
// return true (ignore) if we are inverting the filter, and the ignoredFiles and allFiles are disjoint sets
return Collections.disjoint(allFiles, ignoredFiles);
} else {
return ignoredFiles.containsAll(allFiles);
}
}
代码示例来源:origin: org.apache.bookkeeper/bookkeeper-server
@SuppressWarnings("unchecked")
public Collection<BookieSocketAddress> getPartialScanTargets() {
return CollectionUtils.subtract(mostRecentlyReportedBookies, infoMap.keySet());
}
代码示例来源:origin: Evolveum/midpoint
private AccessCertificationResponseType extractStageOutcome(Set<AccessCertificationResponseType> stageOutcomes, Long caseId, int stage) {
Collection<AccessCertificationResponseType> nonNullOutcomes = CollectionUtils.subtract(stageOutcomes, singleton(NO_RESPONSE));
if (nonNullOutcomes.size() > 1) {
throw new IllegalStateException("Contradictory outcomes for case " + caseId + " in stage " + stage + ": " + stageOutcomes);
} else if (!nonNullOutcomes.isEmpty()) {
return nonNullOutcomes.iterator().next();
} else if (!stageOutcomes.isEmpty()) {
return NO_RESPONSE;
} else {
return null;
}
}
}
代码示例来源:origin: com.github.wenweihu86.rpc/rpc-java
public void updateEndPoints(List<EndPoint> newEndPoints) {
Collection<EndPoint> addList = CollectionUtils.subtract(newEndPoints, endPoints);
Collection<EndPoint> deleteList = CollectionUtils.subtract(endPoints, newEndPoints);
for (EndPoint endPoint : addList) {
addEndPoint(endPoint);
}
for (EndPoint endPoint : deleteList) {
deleteEndPoint(endPoint);
}
}
代码示例来源:origin: com.baidu/brpc-java
public void updateEndPoints(List<EndPoint> newEndPoints) {
Collection<EndPoint> addList = CollectionUtils.subtract(newEndPoints, endPoints);
Collection<EndPoint> deleteList = CollectionUtils.subtract(endPoints, newEndPoints);
for (EndPoint endPoint : addList) {
addEndPoint(endPoint);
}
for (EndPoint endPoint : deleteList) {
deleteEndPoint(endPoint);
}
}
代码示例来源:origin: com.baidu/brpc-java
@Override
public void run(Timeout timeout) throws Exception {
try {
List<EndPoint> currentEndPoints = lookup(null);
Collection<EndPoint> addList = CollectionUtils.subtract(
currentEndPoints, lastEndPoints);
Collection<EndPoint> deleteList = CollectionUtils.subtract(
lastEndPoints, currentEndPoints);
listener.notify(addList, deleteList);
} catch (Exception ex) {
// ignore exception
}
namingServiceTimer.newTimeout(this, updateInterval, TimeUnit.MILLISECONDS);
}
},
代码示例来源:origin: baidu/brpc-java
@Override
public void run(Timeout timeout) throws Exception {
try {
List<EndPoint> currentEndPoints = lookup(null);
Collection<EndPoint> addList = CollectionUtils.subtract(
currentEndPoints, lastEndPoints);
Collection<EndPoint> deleteList = CollectionUtils.subtract(
lastEndPoints, currentEndPoints);
listener.notify(addList, deleteList);
} catch (Exception ex) {
// ignore exception
}
namingServiceTimer.newTimeout(this, updateInterval, TimeUnit.MILLISECONDS);
}
},
代码示例来源:origin: org.ligoj.plugin/plugin-id-ldap
@Override
public void updateMembership(final Collection<String> groups, final UserOrg user) {
// Add new groups
addUserToGroups(user, CollectionUtils.subtract(groups, user.getGroups()));
// Remove old groups
removeUserFromGroups(user, CollectionUtils.subtract(user.getGroups(), groups));
}
代码示例来源:origin: ontopia/ontopia
public void setScope(ScopedIF scoped, Collection<Topic> scope) {
if (scope != null) {
Collection<TopicIF> newScope = new HashSet<>(scope.size());
for (Topic t : scope) {
TopicIF resolved = topic.resolve(scoped.getTopicMap(), t);
newScope.add(resolved);
scoped.addTheme(resolved);
}
for (TopicIF remove : CollectionUtils.subtract(scoped.getScope(), newScope)) {
scoped.removeTheme(remove);
}
}
}
代码示例来源:origin: Nepxion/Thunder
private void consistBatch(String interfaze, List<ApplicationEntity> remoteList) throws Exception {
List<ApplicationEntity> localList = cacheContainer.getConnectionCacheEntity().getApplicationEntityList(interfaze);
if (!CollectionUtils.isEqualCollection(localList, remoteList)) {
List<ApplicationEntity> intersectedList = (List<ApplicationEntity>) CollectionUtils.intersection(localList, remoteList);
List<ApplicationEntity> onlineList = (List<ApplicationEntity>) CollectionUtils.subtract(remoteList, intersectedList);
List<ApplicationEntity> offlineList = (List<ApplicationEntity>) CollectionUtils.subtract(localList, intersectedList);
consistBatchClient(interfaze, onlineList, true);
consistBatchClient(interfaze, offlineList, false);
}
}
代码示例来源:origin: ontopia/ontopia
public void setTypes(TopicIF object, Topic pojo) {
if (pojo.getTypes() != null) {
Collection<TopicIF> newTypes = new HashSet<>(pojo.getTypes().size());
for (Topic t : pojo.getTypes()) {
TopicIF resolved = resolve(object.getTopicMap(), t);
newTypes.add(resolved);
}
for (TopicIF remove : CollectionUtils.subtract(object.getTypes(), newTypes)) {
object.removeType(remove);
}
for (TopicIF add : newTypes) {
object.addType(add);
}
}
}
代码示例来源:origin: info.magnolia.ui/magnolia-ui-api
@SuppressWarnings("unchecked")
@Override
public Set<DefinitionMetadata> unregisterAndRegister(Collection<DefinitionMetadata> metaDataToUnregister, Collection<DefinitionProvider<AppDescriptor>> providersToRegister) {
Collection<DefinitionMetadata> metadataBefore = getRegistryMap().keySet();
Collection<DefinitionProvider<AppDescriptor>> providersBefore = getRegistryMap().values();
Set<DefinitionMetadata> registeredMetaData = super.unregisterAndRegister(metaDataToUnregister, providersToRegister);
Collection<DefinitionMetadata> metadataAfter = getRegistryMap().keySet();
Collection<DefinitionMetadata> added = CollectionUtils.subtract(metadataAfter, metadataBefore);
Collection<DefinitionMetadata> removed = CollectionUtils.subtract(metadataBefore, metadataAfter);
Collection<DefinitionMetadata> kept = CollectionUtils.subtract(metadataBefore, removed);
Collection<DefinitionMetadata> changed = getAppsThatHaveChanged(kept, providersBefore, providersToRegister);
sendEvent(AppRegistryEventType.REGISTERED, added);
sendEvent(AppRegistryEventType.UNREGISTERED, removed);
sendEvent(AppRegistryEventType.REREGISTERED, changed);
return registeredMetaData;
}
代码示例来源:origin: org.opensingular/singular-requirement-commons
public DocumentationMetadataBuilder(SType<?> rootStype) {
initTypeByNameCache(rootStype);
tableRoots = identifyTablesRoots(rootStype);
LinkedHashSet<SType<?>> tableRootsSTypes = tableRoots.stream().flatMap(d -> d.getRootSTypes().stream()).collect(LinkedHashSet::new, LinkedHashSet::add, LinkedHashSet::addAll);
for (DocTable docTable : tableRoots) {
LinkedHashSet<DocBlock> docBlocks = identifyBlocks(docTable.getRootSTypes(), tableRootsSTypes);
docTable.addAllDocBlocks(docBlocks);
LinkedHashSet<SType<?>> allTypesAssociatedToBlocks = gatherAllSTypesAssociatedToBlocks(docBlocks);
allTypesAssociatedToBlocks.addAll(tableRootsSTypes);
for (DocBlock docBlock : docBlocks) {
LinkedHashSet<DocFieldMetadata> docFieldMetadata = identifyFields(rootStype, docBlock, CollectionUtils.subtract(allTypesAssociatedToBlocks, docBlock.getBlockTypes()));
docBlock.addAllFieldsMetadata(docFieldMetadata);
}
}
}
代码示例来源:origin: org.opensingular/singular-requirement-module
public DocumentationMetadataBuilder(SType<?> rootStype) {
initTypeByNameCache(rootStype);
tableRoots = identifyTablesRoots(rootStype);
LinkedHashSet<SType<?>> tableRootsSTypes = tableRoots.stream().flatMap(d -> d.getRootSTypes().stream()).collect(LinkedHashSet::new, LinkedHashSet::add, LinkedHashSet::addAll);
for (DocTable docTable : tableRoots) {
LinkedHashSet<DocBlock> docBlocks = identifyBlocks(docTable.getRootSTypes(), tableRootsSTypes);
docTable.addAllDocBlocks(docBlocks);
LinkedHashSet<SType<?>> allTypesAssociatedToBlocks = gatherAllSTypesAssociatedToBlocks(docBlocks);
allTypesAssociatedToBlocks.addAll(tableRootsSTypes);
for (DocBlock docBlock : docBlocks) {
LinkedHashSet<DocFieldMetadata> docFieldMetadata = identifyFields(rootStype, docBlock, CollectionUtils.subtract(allTypesAssociatedToBlocks, docBlock.getBlockTypes()));
docBlock.addAllFieldsMetadata(docFieldMetadata);
}
}
}
代码示例来源:origin: org.opensingular/singular-server-commons
public DocumentationMetadataBuilder(SType<?> rootStype) {
initTypeByNameCache(rootStype);
tableRoots = identifyTablesRoots(rootStype);
LinkedHashSet<SType<?>> tableRootsSTypes = tableRoots.stream().flatMap(d -> d.getRootSTypes().stream()).collect(LinkedHashSet::new, LinkedHashSet::add, LinkedHashSet::addAll);
for (DocTable docTable : tableRoots) {
LinkedHashSet<DocBlock> docBlocks = identifyBlocks(docTable.getRootSTypes(), tableRootsSTypes);
docTable.addAllDocBlocks(docBlocks);
LinkedHashSet<SType<?>> allTypesAssociatedToBlocks = gatherAllSTypesAssociatedToBlocks(docBlocks);
allTypesAssociatedToBlocks.addAll(tableRootsSTypes);
for (DocBlock docBlock : docBlocks) {
LinkedHashSet<DocFieldMetadata> docFieldMetadata = identifyFields(rootStype, docBlock, CollectionUtils.subtract(allTypesAssociatedToBlocks, docBlock.getBlockTypes()));
docBlock.addAllFieldsMetadata(docFieldMetadata);
}
}
}
代码示例来源:origin: ontopia/ontopia
public void setSubjectLocators(TopicIF object, Topic pojo) {
if (pojo.getSubjectLocators() != null) {
Collection<LocatorIF> toRemove = CollectionUtils.subtract(object.getSubjectLocators(), pojo.getSubjectLocators());
for (LocatorIF sl : pojo.getSubjectLocators()) {
object.addSubjectLocator(sl);
}
for (LocatorIF sl : toRemove) {
object.removeSubjectLocator(sl);
}
}
}
代码示例来源:origin: ontopia/ontopia
public void setItemIdentifiers(TMObjectIF object, TMObject pojo) {
if (pojo.getItemIdentifiers() != null) {
Collection<LocatorIF> toRemove = CollectionUtils.subtract(object.getItemIdentifiers(), pojo.getItemIdentifiers());
for (LocatorIF ii : pojo.getItemIdentifiers()) {
object.addItemIdentifier(ii);
}
for (LocatorIF ii : toRemove) {
object.removeItemIdentifier(ii);
}
}
}
代码示例来源:origin: ontopia/ontopia
public void setSubjectIdentifiers(TopicIF object, Topic pojo) {
if (pojo.getSubjectIdentifiers() != null) {
Collection<LocatorIF> toRemove = CollectionUtils.subtract(object.getSubjectIdentifiers(), pojo.getSubjectIdentifiers());
for (LocatorIF si : pojo.getSubjectIdentifiers()) {
object.addSubjectIdentifier(si);
}
for (LocatorIF si : toRemove) {
object.removeSubjectIdentifier(si);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!