List of usage examples for java.util Collection stream
default Stream<E> stream()
From source file:com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesManager.java
protected void doFetchDynamicAttributes(MetaClass metaClass, Collection<BaseGenericIdEntity> entities) { List<Object> ids = entities.stream().map(e -> referenceToEntitySupport.getReferenceId(e)) .collect(Collectors.toList()); Multimap<Object, CategoryAttributeValue> allAttributeValues = HashMultimap.create(); List<Object> currentIds = new ArrayList<>(); for (Object id : ids) { currentIds.add(id);/*from w w w . ja va 2 s . com*/ if (currentIds.size() >= MAX_ENTITIES_FOR_ATTRIBUTE_VALUES_BATCH) { handleAttributeValuesForIds(metaClass, currentIds, allAttributeValues); currentIds = new ArrayList<>(); } } handleAttributeValuesForIds(metaClass, currentIds, allAttributeValues); for (BaseGenericIdEntity entity : entities) { Collection<CategoryAttributeValue> entityAttributeValues = allAttributeValues .get(referenceToEntitySupport.getReferenceId(entity)); Map<String, CategoryAttributeValue> map = new HashMap<>(); entity.setDynamicAttributes(map); if (CollectionUtils.isNotEmpty(entityAttributeValues)) { for (CategoryAttributeValue categoryAttributeValue : entityAttributeValues) { CategoryAttribute attribute = categoryAttributeValue.getCategoryAttribute(); if (attribute != null) { map.put(attribute.getCode(), categoryAttributeValue); } } } } }
From source file:com.github.drbookings.model.data.manager.MainManager.java
public boolean hasCheckIn(final LocalDate date, final String roomName) { final Collection<BookingEntry> be = bookingEntries.get(date); return be.stream().anyMatch(b -> b.isCheckIn() && b.getRoom().getName().equals(roomName)); }
From source file:com.hortonworks.streamline.streams.cluster.resource.ClusterCatalogResource.java
private Response buildClustersGetResponse(Collection<Cluster> clusters, Boolean detail) { if (BooleanUtils.isTrue(detail)) { List<ClusterResourceUtil.ClusterServicesImportResult> clustersWithServices = clusters.stream() .map(c -> ClusterResourceUtil.enrichCluster(c, environmentService)) .collect(Collectors.toList()); return WSUtils.respondEntities(clustersWithServices, OK); } else {/* w ww .j a va2 s .c om*/ return WSUtils.respondEntities(clusters, OK); } }
From source file:com.ikanow.aleph2.example.flume_harvester.services.FlumeHarvestTechnology.java
@Override public CompletableFuture<BasicMessageBean> onTestSource(DataBucketBean test_bucket, ProcessingTestSpecBean test_spec, IHarvestContext context) { try {/* w w w.ja va 2 s .c o m*/ // First try stopping any existing running service: this.onSuspend(test_bucket, context); // Then clean up from the previous test just in case: FlumeUtils.getAgents(test_bucket).stream().forEach(agent -> { final Collection<SpoolDirConfig> spool_dirs = FlumeUtils.getSpoolDirs(agent); FlumeUtils.deleteGeneratedDirs(test_bucket, spool_dirs, true); spool_dirs.stream().forEach(Lambdas.wrap_consumer_u(v -> { //TODO (ALEPH-10): handle HDFS for the overriden src path (so can go fetch //TODO (ALEPH-10): security for this setting... final File dest_path = new File(v.path() + "/" + BucketUtils.getUniqueSignature(test_bucket.full_name(), Optional.empty())); FileUtils.forceMkdir(dest_path); final File src_path = new File(Optional.ofNullable(v.test_src_path()).orElse(v.path())); if (src_path.exists()) { FileUtils.listFiles(src_path, null, false).forEach(Lambdas.wrap_consumer_u(file -> { Files.createLink(new File(dest_path.toString() + "/" + file.getName()).toPath(), file.toPath()); })); } //(else just nothing to read on this node) })); }); // Now start a normal source except in test mode final CompletableFuture<BasicMessageBean> reply = onNewSource(test_bucket, context, true, true); return reply; } catch (Exception e) { _logger.error(ErrorUtils.getLongForm("onTestSource: Unknown error {0}", e)); return FutureUtils.returnError(e); } }
From source file:com.mycompany.wolf.Room.java
private boolean contains(Collection<String> playerIds, String role) { return playerIds.stream().anyMatch(pid -> { Session session = sessions.stream().filter(s -> Objects.equals(getPlayerId(s), pid)).findAny() .orElse(null);/*from ww w . jav a2s .co m*/ if (session != null) { return Objects.equals(session.getUserProperties().get("role"), role); } return false; }); }
From source file:org.homiefund.api.service.impl.TransactionServiceImpl.java
@Override @Transactional(readOnly = true)//w ww. j a v a 2 s . c o m public PaginatedResponse<TransactionPreviewDTO> getTransactions( PaginatedRequest<TransactionPreviewDTO> paginatedRequest) throws IllegalArgumentException { if (userPreferencesBean.getPreferredHome() != null) { Home preferredHome = mapper.map(userPreferencesBean.getPreferredHome(), Home.class); User currentUser = mapper.map(securityService.getPrincipal(), User.class); Page current = paginatedRequest.getPage(); Collection<TransactionPreview> result = transactionPreviewDAO.getTransactions( (current.getPage() - 1) * current.getPageSize(), current.getPageSize(), preferredHome, mapper.map(securityService.getPrincipal(), User.class)); Long total = transactionPreviewDAO.totalTransactions(preferredHome, currentUser); return new PaginatedResponse<>(current.next(), total, (int) ((total / current.getPageSize()) + 1), result.stream().map(tx -> mapper.map(tx, TransactionPreviewDTO.class)) .collect(Collectors.toList())); } else { return new PaginatedResponse<>(paginatedRequest.getPage(), 0L, 0, new ArrayList<>()); } }
From source file:ws.salient.aws.s3.AmazonS3Repository.java
public void resolveDependencies(String dependency, Collection<RemoteRepository> repositories) { Artifact artifact = new DefaultArtifact(dependency); CollectRequest collectRequest = new CollectRequest(); Dependency root = new Dependency(artifact, ""); collectRequest.setRoot(root);/*from w ww .j a v a 2 s .c o m*/ DependencyRequest dependencyRequest = new DependencyRequest(); dependencyRequest.setCollectRequest(collectRequest); repositories.stream().forEach((repo) -> { collectRequest.addRepository(repo); }); try { aether.getSystem().resolveDependencies(aether.getSession(), dependencyRequest); log.info(dependency); } catch (DependencyResolutionException e) { log.warn("Unable to resolve dependency: " + dependency); } }
From source file:com.hortonworks.streamline.streams.service.NamespaceCatalogResource.java
private void assertServiceIsUnique(Collection<NamespaceServiceClusterMapping> mappings, String service) { if (StringUtils.isNotEmpty(service)) { long streamingEngineMappingCount = mappings.stream().filter(m -> m.getServiceName().equals(service)) .count();/*from w w w .ja v a 2 s .c o m*/ if (streamingEngineMappingCount > 1) { throw BadRequestException.message("Mappings contain more than 1 " + service); } } }
From source file:dk.dma.ais.abnormal.analyzer.analysis.FreeFlowAnalysis.java
protected void performAnalysis() { LOG.debug("Starting " + getAnalysisName() + " " + getCurrentRunTime()); final long systemTimeNanosBeforeAnalysis = nanoTime(); Collection<Track> allTracks = getTrackingService().getTracks(); List<Track> allRelevantTracksPredictedToNow = allTracks.stream().filter(this::isVesselTypeToBeAnalysed) .filter(this::isInsideAreaToBeAnalysed).filter(this::isMinimumSpeedOverGround) .map(this::predictToCurrentTime).filter(this::isPredictedToCurrentTime) .collect(Collectors.toList()); analyseFreeFlow(allRelevantTracksPredictedToNow); statisticsService.incAnalysisStatistics(getAnalysisName(), "Analyses performed"); final long systemTimeNanosAfterAnalysis = nanoTime(); LOG.debug(getAnalysisName() + " of " + allTracks.size() + " tracks completed in " + (systemTimeNanosAfterAnalysis - systemTimeNanosBeforeAnalysis) + " nsecs."); }
From source file:ai.grakn.engine.loader.client.LoaderClient.java
/** * Transform queries into Json configuration needed by the Loader task * @param queries queries to include in configuration * @return configuration for the loader task *//*w w w . j a v a2 s. c o m*/ private String getConfiguration(Collection<InsertQuery> queries) { return Json.object().set(KEYSPACE_PARAM, keyspace) .set(TASK_LOADER_INSERTS, queries.stream().map(InsertQuery::toString).collect(toList())).toString(); }