List of usage examples for java.util Set remove
boolean remove(Object o);
From source file:org.callimachusproject.repository.CalliRepository.java
private void addEach(Trace[] traces, Set<Trace> set) { set.addAll(Arrays.asList(traces)); for (Trace call : traces) { Trace parent = call;//www. java 2s. c om while ((parent = parent.getPreviousTrace()) != null) { set.remove(parent); } } }
From source file:com.facebook.buck.jvm.java.JarDirectoryStepTest.java
@Test public void jarsShouldContainDirectoryEntries() throws IOException { Path zipup = folder.newFolder("dir-zip"); Path subdir = zipup.resolve("dir/subdir"); Files.createDirectories(subdir); Files.write(subdir.resolve("a.txt"), "cake".getBytes()); JarDirectoryStep step = new JarDirectoryStep(new ProjectFilesystem(zipup), Paths.get("output.jar"), ImmutableSortedSet.of(zipup), /* main class */ null, /* manifest file */ null); ExecutionContext context = TestExecutionContext.newInstance(); int returnCode = step.execute(context).getExitCode(); assertEquals(0, returnCode);/*from ww w. j a v a 2s . com*/ Path zip = zipup.resolve("output.jar"); assertTrue(Files.exists(zip)); // Iterate over each of the entries, expecting to see the directory names as entries. Set<String> expected = Sets.newHashSet("dir/", "dir/subdir/"); try (ZipInputStream is = new ZipInputStream(Files.newInputStream(zip))) { for (ZipEntry entry = is.getNextEntry(); entry != null; entry = is.getNextEntry()) { expected.remove(entry.getName()); } } assertTrue("Didn't see entries for: " + expected, expected.isEmpty()); }
From source file:cz.zcu.kiv.eegdatabase.logic.controller.article.ArticleMultiController.java
@RequestMapping(value = "articles/subscribe", method = RequestMethod.GET) public ModelAndView subscribe(HttpServletRequest request, HttpServletResponse response) { ModelAndView mav = new ModelAndView("articles/subscribe"); setPermissionsToView(mav);/*from w w w.j a v a 2 s.c o m*/ Person loggedUser = personDao.getLoggedPerson(); int id = 0; try { id = Integer.parseInt(request.getParameter("articleId")); } catch (NumberFormatException e) { log.debug("Unable to determine article id"); } Article article = (Article) articleDao.read(id); Boolean subscribe = Boolean.parseBoolean(request.getParameter("subscribe")); Set<Person> subscribers = article.getSubscribers(); if (subscribe) { subscribers.add(loggedUser); } else { subscribers.remove(loggedUser); } article.setSubscribers(subscribers); articleDao.update(article); mav = new ModelAndView("redirect:/articles/detail.html?articleId=" + id); return mav; }
From source file:com.pinterest.deployservice.handler.EnvironHandler.java
public void updateGroups(EnvironBean envBean, List<String> groups, String operator) throws Exception { // TODO need to check group env conflicts and reject if so List<String> oldGroupList = groupDAO.getCapacityGroups(envBean.getEnv_id()); Set<String> oldGroups = new HashSet<>(); oldGroups.addAll(oldGroupList);/* w w w .j a v a2 s .c om*/ for (String group : groups) { if (!oldGroups.contains(group)) { groupDAO.addGroupCapacity(envBean.getEnv_id(), group); } else { oldGroups.remove(group); } } for (String group : oldGroups) { groupDAO.removeGroupCapacity(envBean.getEnv_id(), group); } }
From source file:org.openmrs.module.metadatasharing.ConceptMirrorTest.java
@Test public void shouldCorrectlyOverwriteConceptAnswersInMirrorMode() throws Exception { final String conceptUuid = UUID.randomUUID().toString(); final String answer1ConceptUuid = UUID.randomUUID().toString(); final String answer2ConceptUuid = UUID.randomUUID().toString(); runShareTest(new ShareTestHelper() { @Override/* w w w.jav a2 s . com*/ public List<?> prepareExportServer() throws Exception { Concept concept = newConcept(7); concept.setUuid(conceptUuid); Concept concept1 = newConcept(1); concept1.setUuid(answer1ConceptUuid); ConceptAnswer conceptAnswer1 = newConceptAnswer(1); conceptAnswer1.setAnswerConcept(concept1); concept.addAnswer(conceptAnswer1); Concept concept2 = newConcept(2); concept2.setUuid(answer2ConceptUuid); ConceptAnswer conceptAnswer2 = newConceptAnswer(2); conceptAnswer2.setAnswerConcept(concept2); concept.addAnswer(conceptAnswer2); Context.getConceptService().saveConcept(concept); return Arrays.asList(concept); } /** * @see org.openmrs.module.metadatasharing.ShareTestHelper#prepareImportServer() */ @Override public void prepareImportServer() throws Exception { Concept concept = newConcept(7); concept.setUuid(conceptUuid); Concept concept1 = newConcept(1); concept1.setUuid(answer1ConceptUuid); ConceptAnswer conceptAnswer1 = newConceptAnswer(1); conceptAnswer1.setAnswerConcept(concept1); concept.addAnswer(conceptAnswer1); Concept concept2 = newConcept(2); concept2.setUuid(answer2ConceptUuid); ConceptAnswer conceptAnswer2 = newConceptAnswer(2); conceptAnswer2.setAnswerConcept(concept2); concept.addAnswer(conceptAnswer2); Context.getConceptService().saveConcept(concept); } /** * @see org.openmrs.module.metadatasharing.ShareTestHelper#runOnImportServerBeforeImport(org.openmrs.module.metadatasharing.wrapper.PackageImporter) */ @Override public void runOnImportServerBeforeImport(PackageImporter importer) throws Exception { importer.setImportConfig(ImportConfig.valueOf(ImportMode.MIRROR)); } @Override public void runOnImportServerAfterImport() throws Exception { Concept concept = Context.getConceptService().getConceptByUuid(conceptUuid); Collection<ConceptAnswer> answers = concept.getAnswers(); Assert.assertEquals(2, answers.size()); Set<String> expectedAnswers = new HashSet<String>(); expectedAnswers.addAll(Arrays.asList(answer1ConceptUuid, answer2ConceptUuid)); for (ConceptAnswer answer : answers) { assertTrue(answer.getAnswerConcept().getUuid() + " missing", expectedAnswers.remove(answer.getAnswerConcept().getUuid())); } } }); }
From source file:cz.zcu.kiv.eegdatabase.logic.controller.article.ArticleMultiController.java
public ModelAndView subscribeGroupArticles(HttpServletRequest request, HttpServletResponse response) { ModelAndView mav = new ModelAndView("articles/subscribeGroupArticles"); setPermissionsToView(mav);//from www . j a v a 2s. c o m Person loggedUser = personDao.getLoggedPerson(); int id = 0; try { id = Integer.parseInt(request.getParameter("groupId")); } catch (NumberFormatException e) { log.debug("Unable to determine research group id"); } ResearchGroup group = (ResearchGroup) researchGroupDao.read(id); Boolean subscribe = Boolean.parseBoolean(request.getParameter("subscribe")); Set<Person> subscribers = group.getArticlesSubscribers(); if (subscribe) { subscribers.add(loggedUser); } else { subscribers.remove(loggedUser); } group.setArticlesSubscribers(subscribers); researchGroupDao.update(group); mav = new ModelAndView("redirect:/articles/settings.html"); return mav; }
From source file:com.zimbra.cs.mime.MimeTest.java
@Test public void multipartReportRfc822Headers() throws Exception { String content = baseNdrContent + boundary + "\r\n" + "Content-Description: Notification\r\n" + "Content-Type: text/plain;charset=us-ascii\r\n\r\n" + "<mta@example.com>: host mta.example.com[255.255.255.0] said: 554 delivery error: This user doesn't have an example.com account (in reply to end of DATA command)\r\n\r\n" + boundary + "\r\n" + "Content-Description: Delivery report\r\n" + "Content-Type: message/delivery-status\r\n\r\n" + "X-Postfix-Queue-ID: 12345\r\n" + "X-Postfix-Sender: rfc822; test123@example.com\r\n" + "Arrival-Date: Wed, 8 Aug 2012 00:05:30 +0900 (JST)\r\n\r\n" + boundary + "\r\n" + "Content-Description: Undelivered Message Headers\r\n" + "Content-Type: text/rfc822-headers\r\n" + "Content-Transfer-Encoding: 7bit\r\n\r\n" + "From: admin@example\r\n" + "To: test15@example.com\r\n" + "Message-ID: <123456@client.example.com>\r\n" + "Subject: test msg"; MimeMessage mm = new Mime.FixedMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(content.getBytes())); List<MPartInfo> parts = Mime.getParts(mm); Assert.assertNotNull(parts);//from www.ja va 2 s . c om Assert.assertEquals(4, parts.size()); MPartInfo mpart = parts.get(0); Assert.assertEquals("multipart/report", mpart.getContentType()); List<MPartInfo> children = mpart.getChildren(); Assert.assertEquals(3, children.size()); Set<String> types = Sets.newHashSet("text/plain", "message/delivery-status", "text/rfc822-headers"); for (MPartInfo child : children) { Assert.assertTrue("Expected: " + child.getContentType(), types.remove(child.getContentType())); } Set<MPartInfo> bodies = Mime.getBody(parts, false); Assert.assertEquals(2, bodies.size()); types = Sets.newHashSet("text/plain", "text/rfc822-headers"); for (MPartInfo body : bodies) { Assert.assertTrue("Expected: " + body.getContentType(), types.remove(body.getContentType())); } }
From source file:edu.wisc.my.portlets.bookmarks.domain.Folder.java
/** * @see java.lang.Object#hashCode()/*from w w w .java 2 s . c o m*/ */ public int hashCode() { final Set<Integer> visited = hashCodeVisitedFolder.getSet(); final int identityHash = System.identityHashCode(this); try { if (!visited.add(identityHash)) { visited.clear(); throw new IllegalStateException("A loop exists in the Folder tree."); } return new HashCodeBuilder(-409984457, 961354191).appendSuper(super.hashCode()).append(this.children) .append(this.minimized).toHashCode(); } finally { visited.remove(identityHash); } }
From source file:com.yahoo.gondola.container.ZookeeperRegistryClient.java
private String registerHostIdOnZookeeper(String siteId, InetSocketAddress serverAddress) throws Exception { Set<String> eligibleHostIds = getAllHostsAtSite(siteId); for (String key : client.getChildren().forPath(GONDOLA_HOSTS)) { Entry entry = objectMapper.readValue(client.getData().forPath(GONDOLA_HOSTS + "/" + key), Entry.class); if (entry == null) { continue; }// w w w . j a v a 2 s.c om if (entry.gondolaAddress.equals(serverAddress)) { return entry.hostId; } if (config.getSiteIdForHost(entry.hostId).equals(siteId)) { eligibleHostIds.remove(entry.hostId); } } for (String hostId : eligibleHostIds) { Entry entry = new Entry(); entry.hostId = hostId; entry.gondolaAddress = serverAddress; try { client.create().withMode(CreateMode.EPHEMERAL).forPath(GONDOLA_HOSTS + "/" + entry.hostId, objectMapper.writeValueAsBytes(entry)); entries.put(entry.hostId, entry); myHostIds.add(entry.hostId); return entry.hostId; } catch (KeeperException.NodeExistsException ignored) { logger.info("Failed to register for host ID {}", hostId); } } throw new IOException("Unable to register hostId, all hosts are full on site " + siteId); }
From source file:annis.visualizers.component.grid.EventExtractor.java
/** * Returns the annotations to display according to the mappings configuration. * * This will check the "annos" and "annos_regex" paramters for determining. * the annotations to display. It also iterates over all nodes of the graph * matching the type.//w ww .j a v a 2 s. c o m * * @param input The input for the visualizer. * @param type Which type of nodes to include * @return */ public static List<String> computeDisplayAnnotations(VisualizerInput input, Class<? extends SNode> type) { if (input == null) { return new LinkedList<String>(); } SDocumentGraph graph = input.getDocument().getSDocumentGraph(); Set<String> annoPool = getAnnotationLevelSet(graph, input.getNamespace(), type); List<String> annos = new LinkedList<String>(annoPool); String annosConfiguration = input.getMappings().getProperty(MAPPING_ANNOS_KEY); if (annosConfiguration != null && annosConfiguration.trim().length() > 0) { String[] split = annosConfiguration.split(","); annos.clear(); for (String s : split) { s = s.trim(); // is regular expression? if (s.startsWith("/") && s.endsWith("/")) { // go over all remaining items in our pool of all annotations and // check if they match Pattern regex = Pattern.compile(StringUtils.strip(s, "/")); LinkedList<String> matchingAnnos = new LinkedList<String>(); for (String a : annoPool) { if (regex.matcher(a).matches()) { matchingAnnos.add(a); } } annos.addAll(matchingAnnos); annoPool.removeAll(matchingAnnos); } else { annos.add(s); annoPool.remove(s); } } } // filter already found annotation names by regular expression // if this was given as mapping String regexFilterRaw = input.getMappings().getProperty(MAPPING_ANNO_REGEX_KEY); if (regexFilterRaw != null) { try { Pattern regexFilter = Pattern.compile(regexFilterRaw); ListIterator<String> itAnnos = annos.listIterator(); while (itAnnos.hasNext()) { String a = itAnnos.next(); // remove entry if not matching if (!regexFilter.matcher(a).matches()) { itAnnos.remove(); } } } catch (PatternSyntaxException ex) { log.warn("invalid regular expression in mapping for grid visualizer", ex); } } return annos; }