List of usage examples for java.util Set remove
boolean remove(Object o);
From source file:com.connexta.arbitro.ctx.xacml2.XACML2EvaluationCtx.java
/** * Changes the value of the resource-id attribute in this context. This is useful when you have * multiple resources (ie, a scope other than IMMEDIATE), and you need to keep changing only the * resource-id to evaluate the different effective requests. * * @param attributesSet The attributes to be added to the ResourceId * @param resourceId the new resource-id value */// w w w .j a v a 2s . c o m public void setResourceId(AttributeValue resourceId, Set<Attributes> attributesSet) { this.resourceId = resourceId; // there will always be exactly one value for this attribute Set attrSet = (Set) (resourceMap.get(XACMLConstants.RESOURCE_ID)); Attribute attr = (Attribute) (attrSet.iterator().next()); // remove the old value... attrSet.remove(attr); // ...and insert the new value attrSet.add(new Attribute(attr.getId(), attr.getIssuer(), attr.getIssueInstant(), resourceId, XACMLConstants.XACML_VERSION_2_0)); }
From source file:mitm.djigzo.web.pages.admin.mta.MTAConfig.java
private Object removeDestination() throws WebServiceCheckedException { if (selectedDestination != null) { Set<String> destinations = new LinkedHashSet<String>(getMainConfig().getMyDestinations()); destinations.remove(selectedDestination); getMainConfig().setMyDestination(destinations); }// w w w.jav a 2 s .c o m return request.isXHR() ? myDestinationBlock : getKeepConfigReloadLink(); }
From source file:gemlite.core.internal.view.GemliteViewContext.java
/** * remove view//w w w.j av a 2 s . co m * * @param viewName */ @SuppressWarnings("rawtypes") public boolean removeViewItem(String viewName) { ViewItem viewItem = viewContext.get(viewName); if (viewItem == null) { LogUtil.getCoreLog().error("Drop view failed, this view can not be founded in view context."); return false; } if (TriggerOn.REGION.equals(viewItem.getTriggerOn())) { String regionName = viewItem.getRegionName(); Set<String> viewSet = regionToView.get(regionName); if (viewSet != null) { viewSet.remove(viewName); } } if (TriggerOn.INDEX.equals(viewItem.getTriggerOn())) { IIndexContext context = this.getIndexContextByIndexName(viewItem.getIndexName()); IndexTool tool = (IndexTool) context.getIndexInstance(); tool.removeViewItem(viewItem.getName()); } // remove viewItem from viewContext viewContext.remove(viewItem.getName()); try { removeMbean(viewItem); Region region = cache.getRegion(viewItem.getName()); if (region != null) region.destroyRegion(); } catch (Exception e) { LogUtil.getCoreLog().error("drop view " + viewName + " failed.", e); e.printStackTrace(); return false; } if (LogUtil.getCoreLog().isInfoEnabled()) { LogUtil.getCoreLog().info("drop view " + viewName + " successfully."); } return true; }
From source file:it.geosolutions.geostore.services.rest.impl.RESTUserServiceImpl.java
/** * Utility method to remove Reserved group (for example EVERYONE) from a group list * // w w w.ja va2s .com * @param groups * @return */ private Set<UserGroup> removeReservedGroups(Set<UserGroup> groups) { List<UserGroup> reserved = new ArrayList<UserGroup>(); for (UserGroup ug : groups) { if (!GroupReservedNames.isAllowedName(ug.getGroupName())) { reserved.add(ug); } } for (UserGroup ug : reserved) { groups.remove(ug); } return groups; }
From source file:org.openmrs.web.controller.report.RunReportController.java
public void validate(Object commandObject, Errors errors) { CommandObject command = (CommandObject) commandObject; ValidationUtils.rejectIfEmpty(errors, "schema", "Missing reportId, or report not found"); if (command.getSchema() != null) { ReportSchema rs = command.getSchema(); Set<String> requiredParams = new HashSet<String>(); if (rs.getReportParameters() != null) { for (Parameter p : rs.getReportParameters()) { if (p.isRequired()) requiredParams.add(p.getName()); }/* ww w. j a v a2s . c om*/ } for (Map.Entry<String, String> e : command.getUserEnteredParams().entrySet()) { if (StringUtils.hasText(e.getValue())) requiredParams.remove(e.getKey()); } if (requiredParams.size() > 0) { errors.rejectValue("userEnteredParams", "Enter all parameter values"); } if (rs.getDataSetDefinitions() == null || rs.getDataSetDefinitions().size() == 0) errors.rejectValue("schema", "ReportSchema must declare some data set definitions"); } ValidationUtils.rejectIfEmpty(errors, "selectedRenderer", "Pick a renderer"); }
From source file:com.bstek.dorado.data.type.manager.DefaultDataTypeManager.java
/** * ??DataType???DataType/*from w w w . jav a 2 s.c o m*/ */ private void filterMatchingDataTypes(Set<DataTypeWrapper> dtws) { DataTypeWrapper[] dtwArray = new DataTypeWrapper[dtws.size()]; dtws.toArray(dtwArray); for (DataTypeWrapper dtw1 : dtwArray) { Iterator<DataTypeWrapper> iter = dtws.iterator(); while (iter.hasNext()) { DataTypeWrapper dtw2 = iter.next(); if (dtw1 != dtw2) { if (dtw1.getType().isAssignableFrom(dtw2.getType())) { dtws.remove(dtw1); break; } if (isChildTypeOf(dtw2.getDataType(), dtw1.getDataType())) { dtws.remove(dtw1); break; } } } } }
From source file:org.openmrs.module.auditlog.AuditLogBehaviorTest.java
@Test public void shouldUpdateTheAuditedClassCacheWhenTheAuditedClassGlobalPropertyIsUpdatedWithARemoval() throws Exception { assertTrue(auditLogService.isAudited(Concept.class)); assertTrue(auditLogService.isAudited(ConceptNumeric.class)); assertTrue(auditLogService.isAudited(ConceptComplex.class)); Set<Class<?>> auditedClasses = new HashSet<Class<?>>(); auditedClasses.addAll(helper.getExceptions()); auditedClasses.remove(Concept.class); String exceptions = StringUtils.join(AuditLogUtil.getAsListOfClassnames(auditedClasses), SEPARATOR); AuditLogUtil.setGlobalProperty(ExceptionBasedAuditStrategy.GLOBAL_PROPERTY_EXCEPTION, exceptions); assertFalse(auditLogService.isAudited(Concept.class)); assertTrue(auditLogService.isAudited(ConceptNumeric.class)); assertTrue(auditLogService.isAudited(ConceptComplex.class)); }
From source file:com.puppycrawl.tools.checkstyle.internal.XdocsPagesTest.java
private static void validateStyleModules(Set<Node> checks, Set<Node> configs, Set<String> styleChecks, String fileName, String ruleName) { final Iterator<Node> itrChecks = checks.iterator(); final Iterator<Node> itrConfigs = configs.iterator(); while (itrChecks.hasNext()) { final Node module = itrChecks.next(); final String moduleName = module.getTextContent().trim(); if (!module.getAttributes().getNamedItem("href").getTextContent().startsWith("config_")) { continue; }/*from www.j a v a2s . c o m*/ Assert.assertTrue( fileName + " rule '" + ruleName + "' module '" + moduleName + "' shouldn't end with 'Check'", !moduleName.endsWith("Check")); styleChecks.remove(moduleName); for (String configName : new String[] { "config", "test" }) { Node config = null; try { config = itrConfigs.next(); } catch (NoSuchElementException ignore) { Assert.fail(fileName + " rule '" + ruleName + "' module '" + moduleName + "' is missing the config link: " + configName); } Assert.assertEquals(fileName + " rule '" + ruleName + "' module '" + moduleName + "' has mismatched config/test links", configName, config.getTextContent().trim()); final String configUrl = config.getAttributes().getNamedItem("href").getTextContent(); if ("config".equals(configName)) { final String expectedUrl = "https://github.com/search?q=" + "path%3Asrc%2Fmain%2Fresources+filename%3Agoogle_checks.xml+" + "repo%3Acheckstyle%2Fcheckstyle+" + moduleName; Assert.assertEquals(fileName + " rule '" + ruleName + "' module '" + moduleName + "' should have matching " + configName + " url", expectedUrl, configUrl); } else if ("test".equals(configName)) { Assert.assertTrue( fileName + " rule '" + ruleName + "' module '" + moduleName + "' should have matching " + configName + " url", configUrl.startsWith("https://github.com/checkstyle/checkstyle/" + "blob/master/src/it/java/com/google/checkstyle/test/")); Assert.assertTrue(fileName + " rule '" + ruleName + "' module '" + moduleName + "' should have matching " + configName + " url", configUrl.endsWith("/" + moduleName + "Test.java")); Assert.assertTrue( fileName + " rule '" + ruleName + "' module '" + moduleName + "' should have a test that exists", new File(configUrl.substring(53).replace('/', File.separatorChar)).exists()); } } } Assert.assertFalse(fileName + " rule '" + ruleName + "' has too many configs", itrConfigs.hasNext()); }
From source file:io.seldon.trust.impl.jdo.RecommendationPeer.java
public SortResult sort(Long userId, List<Long> items, CFAlgorithm options, List<Long> recentActions) { ClientPersistable cp = new ClientPersistable(options.getName()); if (debugging) logger.debug("Calling sort for user " + userId); if (items != null && items.size() > 0) { if (debugging) logger.debug("Trying sort for user " + userId); Map<Long, Integer> results = new HashMap<>(); List<CF_SORTER> successfulMethods = new ArrayList<>(); int successfulPrevAlg = 0; for (CF_SORTER sortMethod : options.getSorters()) { if (debugging) logger.debug("Trying " + sortMethod.name()); List<Long> res = null; switch (sortMethod) { case NOOP: res = items;//from ww w . ja va2s .com break; case SEMANTIC_VECTORS: { if (debugging) logger.debug("Getting semantic vectors peer for client [" + options.getName() + "]"); SemVectorsPeer sem = SemanticVectorsStore.get(options.getName(), SemanticVectorsStore.PREFIX_FIND_SIMILAR); if (debugging) logger.debug("Getting recent actions for user " + userId + " SV History size:" + options.getTxHistorySizeForSV() + " with min " + options.getMinNumTxsForSV()); //FIXME - needs to ignore FacebookLikes etc.. needs this done in generic way if (recentActions.size() >= options.getMinNumTxsForSV()) { //Limiting the list size List<Long> limitedRecentActions; if (recentActions.size() > options.getTxHistorySizeForSV()) { limitedRecentActions = recentActions.subList(0, options.getTxHistorySizeForSV()); } else { limitedRecentActions = recentActions; } if (debugging) logger.debug("Calling semantic vectors to sort"); res = sem.sortDocsUsingDocQuery(limitedRecentActions, items, new DocumentIdTransform()); if (debugging) { if (res != null && res.size() > 0) logger.debug("Got result of size " + res.size()); else logger.debug("Got no results from semantic vectors"); } } else if (debugging) logger.debug("Not enough tx for user " + userId + " they had " + recentActions.size() + " min is " + options.getMinNumTxsForSV()); } break; case CLUSTER_COUNTS: case CLUSTER_COUNTS_DYNAMIC: { JdoCountRecommenderUtils cUtils = new JdoCountRecommenderUtils(options.getName()); CountRecommender r = cUtils.getCountRecommender(options.getName()); if (r != null) { boolean includeShortTermClusters = sortMethod == CF_SORTER.CLUSTER_COUNTS_DYNAMIC; long t1 = System.currentTimeMillis(); res = r.sort(userId, items, null, includeShortTermClusters, options.getLongTermWeight(), options.getShortTermWeight()); // group hardwired to null long t2 = System.currentTimeMillis(); if (debugging) logger.debug("Sorting for user " + userId + " took " + (t2 - t1)); } } break; case DEMOGRAPHICS: res = null; break; } boolean success = res != null && res.size() > 0; if (success) { successfulMethods.add(sortMethod); if (debugging) logger.debug("Successful sort for user " + userId + " for sort " + sortMethod.name()); switch (options.getSorterStrategy()) { case FIRST_SUCCESSFUL: case RANK_SUM: case WEIGHTED: // presently does same as RANK_SUM { // add results to Map int pos = 0; // update the counts for articles not seen in this algorithm set int currentResultsSize = results.size(); Set<Long> missedItems = new HashSet<>(results.keySet()); for (Long itemId : res) { missedItems.remove(itemId); pos++; Integer count = results.get(itemId); int countNew; if (count != null) countNew = count + pos; else countNew = pos + (currentResultsSize * successfulPrevAlg); results.put(itemId, countNew); } for (Long item : missedItems) results.put(item, results.get(item) + res.size()); successfulPrevAlg++; } break; case ADD_MISSING: { if (debugging) logger.debug("Adding missing items returned " + sortMethod.name() + " to global list: " + CollectionTools.join(res, ",")); successfulPrevAlg++; Set<Long> currentItems = new HashSet<>(results.keySet()); int pos = currentItems.size(); for (Long itemId : res) { if (!currentItems.contains(itemId)) { pos++; results.put(itemId, pos); } } } break; } } else if (debugging) logger.debug("unsuccessful sort for user " + userId + " for sort " + sortMethod.name()); if (success && options.getSorterStrategy() == CFAlgorithm.CF_STRATEGY.FIRST_SUCCESSFUL) break; else { // just continue } } List<Long> res = CollectionTools.sortMapAndLimitToList(results, results.size(), false); if (res == null) res = new ArrayList<>(); return new SortResult(res, successfulMethods, options.getSorterStrategy()); } else { logger.warn("No items to sort for user " + userId); return new SortResult(new ArrayList<Long>(), new ArrayList<CF_SORTER>(), options.getSorterStrategy()); } }