List of usage examples for java.util Collection remove
boolean remove(Object o);
From source file:org.jboss.as.test.integration.logging.handlers.SocketHandlerTestCase.java
private void checkLevelsLogged(final JsonLogServer server, final Set<Logger.Level> expectedLevels, final String msg) throws IOException, InterruptedException { executeRequest(msg, Collections.singletonMap("includeLevel", "true")); final List<JsonObject> foundMessages = new ArrayList<>(); for (int i = 0; i < expectedLevels.size(); i++) { final JsonObject foundMessage = server.getLogMessage(DFT_TIMEOUT); if (foundMessage == null) { final String failureMessage = "A log messages was not received within " + DFT_TIMEOUT + " milliseconds." + System.lineSeparator() + "Found the following messages: " + foundMessages + System.lineSeparator() + "Expected the following levels to be logged: " + expectedLevels;/*from w ww .ja va 2s. c om*/ Assert.fail(failureMessage); } foundMessages.add(foundMessage); } Assert.assertEquals(expectedLevels.size(), foundMessages.size()); // Check that we have all the expected levels final Collection<String> levels = expectedLevels.stream().map(Enum::name).collect(Collectors.toList()); final Iterator<JsonObject> iter = foundMessages.iterator(); while (iter.hasNext()) { final JsonObject foundMessage = iter.next(); final String foundLevel = foundMessage.getString("level"); Assert.assertNotNull("Expected a level on " + foundMessage, foundLevel); Assert.assertTrue(String.format("Level %s was logged, but not expected.", foundLevel), levels.remove(foundLevel)); iter.remove(); } // The string levels should be empty, if not we're missing an expected level Assert.assertTrue("Found levels that did not appear to be logged: " + levels, levels.isEmpty()); }
From source file:eu.trentorise.smartcampus.permissionprovider.controller.PermissionController.java
/** * Save permissions requested by the app. * @param permissions/*from w ww .j ava 2 s .c om*/ * @param clientId * @param serviceId * @return {@link Response} entity containing the processed app {@link Permissions} descriptor */ @RequestMapping(value = "/dev/permissions/{clientId}/{serviceId:.*}", method = RequestMethod.PUT) public @ResponseBody Response savePermissions(@RequestBody Permissions permissions, @PathVariable String clientId, @PathVariable String serviceId) { Response response = new Response(); response.setResponseCode(RESPONSE.OK); try { // check that the client is owned by the current user checkClientIdOwnership(clientId); ClientDetailsEntity clientDetails = clientDetailsRepository.findByClientId(clientId); ClientAppInfo info = ClientAppInfo.convert(clientDetails.getAdditionalInformation()); if (info.getResourceApprovals() == null) info.setResourceApprovals(new HashMap<String, Boolean>()); Collection<String> resourceIds = new HashSet<String>(clientDetails.getResourceIds()); Collection<String> scopes = new HashSet<String>(clientDetails.getScope()); for (String r : permissions.getSelectedResources().keySet()) { Resource resource = resourceRepository.findOne(Long.parseLong(r)); // if not checked, remove from permissions and from pending requests if (!permissions.getSelectedResources().get(r)) { info.getResourceApprovals().remove(r); resourceIds.remove(r); scopes.remove(resource.getResourceUri()); // if checked but requires approval, check whether // - is the resource of the same client, so add automatically // - already approved (i.e., included in client resourceIds) // - already requested (i.e., included in additional info approval requests map) } else if (!clientId.equals(resource.getClientId()) && resource.isApprovalRequired()) { if (!resourceIds.contains(r) && !info.getResourceApprovals().containsKey(r)) { info.getResourceApprovals().put(r, true); } // if approval is not required, include directly in client resource ids } else { resourceIds.add(r); scopes.add(resource.getResourceUri()); } } clientDetails.setResourceIds(StringUtils.collectionToCommaDelimitedString(resourceIds)); clientDetails.setScope(StringUtils.collectionToCommaDelimitedString(scopes)); clientDetails.setAdditionalInformation(info.toJson()); clientDetailsRepository.save(clientDetails); response.setData(buildPermissions(clientDetails, serviceId)); } catch (Exception e) { logger.error("Failure saving permissions model: " + e.getMessage(), e); response.setErrorMessage(e.getMessage()); response.setResponseCode(RESPONSE.ERROR); } return response; }
From source file:org.training.storefront.breadcrumb.impl.SearchBreadcrumbBuilder.java
public List<Breadcrumb> getBreadcrumbs(final String categoryCode, final String searchText, final boolean emptyBreadcrumbs) throws IllegalArgumentException { final List<Breadcrumb> breadcrumbs = new ArrayList<>(); if (categoryCode == null) { final Breadcrumb breadcrumb = new Breadcrumb("/search?text=" + getEncodedUrl(searchText), StringEscapeUtils.escapeHtml(searchText), (emptyBreadcrumbs ? LAST_LINK_CLASS : "")); breadcrumbs.add(breadcrumb);//from w w w . j a va2 s .co m } else { // Create category hierarchy path for breadcrumb final List<Breadcrumb> categoryBreadcrumbs = new ArrayList<>(); final Collection<CategoryModel> categoryModels = new ArrayList<>(); final CategoryModel lastCategoryModel = getCommerceCategoryService().getCategoryForCode(categoryCode); categoryModels.addAll(lastCategoryModel.getSupercategories()); categoryBreadcrumbs .add(getCategoryBreadcrumb(lastCategoryModel, (!emptyBreadcrumbs ? LAST_LINK_CLASS : ""))); while (!categoryModels.isEmpty()) { final CategoryModel categoryModel = categoryModels.iterator().next(); if (!(categoryModel instanceof ClassificationClassModel)) { if (categoryModel != null) { categoryBreadcrumbs.add(getCategoryBreadcrumb(categoryModel)); categoryModels.clear(); categoryModels.addAll(categoryModel.getSupercategories()); } } else { categoryModels.remove(categoryModel); } } Collections.reverse(categoryBreadcrumbs); breadcrumbs.addAll(categoryBreadcrumbs); } return breadcrumbs; }
From source file:it.smartcommunitylab.aac.controller.PermissionController.java
/** * Save permissions requested by the app. * @param permissions/*from w ww . j av a 2 s . c om*/ * @param clientId * @param serviceId * @return {@link Response} entity containing the processed app {@link Permissions} descriptor * @throws Exception */ @RequestMapping(value = "/dev/permissions/{clientId}/{serviceId:.*}", method = RequestMethod.PUT) public @ResponseBody Response savePermissions(@RequestBody Permissions permissions, @PathVariable String clientId, @PathVariable String serviceId) throws Exception { Response response = new Response(); // check that the client is owned by the current user userManager.checkClientIdOwnership(clientId); ClientDetailsEntity clientDetails = clientDetailsRepository.findByClientId(clientId); ClientAppInfo info = ClientAppInfo.convert(clientDetails.getAdditionalInformation()); if (info.getResourceApprovals() == null) info.setResourceApprovals(new HashMap<String, Boolean>()); Collection<String> resourceIds = new HashSet<String>(clientDetails.getResourceIds()); Collection<String> scopes = new HashSet<String>(clientDetails.getScope()); for (String r : permissions.getSelectedResources().keySet()) { Resource resource = resourceRepository.findOne(Long.parseLong(r)); // if not checked, remove from permissions and from pending requests if (!permissions.getSelectedResources().get(r)) { info.getResourceApprovals().remove(r); resourceIds.remove(r); scopes.remove(resource.getResourceUri()); // if checked but requires approval, check whether // - is the resource of the same client, so add automatically // - already approved (i.e., included in client resourceIds) // - already requested (i.e., included in additional info approval requests map) } else if (!clientId.equals(resource.getClientId()) && resource.isApprovalRequired()) { if (!resourceIds.contains(r) && !info.getResourceApprovals().containsKey(r)) { info.getResourceApprovals().put(r, true); } // if approval is not required, include directly in client resource ids } else { resourceIds.add(r); scopes.add(resource.getResourceUri()); } } clientDetails.setResourceIds(StringUtils.collectionToCommaDelimitedString(resourceIds)); clientDetails.setScope(StringUtils.collectionToCommaDelimitedString(scopes)); clientDetails.setAdditionalInformation(info.toJson()); clientDetailsRepository.save(clientDetails); response.setData(buildPermissions(clientDetails, serviceId)); return response; }
From source file:com.atlassian.clover.ant.taskdefs.CloverCompilerAdapter.java
private TestDetector calcTestDetector(Set<File> compileSet, Collection<File> copySet, Collection<File> instrSet) { final AntInstrumentationConfig config = AntInstrumentationConfig.getFrom(project); if (config != null && config.getTestSources() != null) { final FileMappedTestDetector fileMappedTestDetector = new FileMappedTestDetector(); final List<TestSourceSet> testSourcesList = config.getTestSources(); for (final TestSourceSet testSourceSet : testSourcesList) { final Set<File> included = testSourceSet.getIncludedFiles(); for (final File inc : included) { if (compileSet.contains(inc)) { instrSet.add(inc);/* www. ja va 2 s . c o m*/ copySet.remove(inc); } } final Set<File> excluded = testSourceSet.getExcludedFiles(); for (final File exc : excluded) { if (compileSet.contains(exc)) { instrSet.remove(exc); copySet.add(exc); } } fileMappedTestDetector.addTestSourceMatcher(testSourceSet); } return fileMappedTestDetector; } return null; }
From source file:org.opencms.workplace.commons.CmsAvailability.java
/** * Builds a String with HTML code to display the responsibles of a resource.<p> * /*from w w w. j ava2 s . c om*/ * @return HTML code for the responsibles of the current resource */ public String buildResponsibleList() { if (isMultiOperation()) { // show no responsibles list for multi operation return ""; } else { // single resource operation, create list of responsibles StringBuffer result = new StringBuffer(512); result.append("<tr><td colspan=\"3\">"); List parentResources = new ArrayList(); Map responsibles = new HashMap(); CmsObject cms = getCms(); String resourceSitePath = cms.getRequestContext().removeSiteRoot(getParamResource()); try { // get all parent folders of the current file parentResources = cms.readPath(getParamResource(), CmsResourceFilter.IGNORE_EXPIRATION); } catch (CmsException e) { // can usually be ignored if (LOG.isInfoEnabled()) { LOG.info(e.getLocalizedMessage()); } } Iterator i = parentResources.iterator(); while (i.hasNext()) { CmsResource resource = (CmsResource) i.next(); try { String sitePath = cms.getRequestContext().removeSiteRoot(resource.getRootPath()); Iterator entries = cms.getAccessControlEntries(sitePath, false).iterator(); while (entries.hasNext()) { CmsAccessControlEntry ace = (CmsAccessControlEntry) entries.next(); if (ace.isResponsible()) { I_CmsPrincipal principal = cms.lookupPrincipal(ace.getPrincipal()); if (principal != null) { responsibles.put(principal, resourceSitePath.equals(sitePath) ? null : sitePath); } } } } catch (CmsException e) { // can usually be ignored if (LOG.isInfoEnabled()) { LOG.info(e.getLocalizedMessage()); } } } if (responsibles.size() == 0) { // no responsibles found result.append(key(Messages.GUI_AVAILABILITY_NO_RESPONSIBLES_0)); } else { // found responsibles, create list result.append( dialogToggleStart(key(Messages.GUI_AVAILABILITY_RESPONSIBLES_0), "responsibles", false)); Collection parentFolders = new ArrayList(responsibles.values()); parentFolders.remove(null); if (parentFolders.size() > 0) { result.append("<table border=\"0\">\n<tr>\n\t<td>"); result.append(key(Messages.GUI_PERMISSION_SELECT_VIEW_0)); result.append("</td>\n<td><input type=\"button\" onclick=\"toggleInheritInfo();\" value=\""); result.append(key(Messages.GUI_LABEL_DETAILS_0)); result.append("\" id=\"button\"/></td></tr></table>"); } result.append(dialogWhiteBoxStart()); Iterator it = responsibles.entrySet().iterator(); for (int j = 0; it.hasNext(); j++) { Map.Entry entry = (Map.Entry) it.next(); I_CmsPrincipal principal = (I_CmsPrincipal) entry.getKey(); String image = "user.png"; String localizedType = getLocalizedType(CmsAccessControlEntry.ACCESS_FLAGS_USER); if (principal instanceof CmsGroup) { image = "group.png"; localizedType = getLocalizedType(CmsAccessControlEntry.ACCESS_FLAGS_GROUP); } result.append("<div class=\"dialogrow\"><img src=\""); result.append(getSkinUri()); result.append("commons/"); result.append(image); result.append("\" class=\"noborder\" width=\"16\" height=\"16\" alt=\""); result.append(localizedType); result.append("\" title=\""); result.append(localizedType); result.append("\"> <span class=\"textbold\">"); result.append(principal.getName()); result.append("</span><div class=\"hide\" id=\"inheritinfo"); result.append(j); result.append("\"><div class=\"dialogpermissioninherit\">"); String resourceName = (String) entry.getValue(); if (CmsStringUtil.isNotEmpty(resourceName)) { result.append(key(Messages.GUI_PERMISSION_INHERITED_FROM_1, new Object[] { resourceName })); } result.append("</div></div></div>\n"); } result.append(dialogWhiteBoxEnd()); result.append("</div>\n"); result.append("</td></tr>"); } return result.toString(); } }
From source file:com.ecyrd.jspwiki.ReferenceManager.java
/** * Clears the references to a certain page so it's no longer in the map. * * @param pagename Name of the page to clear references for. *//* w w w .ja v a 2s . c o m*/ public synchronized void clearPageEntries(String pagename) { pagename = getFinalPageName(pagename); // // Remove this item from the referredBy list of any page // which this item refers to. // Collection<String> c = m_refersTo.get(pagename); if (c != null) { for (String key : c) { Collection<?> dref = m_referredBy.get(key); dref.remove(pagename); } } // // Finally, remove direct references. // m_referredBy.remove(pagename); m_refersTo.remove(pagename); }
From source file:com.exxonmobile.ace.hybris.storefront.breadcrumb.impl.SearchBreadcrumbBuilder.java
public List<Breadcrumb> getBreadcrumbs(final String categoryCode, final String searchText, final boolean emptyBreadcrumbs) throws IllegalArgumentException { final List<Breadcrumb> breadcrumbs = new ArrayList<Breadcrumb>(); if (categoryCode == null) { final Breadcrumb breadcrumb = new Breadcrumb("/search?text=" + getEncodedUrl(searchText), StringEscapeUtils.escapeHtml(searchText), (emptyBreadcrumbs ? LAST_LINK_CLASS : "")); breadcrumbs.add(breadcrumb);//from ww w . ja v a2 s .c o m } else { // Create category hierarchy path for breadcrumb final List<Breadcrumb> categoryBreadcrumbs = new ArrayList<Breadcrumb>(); final Collection<CategoryModel> categoryModels = new ArrayList<CategoryModel>(); final CategoryModel lastCategoryModel = getCommerceCategoryService().getCategoryForCode(categoryCode); categoryModels.addAll(lastCategoryModel.getSupercategories()); categoryBreadcrumbs .add(getCategoryBreadcrumb(lastCategoryModel, (!emptyBreadcrumbs ? LAST_LINK_CLASS : ""))); while (!categoryModels.isEmpty()) { final CategoryModel categoryModel = categoryModels.iterator().next(); if (!(categoryModel instanceof ClassificationClassModel)) { if (categoryModel != null) { categoryBreadcrumbs.add(getCategoryBreadcrumb(categoryModel)); categoryModels.clear(); categoryModels.addAll(categoryModel.getSupercategories()); } } else { categoryModels.remove(categoryModel); } } Collections.reverse(categoryBreadcrumbs); breadcrumbs.addAll(categoryBreadcrumbs); } return breadcrumbs; }
From source file:com.pedra.storefront.breadcrumb.impl.SearchBreadcrumbBuilder.java
public List<Breadcrumb> getBreadcrumbs(final String categoryCode, final String searchText, final boolean emptyBreadcrumbs) throws IllegalArgumentException { final List<Breadcrumb> breadcrumbs = new ArrayList<Breadcrumb>(); if (categoryCode == null) { final Breadcrumb breadcrumb = new Breadcrumb("/search?text=" + getEncodedUrl(searchText), StringEscapeUtils.escapeHtml(searchText), (emptyBreadcrumbs ? LAST_LINK_CLASS : "")); breadcrumbs.add(breadcrumb);/*from w ww .jav a 2s . c om*/ } else { // Create category hierarchy path for breadcrumb final List<Breadcrumb> categoryBreadcrumbs = new ArrayList<Breadcrumb>(); final Collection<CategoryModel> categoryModels = new ArrayList<CategoryModel>(); final CategoryModel lastCategoryModel = getCommerceCategoryService().getCategoryForCode(categoryCode); categoryModels.addAll(lastCategoryModel.getSupercategories()); categoryBreadcrumbs .add(getCategoryBreadcrumb(lastCategoryModel, (!emptyBreadcrumbs ? LAST_LINK_CLASS : ""))); while (!categoryModels.isEmpty()) { final CategoryModel categoryModel = categoryModels.iterator().next(); if (!(categoryModel instanceof ClassificationClassModel)) { if (categoryModel != null) { categoryBreadcrumbs.add(getCategoryBreadcrumb(categoryModel)); categoryModels.clear(); categoryModels.addAll(categoryModel.getSupercategories()); } } else { categoryModels.remove(categoryModel); } } Collections.reverse(categoryBreadcrumbs); breadcrumbs.addAll(categoryBreadcrumbs); } return breadcrumbs; }
From source file:com.jkoolcloud.tnt4j.streams.configure.sax.ConfigParserHandlerTest.java
protected void validateConfigs(File samplesDir, String configFileWildcard, boolean checkStreams, List<String> skipFiles) throws Exception { Collection<File> sampleConfigurations = FileUtils.listFiles(samplesDir, FileFilterUtils.asFileFilter( (FilenameFilter) new WildcardFileFilter(configFileWildcard, IOCase.INSENSITIVE)), TrueFileFilter.INSTANCE);/*from w w w . j av a2 s .co m*/ Collection<File> sampleConfigurationsFiltered = new ArrayList<>(sampleConfigurations); if (CollectionUtils.isNotEmpty(skipFiles)) { for (File sampleConfiguration : sampleConfigurations) { for (String skipFile : skipFiles) { if (sampleConfiguration.getAbsolutePath().contains(skipFile)) sampleConfigurationsFiltered.remove(sampleConfiguration); } } } for (File sampleConfiguration : sampleConfigurationsFiltered) { System.out.println("Reading configuration file: " + sampleConfiguration.getAbsolutePath()); // NON-NLS Reader testReader = new FileReader(sampleConfiguration); SAXParserFactory parserFactory = SAXParserFactory.newInstance(); SAXParser parser = parserFactory.newSAXParser(); ConfigParserHandler hndlr = new ConfigParserHandler(); parser.parse(new InputSource(testReader), hndlr); assertNotNull("Parsed streams config data is null", hndlr.getStreamsConfigData()); boolean parseable = true; if (checkStreams) { assertTrue("No configured streams", hndlr.getStreamsConfigData().isStreamsAvailable()); parseable = false; for (TNTInputStream<?, ?> s : hndlr.getStreamsConfigData().getStreams()) { if (s instanceof TNTParseableInputStream) { parseable = true; break; } } } if (parseable) { assertTrue("No configured parsers", hndlr.getStreamsConfigData().isParsersAvailable()); } Utils.close(testReader); } }