List of usage examples for java.util Set removeAll
boolean removeAll(Collection<?> c);
From source file:de.berlios.gpon.common.util.AbstractMappedItem.java
/** Copies values from other into this object. New properties are added, orphan entries will be removed. * @param other the AbstractMappedItem to sync with *//*from w w w .j a va 2s . com*/ public void syncWith(AbstractMappedItem other) { Map myMap = getMap(); Map otherMap = other.getMap(); // nothing to do if (otherMap == null && myMap == null) { return; } Set myKeys = null; Set otherKeys = null; if (myMap != null) { myKeys = myMap.keySet(); } if (otherMap != null) { otherKeys = otherMap.keySet(); } if (myKeys != null) { // orphan = my.keys - other.keys Set orphan = new HashSet(); orphan.addAll(myKeys); if (otherKeys != null) { orphan.removeAll(otherKeys); } if (!orphan.isEmpty()) { Iterator it = orphan.iterator(); while (it.hasNext()) { Object key = it.next(); log.info("Removing attribute " + key); this.removeValue(key.toString()); } } } if (otherKeys != null) { Iterator it = otherKeys.iterator(); while (it.hasNext()) { Object key = it.next(); log.info("Setting value for " + key + " to " + other.getValueInNormalForm(key.toString())); this.setValue(key.toString(), other.getValueInNormalForm(key.toString()), NORMAL_FORM); } } }
From source file:com.trailmagic.image.security.SpringSecurityImageSecurityService.java
public void effectPermissions(MutableAcl acl, Sid recipient, Set<Permission> newPermissions, boolean additive) { Set<Permission> existingPermissions = findExistingPermissions(acl, recipient); if (!additive) { Set<Permission> permsToRemove = new HashSet<Permission>(); permsToRemove.addAll(existingPermissions); permsToRemove.removeAll(newPermissions); for (Permission perm : permsToRemove) { acl.deleteAce(indexOf(recipient, perm, acl)); if (log.isDebugEnabled()) { log.debug("Removed ACE for permission " + perm + ", recipient " + recipient + ", on object " + acl.getObjectIdentity()); }/* w ww. j a v a 2 s.co m*/ } } Set<Permission> permsToAdd = new HashSet<Permission>(); permsToAdd.addAll(newPermissions); permsToAdd.removeAll(existingPermissions); for (Permission perm : permsToAdd) { acl.insertAce(acl.getEntries().size(), perm, recipient, true); if (log.isDebugEnabled()) { log.debug("Added ACE for permission " + perm + ", recipient " + recipient + ", on object " + acl.getObjectIdentity()); } } aclService.updateAcl(acl); }
From source file:com.github.fge.jsonschema.keyword.validator.common.DependenciesValidator.java
@Override public void validate(final Processor<FullData, FullData> processor, final ProcessingReport report, final MessageBundle bundle, final FullData data) throws ProcessingException { final JsonNode instance = data.getInstance().getNode(); final Set<String> fields = Sets.newHashSet(instance.fieldNames()); Collection<String> collection; Set<String> set; for (final String field : propertyDeps.keySet()) { if (!fields.contains(field)) continue; collection = propertyDeps.get(field); set = Sets.newLinkedHashSet(collection); set.removeAll(fields); if (!set.isEmpty()) report.error(newMsg(data, bundle, "err.common.dependencies.missingPropertyDeps") .putArgument("property", field).putArgument("required", toArrayNode(collection)) .putArgument("missing", toArrayNode(set))); }/*from ww w . ja v a 2 s . co m*/ if (schemaDeps.isEmpty()) return; final SchemaTree tree = data.getSchema(); FullData newData; JsonPointer pointer; for (final String field : schemaDeps) { if (!fields.contains(field)) continue; pointer = JsonPointer.of(keyword, field); newData = data.withSchema(tree.append(pointer)); processor.process(report, newData); } }
From source file:gov.nih.nci.caintegrator.application.query.FoldChangeCriterionHandler.java
private Collection<ArrayData> getCandidateArrayDatas(Study study, Set<ArrayData> controlArrayData, ReporterTypeEnum reporterType, Platform platform) { Set<ArrayData> candidateDatas = new HashSet<ArrayData>(); candidateDatas.addAll(study.getArrayDatas(reporterType, platform)); candidateDatas.removeAll(controlArrayData); return candidateDatas; }
From source file:eu.esdihumboldt.util.resource.scavenger.AbstractResourceScavenger.java
/** * @see ResourceScavenger#triggerScan()/*from ww w. j a va2s. co m*/ */ @Override public void triggerScan() { synchronized (resources) { if (huntingGrounds != null) { if (huntingGrounds.isDirectory()) { // scan for sub-directories Set<String> foundIds = new HashSet<String>(); File[] resourceDirs = huntingGrounds.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { // accept non-hidden directories return pathname.isDirectory() && !pathname.isHidden(); } }); for (File resourceDir : resourceDirs) { String resourceId = resourceDir.getName(); foundIds.add(resourceId); if (!resources.containsKey(resourceId)) { // resource reference not loaded yet T handler; try { handler = loadReference(resourceDir, null, resourceId); resources.put(resourceId, handler); } catch (IOException e) { log.error("Error creating resource reference", e); } } else { // update existing resource updateResource(resources.get(resourceId), resourceId); } } Set<String> removed = new HashSet<String>(resources.keySet()); removed.removeAll(foundIds); // deal with resources that have been removed for (String resourceId : removed) { T reference = resources.remove(resourceId); if (reference != null) { // remove active environment onRemove(reference, resourceId); } } } else { // one project mode if (!resources.containsKey(DEFAULT_RESOURCE_ID)) { // project configuration not loaded yet T handler; try { handler = loadReference(huntingGrounds.getParentFile(), huntingGrounds.getName(), DEFAULT_RESOURCE_ID); resources.put(DEFAULT_RESOURCE_ID, handler); } catch (IOException e) { log.error("Error creating project handler", e); } } else { // update existing project updateResource(resources.get(DEFAULT_RESOURCE_ID), DEFAULT_RESOURCE_ID); } } } } }
From source file:info.novatec.ita.check.StereotypeCheckValidator.java
private void checkDependency(DetailAST ast, ClassInfo classToCheck, StereotypeConfiguration config) { Set<StereotypeIdentifier> allowedDependencies = check.getConfig().getDependencies().get(config.getId()) .getAllowedToDependencies(); Set<StereotypeIdentifier> disallowedDependencies = new HashSet<StereotypeIdentifier>( check.getConfig().getStereotypeConfig().keySet()); if (allowedDependencies != null) { disallowedDependencies.removeAll(allowedDependencies); }//w w w .ja v a 2 s . c o m for (StereotypeIdentifier to : disallowedDependencies) { StereotypeConfiguration toConfig = check.getConfig().getStereotypeConfig().get(to); for (String importedClass : classToCheck.getImports()) { if ((check.getConfig().isInApplicationPackage(importedClass) || check.getConfig().isPartOfAnyStereotype(importedClass)) && !toConfig.isPartOfStereotype(importedClass)) { if (toConfig.getPostfixCondition() == StereotypeCondition.sufficient && importedClass.endsWith(toConfig.getPostfix())) { DetailAST importAst = classToCheck.getImportAst(importedClass); addError(importAst, "Disallowed dependency from stereotype " + config.getId() + " to stereotype " + toConfig.getId() + ": " + importedClass); } if (toConfig.getPackageNameCondition() == StereotypeCondition.sufficient && importedClass.startsWith(toConfig.getPackageName())) { DetailAST importAst = classToCheck.getImportAst(importedClass); addError(importAst, "Disallowed dependency from stereotype " + config.getId() + " to stereotype " + toConfig.getId() + ": " + importedClass); } } } } }
From source file:org.solmix.runtime.support.spring.SpringBeanProvider.java
private <T> Collection<? extends T> _doGetBeansOfType(ApplicationContext context, Class<T> type) { if (context != null) { Set<String> s = new LinkedHashSet<String>( Arrays.asList(context.getBeanNamesForType(type, false, false))); s.removeAll(passThroughs); List<T> lst = new LinkedList<T>(); for (String n : s) { lst.add(type.cast(context.getBean(n, type))); }//from w ww. jav a 2 s . c om if (context.getParent() != null) { lst.addAll(_doGetBeansOfType(context.getParent(), type)); } return lst; } return null; }
From source file:gov.ca.cwds.cals.service.dao.FacilityChildDao.java
/** Get Assigned Worker Information for children. */ public List<ChildAssignedWorker> retrieveChildAssignedWorkerList(String[] clientIds) { if (ArrayUtils.isEmpty(clientIds)) { return Collections.emptyList(); }/* ww w. j a va 2s. co m*/ List<ChildAssignedWorker> childAssignedWorkerList = prepareCaseAssignedWorkerQuery(clientIds).list(); Set<String> clientIdSet = new HashSet<>(Arrays.asList(clientIds)); Set<String> availableIdSet = new HashSet<>(); childAssignedWorkerList.stream() .forEach(childAssignedWorker -> availableIdSet.add(childAssignedWorker.getChildIdentifier())); clientIdSet.removeAll(availableIdSet); if (clientIdSet.isEmpty()) { return childAssignedWorkerList; } childAssignedWorkerList.addAll( prepareReferralAssignedWorkerQuery(clientIdSet.toArray(new String[clientIdSet.size()])).list()); return childAssignedWorkerList; }
From source file:org.fusesource.cloudmix.controller.provisioning.ProvisioningGridController.java
/** * Lets poll to see if there are any new features we can provision *///www . j a v a 2s . com public Object call() throws Exception { if (LOG.isDebugEnabled()) { LOG.debug("in call()"); } List<ProvisioningAction> answer = new ArrayList<ProvisioningAction>(); // cleaning up all features from de-activated agents for (AgentController ac : agentTrackers()) { if (ac.isDeActivated() && (ac.getFeatures() != null) && (ac.getFeatures().size() > 0)) { String agentId = ac.getDetails().getId(); for (String fid : ac.getFeatures().toArray(new String[ac.getFeatures().size()])) { removeAgentFromFeature(fid, agentId); ProvisioningHistory history = ac.getHistory(); history.addCfgUpdate(new AgentCfgUpdate(AgentCfgUpdate.PROPERTY_AGENT_FORCE_REGISTER, "true")); } } } for (ProfileController profile : profileControllers()) { String profileID = decodeURL(profile.getDetails().getId()); // the profile was modified so re-deploy everything // TODO maybe something less drastic would do, like only uninstalling the features for which the // cfg overrides were modified if (profile.hasChanged()) { LOG.info("profile '" + profile.getDetails().getId() + "' was updated: initiating redeploy..."); List<String> toRemove = new ArrayList<String>(); for (Dependency dep : profile.getDetails().getFeatures()) { if (dep.hasChanged()) { toRemove.add(dep.getFeatureId()); dep.setChanged(false); } } for (AgentController ac : agentTrackers(profileID)) { for (String featureToRemove : toRemove) { removeAgentFromFeature(featureToRemove, ac.getDetails().getId()); } } profile.setChanged(false); } List<FeatureController> deployableFeatures = profile.getDeployableFeatures(); for (FeatureController fc : deployableFeatures) { String featureId = decodeURL(fc.getId()); Collection<AgentController> agentTrackers = agentTrackers(); AgentController agent = fc.selectAgentForDeployment(profileID, agentTrackers); if (agent == null) { LOG.debug("for feature: " + featureId + " no agent selected from possible agents " + agentTrackers.size()); } else { LOG.debug("for feature: " + featureId + " found adequate agent: " + agent.getDetails()); Map<String, String> cfgOverridesProps = getFeatureConfigurationOverrides(profile, featureId); List<ProvisioningAction> list = addAgentToFeature(agent, fc.getId(), cfgOverridesProps); answer.addAll(list); } } // cleaning up redundant features from agents that still have a profile assigned // (either because we switched profile or because the profile was updated) List<String> featureIds = new ArrayList<String>(); for (Dependency featureDependency : profile.getDetails().getFeatures()) { featureIds.add(featureDependency.getFeatureId()); } for (AgentController ac : agentTrackers(profileID)) { Set<String> featuresToRemove = new HashSet<String>(ac.getFeatures()); featuresToRemove.removeAll(featureIds); for (String fid : featuresToRemove) { removeAgentFromFeature(fid, ac.getDetails().getId()); } } } // cleaning up all features from agents that that do not have a profile assigned anymore // (... or only an unpublished one...) or for (AgentController ac : agentTrackers()) { String assignedProfile = ac.getDetails().getProfile(); boolean agentProfileGone = assignedProfile == null || hasProfileGone(assignedProfile) && !assignedProfile.equals(Constants.WILDCARD_PROFILE_NAME); if (ac.getFeatures() != null && !ac.getFeatures().isEmpty()) { String agentId = ac.getDetails().getId(); String[] featuresCopy = ac.getFeatures().toArray(new String[ac.getFeatures().size()]); if (agentProfileGone) { for (String fid : featuresCopy) { removeAgentFromFeature(fid, agentId); } } else { for (String fid : featuresCopy) { FeatureController featureController = getFeatureController(fid); // if the feature controller has gone, then the feature has gone // either by being deleted itself, or due to the profile going boolean deleteFeature = true; if (featureController != null) { deleteFeature = false; FeatureDetails details = featureController.getDetails(); if (details != null && details.getOwnedByProfileId() != null && hasProfileGone(details.getOwnedByProfileId())) { deleteFeature = true; } } if (deleteFeature) { removeAgentFromFeature(fid, agentId); } } } } } return answer; }
From source file:com.soulgalore.crawler.core.impl.DefaultCrawler.java
/** * Verify that all urls in allUrls returns 200. If not, they will be removed from that set and * instead added to the nonworking list. * //from ww w . j av a 2s .co m * @param allUrls all the links that has been fetched * @param nonWorkingUrls links that are not working */ private void verifyUrls(Set<CrawlerURL> allUrls, Set<HTMLPageResponse> verifiedUrls, Set<HTMLPageResponse> nonWorkingUrls, Map<String, String> requestHeaders) { Set<CrawlerURL> urlsThatNeedsVerification = new LinkedHashSet<CrawlerURL>(allUrls); urlsThatNeedsVerification.removeAll(verifiedUrls); final Set<Callable<HTMLPageResponse>> tasks = new HashSet<Callable<HTMLPageResponse>>( urlsThatNeedsVerification.size()); for (CrawlerURL testURL : urlsThatNeedsVerification) { tasks.add(new HTMLPageResponseCallable(testURL, responseFetcher, true, requestHeaders, false)); } try { // wait for all urls to verify List<Future<HTMLPageResponse>> responses = service.invokeAll(tasks); for (Future<HTMLPageResponse> future : responses) { if (!future.isCancelled()) { HTMLPageResponse response = future.get(); if (response.getResponseCode() == HttpStatus.SC_OK && response.getResponseType().indexOf("html") > 0) { // remove, way of catching interrupted / execution e urlsThatNeedsVerification.remove(response.getPageUrl()); verifiedUrls.add(response); } else if (response.getResponseCode() == HttpStatus.SC_OK) { // it is not HTML urlsThatNeedsVerification.remove(response.getPageUrl()); } else { nonWorkingUrls.add(response); } } } } catch (InterruptedException e1) { // TODO add some logging e1.printStackTrace(); } catch (ExecutionException e) { // TODO Auto-generated catch block e.printStackTrace(); } // TODO: We can have a delta here if the exception occur }