List of usage examples for java.util Collection stream
default Stream<E> stream()
From source file:org.psidnell.omnifocus.model.DataCache.java
public void exportData(File file, Predicate<NodeImpl> filterFn) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, SQLException, JsonGenerationException, JsonMappingException, IOException { try (Writer out = new FileWriter(file)) { Collection<Folder> folders = rawData.getFolders().stream().filter(filterFn) .collect(Collectors.toList()); Collection<Task> tasks = rawData.getTasks().stream().filter(filterFn).collect(Collectors.toList()); Collection<Context> contexts = rawData.getContexts().stream().filter(filterFn) .collect(Collectors.toList()); // ProjInfos don't have a name, have to use their associated root task names Set<String> taskIds = tasks.stream().map((t) -> t.getId()).collect(Collectors.toSet()); Collection<ProjectInfo> projInfos = rawData.getProjects().stream() .filter((pi) -> taskIds.contains(pi.getRootTaskId())).collect(Collectors.toList()); RawData filteredData = new RawData(); filteredData.setProjects(new LinkedList<>(projInfos)); filteredData.setContexts(new LinkedList<>(contexts)); filteredData.setTasks(new LinkedList<>(tasks)); filteredData.setFolders(new LinkedList<>(folders)); RawData.exportRawData(filteredData, file); }/*from w w w . ja v a 2 s . c om*/ }
From source file:com.hortonworks.streamline.streams.service.ClusterCatalogResource.java
private void assertNoNamespaceRefersCluster(Long clusterId) { Collection<Namespace> namespaces = environmentService.listNamespaces(); if (namespaces != null) { for (Namespace namespace : namespaces) { Collection<NamespaceServiceClusterMapping> mappings = environmentService .listServiceClusterMapping(namespace.getId()); if (mappings != null) { boolean matched = mappings.stream().anyMatch(m -> Objects.equals(m.getClusterId(), clusterId)); if (matched) { throw BadRequestException.message( "Namespace refers the cluster trying to remove - cluster id: " + clusterId); }// w ww . ja v a2 s.c o m } } } }
From source file:org.ligoj.app.plugin.security.fortify.FortifyPluginResourceTest.java
@Test public void findProjectVersions() throws Exception { prepareMockProjectVersions();/*from w ww . jav a2 s. co m*/ final Collection<FortifyProject> versions = resource.findProjectVersions("service:security:fortify:dig", "2", StringUtils.EMPTY); Assertions.assertEquals(1, versions.size()); Assertions.assertEquals(4, versions.stream().findFirst().get().getId().intValue()); Assertions.assertEquals("1.0", versions.stream().findFirst().get().getName()); }
From source file:com.github.drbookings.ui.controller.StatsViewController.java
private void updateUI(final Collection<? extends BookingEntry> bookings) { data.clear();/*from w w w . j ava 2s . c om*/ if (bookings == null || bookings.isEmpty()) { return; } final BookingsByOrigin<BookingEntry> bo = new BookingsByOrigin<>(bookings); updateUI(bo, LocalDates.getDateRange(bookings.stream().map(e -> e.getDate()).collect(Collectors.toList()))); // updateTotals(); }
From source file:com.hortonworks.streamline.streams.service.NamespaceCatalogResource.java
private Response buildNamespacesGetResponse(Collection<Namespace> namespaces, Boolean detail) { if (BooleanUtils.isTrue(detail)) { List<CatalogResourceUtil.NamespaceWithMapping> namespacesWithMapping = namespaces.stream() .map(namespace -> CatalogResourceUtil.enrichNamespace(namespace, environmentService)) .collect(toList());/*from w w w . ja v a 2s .c om*/ return WSUtils.respondEntities(namespacesWithMapping, OK); } else { return WSUtils.respondEntities(namespaces, OK); } }
From source file:com.github.drbookings.model.data.manager.MainManager.java
public synchronized boolean needsCleaning(final String roomName, final LocalDate date) { final Collection<BookingEntry> bookings = bookingEntries.get(date); final Stream<BookingEntry> sbe = bookings.stream().filter(be -> be.getRoom().getName().equals(roomName)); final Stream<BookingBean> sb = sbe.map(be -> be.getElement()); return sb.anyMatch(b -> b.getCleaning() == null); }
From source file:com.github.drbookings.ui.controller.BookingDetailsController.java
private void update(final Collection<? extends RoomBean> rooms) { clearAll();/* w w w.ja v a 2 s . c o m*/ final List<BookingBean> bookings = new ArrayList<>( rooms.stream().flatMap(r -> r.getFilteredBookingEntries().stream().map(b -> b.getElement())) .collect(Collectors.toSet())); Collections.sort(bookings); for (final Iterator<BookingBean> it = bookings.iterator(); it.hasNext();) { final BookingBean be = it.next(); addBookingEntry(be); if (it.hasNext()) { addSeparator(); } } }
From source file:dk.dma.ais.abnormal.analyzer.analysis.FreeFlowAnalysis.java
private void analyseFreeFlow(Collection<Track> tracks) { LOG.debug("Performing analysis of " + tracks.size() + " tracks"); final long t0 = nanoTime(); tracks.stream().forEach(t -> analyseFreeFlow(tracks, t)); final long t1 = nanoTime(); LOG.debug("Analysis performed in " + (t1 - t0) / 1000 + " msecs"); }
From source file:ddf.catalog.impl.operations.CreateOperations.java
private boolean blockCreateMetacards(Collection<Metacard> metacards, List<String> fanoutBlacklist) { return metacards.stream().anyMatch((metacard) -> isMetacardBlacklisted(metacard, fanoutBlacklist)); }
From source file:com.hortonworks.streamline.streams.service.NamespaceCatalogResource.java
@DELETE @Path("/namespaces/{id}/mapping") @Timed/*from ww w . ja v a 2 s . com*/ public Response unmapAllServicesToClusterInNamespace(@PathParam("id") Long namespaceId, @Context SecurityContext securityContext) { SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_ENVIRONMENT_SUPER_ADMIN, Namespace.NAMESPACE, namespaceId, WRITE); Namespace namespace = environmentService.getNamespace(namespaceId); if (namespace == null) { throw EntityNotFoundException.byId(namespaceId.toString()); } String streamingEngine = namespace.getStreamingEngine(); Collection<NamespaceServiceClusterMapping> mappings = environmentService .listServiceClusterMapping(namespaceId); boolean containsStreamingEngine = mappings.stream() .anyMatch(m -> m.getServiceName().equals(streamingEngine)); if (containsStreamingEngine) { assertNoTopologyReferringNamespaceIsRunning(namespaceId, WSUtils.getUserFromSecurityContext(securityContext)); } List<NamespaceServiceClusterMapping> removed = mappings.stream().map((x) -> environmentService .removeServiceClusterMapping(x.getNamespaceId(), x.getServiceName(), x.getClusterId())) .collect(toList()); return WSUtils.respondEntities(removed, OK); }