List of usage examples for java.util Set forEach
default void forEach(Consumer<? super T> action)
From source file:org.onosproject.openstacknetworkingui.OpenstackNetworkingUiMessageHandler.java
private List<OpenstackLink> linksInSameNetwork(HostId hostId) { OpenstackLinkMap linkMap = new OpenstackLinkMap(); Streams.stream(hostService.getHosts()).filter(host -> isHostInSameNetwork(host, networkId(hostId))) .forEach(host -> {//from ww w . ja v a 2 s.c o m linkMap.add(createEdgeLink(host, true)); linkMap.add(createEdgeLink(host, false)); Set<Path> paths = pathService.getPaths(hostId, host.id()); if (!paths.isEmpty()) { paths.forEach(path -> path.links().forEach(linkMap::add)); } }); List<OpenstackLink> openstackLinks = Lists.newArrayList(); linkMap.biLinks().forEach(openstackLinks::add); return openstackLinks; }
From source file:com.adobe.acs.commons.mcp.impl.processes.asset.UrlAssetImport.java
protected Set<FileOrRendition> extractFilesAndFolders(List<Map<String, CompositeVariant>> fileData) { Set<FileOrRendition> allFiles = fileData.stream().peek(this::extractFolder).map(this::extractFile) .filter(t -> t != null).collect(Collectors.toSet()); // Remove renditions from the data set and file them with their original renditions Set<FileOrRendition> renditions = allFiles.stream().filter(FileOrRendition::isRendition) .collect(Collectors.toSet()); allFiles.removeAll(renditions);/*from w w w . jav a2 s.c o m*/ renditions.forEach(r -> { Optional<FileOrRendition> asset = findOriginalRendition(allFiles, r); if (asset.isPresent()) { asset.get().addRendition(r); } else { unmatchedRenditions.add(r.getProperties()); } }); return allFiles; }
From source file:se.uu.it.cs.recsys.ruleminer.datastructure.builder.FPTreeHeaderTableBuilder.java
/** * * @param minSupport//from w w w . j a va 2 s . c o m * @return non-null list; the list is empty if the min support requirement * is not met */ public List<HeaderTableItem> buildHeaderTableFromDB(int minSupport) { Map<Integer, Integer> courseIdAndCount = new HashMap<>(); int studentId = 1; final int maxStudentID = this.courseSelectionNormalizedRepository .findMaxCourseSelectionNormalizedPKStudentId(); // LOGGER.debug("Max studentId: {}", maxStudentID); while (studentId <= maxStudentID) { Set<Integer> allAttendedCourseIDs = this.courseSelectionNormalizedRepository .findCourseSelectionNormalizedPKNormalizedCourseIdByCourseSelectionNormalizedPKStudentId( studentId); // LOGGER.debug("Normalized attended coursed ids: {}, studentId: {}", allAttendedCourseIDs, studentId); allAttendedCourseIDs.forEach((courseId) -> { if (courseIdAndCount.containsKey(courseId)) { Integer existingAmount = courseIdAndCount.get(courseId); courseIdAndCount.put(courseId, existingAmount + 1); } else { courseIdAndCount.put(courseId, 1); } }); studentId++; } return build(courseIdAndCount, minSupport); }
From source file:org.niord.core.schedule.FiringExerciseService.java
/** * Formats the subject//from w ww . ja v a 2 s . com * @param detailsPart the message part to update * @param languages the languages to include */ private void formatSubject(MessagePart detailsPart, Set<String> languages) { DictionaryEntry titleEntry = dictionaryService.findByName("message").getEntries() .get("msg.firing_exercises.subject"); languages.forEach(lang -> { String subject = (titleEntry != null && titleEntry.getDesc(lang) != null) ? titleEntry.getDesc(lang).getValue() : "Firing exercises. Warning."; detailsPart.checkCreateDesc(lang).setSubject(subject); }); }
From source file:dk.dma.msiproxy.common.provider.AbstractProviderService.java
/** * May be called periodically to clean up the message repo folder associated * with the provider./*from ww w .ja v a 2s. co m*/ * <p> * The procedure will determine which repository message ID's are still active. * and delete folders associated with messages ID's that are not active anymore. */ public void cleanUpMessageRepoFolder() { long t0 = System.currentTimeMillis(); // Compute the ID's for message repository folders to keep Set<Integer> ids = computeReferencedMessageIds(messages); // Build a lookup map of all the paths that ara still active Set<Path> paths = new HashSet<>(); ids.forEach(id -> { try { Path path = getMessageRepoFolder(id); // Add the path and the hashed sub-folders above it paths.add(path); paths.add(path.getParent()); paths.add(path.getParent().getParent()); } catch (IOException e) { log.error("Failed computing " + getProviderId() + " message repo paths for id " + id + ": " + e.getMessage()); } }); // Scan all sub-folders and delete those Path messageRepoRoot = getRepositoryService().getRepoRoot().resolve(MESSAGE_REPO_ROOT_FOLDER) .resolve(getProviderId()); paths.add(messageRepoRoot); try { Files.walkFileTree(messageRepoRoot, new SimpleFileVisitor<Path>() { @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { if (!paths.contains(dir)) { log.info("Deleting message repo directory :" + dir); Files.delete(dir); } return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (!paths.contains(file.getParent())) { log.info("Deleting message repo file :" + file); Files.delete(file); } return FileVisitResult.CONTINUE; } }); } catch (IOException e) { log.error("Failed cleaning up " + getProviderId() + " message repo: " + e.getMessage()); } log.info(String.format("Cleaned up %s message repo in %d ms", getProviderId(), System.currentTimeMillis() - t0)); }
From source file:de.tudarmstadt.ukp.dkpro.core.io.lif.internal.Lif2DKPro.java
public void convert(Container aContainer, JCas aJCas) { aJCas.setDocumentLanguage(aContainer.getLanguage()); aJCas.setDocumentText(aContainer.getText()); View view = aContainer.getView(0); // Paragraph/* w w w .ja v a 2 s. com*/ view.getAnnotations().stream().filter(a -> Discriminators.Uri.PARAGRAPH.equals(a.getAtType())) .forEach(para -> { Paragraph paraAnno = new Paragraph(aJCas, para.getStart().intValue(), para.getEnd().intValue()); paraAnno.addToIndexes(); }); // Sentence view.getAnnotations().stream().filter(a -> Discriminators.Uri.SENTENCE.equals(a.getAtType())) .forEach(sent -> { Sentence sentAnno = new Sentence(aJCas, sent.getStart().intValue(), sent.getEnd().intValue()); sentAnno.addToIndexes(); }); Map<String, Token> tokenIdx = new HashMap<>(); // Token, POS, Lemma view.getAnnotations().stream().filter(a -> Discriminators.Uri.TOKEN.equals(a.getAtType())) .forEach(token -> { Token tokenAnno = new Token(aJCas, token.getStart().intValue(), token.getEnd().intValue()); String pos = token.getFeature(Features.Token.POS); String lemma = token.getFeature(Features.Token.LEMMA); if (isNotEmpty(pos)) { POS posAnno = new POS(aJCas, tokenAnno.getBegin(), tokenAnno.getEnd()); posAnno.setPosValue(pos.intern()); posAnno.setCoarseValue(posAnno.getClass().equals(POS.class) ? null : posAnno.getType().getShortName().intern()); posAnno.addToIndexes(); tokenAnno.setPos(posAnno); } if (isNotEmpty(lemma)) { Lemma lemmaAnno = new Lemma(aJCas, tokenAnno.getBegin(), tokenAnno.getEnd()); lemmaAnno.setValue(lemma); lemmaAnno.addToIndexes(); tokenAnno.setLemma(lemmaAnno); } tokenAnno.addToIndexes(); tokenIdx.put(token.getId(), tokenAnno); }); // NamedEntity view.getAnnotations().stream().filter(a -> Discriminators.Uri.NE.equals(a.getAtType())).forEach(ne -> { NamedEntity neAnno = new NamedEntity(aJCas, ne.getStart().intValue(), ne.getEnd().intValue()); neAnno.setValue(ne.getLabel()); neAnno.addToIndexes(); }); // Dependencies view.getAnnotations().stream().filter(a -> Discriminators.Uri.DEPENDENCY.equals(a.getAtType())) .forEach(dep -> { String dependent = dep.getFeature(Features.Dependency.DEPENDENT); String governor = dep.getFeature(Features.Dependency.GOVERNOR); if (isEmpty(governor) || governor.equals(dependent)) { ROOT depAnno = new ROOT(aJCas); depAnno.setDependencyType(dep.getLabel()); depAnno.setDependent(tokenIdx.get(dependent)); depAnno.setGovernor(tokenIdx.get(dependent)); depAnno.setBegin(depAnno.getDependent().getBegin()); depAnno.setEnd(depAnno.getDependent().getEnd()); depAnno.addToIndexes(); } else { Dependency depAnno = new Dependency(aJCas); depAnno.setDependencyType(dep.getLabel()); depAnno.setDependent(tokenIdx.get(dependent)); depAnno.setGovernor(tokenIdx.get(governor)); depAnno.setBegin(depAnno.getDependent().getBegin()); depAnno.setEnd(depAnno.getDependent().getEnd()); depAnno.addToIndexes(); } }); // Constituents view.getAnnotations().stream().filter(a -> Discriminators.Uri.PHRASE_STRUCTURE.equals(a.getAtType())) .forEach(ps -> { String rootId = findRoot(view, ps); // Get the constituent IDs Set<String> constituentIDs; constituentIDs = new HashSet<>(getSetFeature(ps, Features.PhraseStructure.CONSTITUENTS)); List<Annotation> constituents = new ArrayList<>(); Map<String, Constituent> constituentIdx = new HashMap<>(); // Instantiate all the constituents view.getAnnotations().stream().filter(a -> constituentIDs.contains(a.getId())).forEach(con -> { if (Discriminators.Uri.CONSTITUENT.equals(con.getAtType())) { Constituent conAnno; if (rootId.equals(con.getId())) { conAnno = new de.tudarmstadt.ukp.dkpro.core.api.syntax.type.constituent.ROOT(aJCas); } else { conAnno = new Constituent(aJCas); } if (con.getStart() != null) { conAnno.setBegin(con.getStart().intValue()); } if (con.getEnd() != null) { conAnno.setEnd(con.getEnd().intValue()); } conAnno.setConstituentType(con.getLabel()); constituentIdx.put(con.getId(), conAnno); constituents.add(con); } // If it is not a constituent, it must be a token ID - we already // have created the tokens and recorded them in the tokenIdx }); // Set parent and children features constituents.forEach(con -> { // Check if it is a constituent or token Constituent conAnno = constituentIdx.get(con.getId()); Set<String> childIDs = getSetFeature(con, Features.Constituent.CHILDREN); List<org.apache.uima.jcas.tcas.Annotation> children = new ArrayList<>(); childIDs.forEach(childID -> { Constituent conChild = constituentIdx.get(childID); Token tokenChild = tokenIdx.get(childID); if (conChild != null && tokenChild == null) { conChild.setParent(conAnno); children.add(conChild); } else if (conChild == null && tokenChild != null) { tokenChild.setParent(conAnno); children.add(tokenChild); } else if (conChild == null && tokenChild == null) { throw new IllegalStateException("ID [" + con.getId() + "] not found"); } else { throw new IllegalStateException( "ID [" + con.getId() + "] is constituent AND token? Impossible!"); } }); conAnno.setChildren(FSCollectionFactory.createFSArray(aJCas, children)); }); // Percolate offsets - they might not have been set on the constituents! Constituent root = constituentIdx.get(rootId); percolateOffsets(root); // Add to indexes constituentIdx.values().forEach(conAnno -> { conAnno.addToIndexes(); }); }); }
From source file:dk.dma.ais.abnormal.analyzer.analysis.CloseEncounterAnalysisTest.java
@Test public void closeEncounterEventContainsTwoVesselBehaviours() throws Exception { analysis.clearTrackPairsAnalyzed();/*ww w . j a va 2 s . c om*/ final ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class); context.checking(new Expectations() { { ignoring(statisticsService).incAnalysisStatistics( with(CloseEncounterAnalysis.class.getSimpleName()), with(any(String.class))); ignoring(statisticsService).setAnalysisStatistics( with(CloseEncounterAnalysis.class.getSimpleName()), with(any(String.class)), with(any(Long.class))); oneOf(eventRepository).findOngoingEventByVessel(track.getMmsi(), CloseEncounterEvent.class); oneOf(eventRepository).save(with(eventCaptor.getMatcher())); } }); analysis.analyseCloseEncounter(track, closeTrack); Event event = eventCaptor.getCapturedObject(); Set<Behaviour> behaviours = event.getBehaviours(); assertEquals(2, behaviours.size()); assertEquals(1, behaviours.stream().filter(t -> t.getVessel().getMmsi() == track.getMmsi()).count()); assertEquals(1, behaviours.stream().filter(t -> t.getVessel().getMmsi() == closeTrack.getMmsi()).count()); behaviours.forEach(b -> { if (b.getVessel().getMmsi() == track.getMmsi()) { assertEquals(1, b.getTrackingPoints().size()); // No. of previous tracking points in event } else if (b.getVessel().getMmsi() == closeTrack.getMmsi()) { assertEquals(5, b.getTrackingPoints().size()); // No. of previous tracking points in event } }); }
From source file:org.jboss.pnc.coordinator.test.event.StatusUpdatesTest.java
@Test @InSequence(30)//w ww .j ava 2 s .c o m public void BuildTaskCallbacksShouldBeCalled() throws DatastoreException, CoreException { User user = User.Builder.newBuilder().id(3).username("test-user-3").build(); Set<BuildTask> buildTasks = initializeBuildTaskSet(configurationBuilder, user, (buildConfigSetRecord) -> { }).getBuildTasks(); Set<Integer> tasksIds = buildTasks.stream().map((BuildTask::getId)).collect(Collectors.toSet()); Set<Integer> receivedUpdatesForId = new HashSet<>(); Consumer<BuildCoordinationStatusChangedEvent> statusChangeEventConsumer = (statusChangedEvent) -> { receivedUpdatesForId.add(statusChangedEvent.getBuild().getId()); }; tasksIds.forEach((id) -> { buildStatusNotifications.subscribe(new BuildCallBack(id, statusChangeEventConsumer)); }); buildTasks.forEach((bt) -> { buildCoordinator.updateBuildTaskStatus(bt, BuildCoordinationStatus.DONE); }); tasksIds.forEach((id) -> { Assert.assertTrue("Did not receive update for task " + id, receivedUpdatesForId.contains(id)); }); }
From source file:org.obiba.agate.web.rest.notification.NotificationsResource.java
/** * Send an email by processing a template with request form parameters and the recipient * {@link org.obiba.agate.domain.User} as a context. The Template is expected to be located in a folder having * the application name./*from w w w. j av a 2s .c o m*/ * * @param subject * @param templateName * @param context * @param recipients */ private void sendTemplateEmail(String subject, String templateName, Map<String, String[]> context, Set<User> recipients) { org.thymeleaf.context.Context ctx = new org.thymeleaf.context.Context(); context.forEach((k, v) -> { if (v != null && v.length == 1) { ctx.setVariable(k, v[0]); } else { ctx.setVariable(k, v); } }); String templateLocation = getApplicationName() + "/" + templateName; recipients.forEach(rec -> { ctx.setVariable("user", rec); ctx.setLocale(LocaleUtils.toLocale(rec.getPreferredLanguage())); mailService.sendEmail(rec.getEmail(), subject, templateEngine.process(templateLocation, ctx)); }); }