List of usage examples for java.util Collection stream
default Stream<E> stream()
From source file:io.logspace.hq.core.solr.event.SolrEventService.java
@Override public void store(Collection<? extends Event> events, String space) { if (events == null || events.isEmpty()) { return;//from www. j av a 2s . c om } String system = events.stream().findFirst().get().getSystem(); this.logger.debug("Storing {} event(s) for space '{}' from system {}", events.size(), space, system); try { Collection<SolrInputDocument> inputDocuments = this.createInputDocuments(events, space); this.solrClient.add(inputDocuments); this.logger.info("Successfully stored {} event(s) for space '{}' from system {}", events.size(), space, system); } catch (SolrServerException | IOException e) { String message = "Failed to store " + events.size() + " events."; this.logger.error(message, e); throw EventStoreException.storeFailed(message, e); } }
From source file:com.adobe.acs.commons.mcp.impl.processes.asset.UrlAssetImport.java
private Optional<FileOrRendition> findOriginalRendition(Collection<FileOrRendition> allFiles, FileOrRendition rendition) {//from w ww .j av a2 s . c om // Build list of files in the target folder List<FileOrRendition> filesInFolder = allFiles.stream() .filter(f -> f.getParent().getNodePath().equals(rendition.getParent().getNodePath())) .collect(Collectors.toList()); if (filesInFolder.isEmpty()) { LOG.error("Unable to find any other files in directory " + rendition.getParent().getNodePath()); return Optional.empty(); } else { // Organize files by closest match (better match = smaller levensthein distance) String fileName = rendition.getOriginalAssetName() == null || rendition.getOriginalAssetName().isEmpty() ? rendition.getName().toLowerCase() : rendition.getOriginalAssetName().toLowerCase(); filesInFolder.sort((a, b) -> compareName(a, b, fileName)); // Return best match return Optional.of(filesInFolder.get(0)); } }
From source file:com.taobao.android.builder.tools.multidex.dex.DexMerger.java
public DexMerger(MultiDexConfig multiDexConfig, Collection<File> fileList) throws IOException { this.multiDexConfig = multiDexConfig; this.fileList = fileList.stream().sorted(new FileComparator()).collect(Collectors.toList()); for (File file : fileList) { Dex dex = new Dex(file); jarDexMap.put(file, dex);/*w w w. jav a 2 s.c o m*/ } dexList = new ArrayList<>(jarDexMap.values()); }
From source file:edu.washington.gs.skyline.model.quantification.FoldChangeDataSet.java
/** * Construct a new FoldChangeDataSet. The first four collections must all have the same number of elements. * The "subjectControls" must have the same number of elements as the number of unique values of "subjects". * @param abundances log2 intensity//from w ww. ja v a 2 s . co m * @param features identifiers of the transition that the abundance was measured for. Note that Skyline always sums * the transition intensities before coming in here, the feature values should all be zero. * @param runs integers representing which replicate the value came from * @param subjects identifiers used for combining biological replicates. * @param subjectControls specifies which subject values belong to the control group. */ public FoldChangeDataSet(Collection<Double> abundances, Collection<Integer> features, Collection<Integer> runs, Collection<Integer> subjects, Collection<Boolean> subjectControls) { if (abundances.size() != features.size() || abundances.size() != subjects.size() || abundances.size() != runs.size()) { throw new IllegalArgumentException("Wrong number of rows"); } this.abundances = abundances.stream().mapToDouble(Double::doubleValue).toArray(); this.features = features.stream().mapToInt(Integer::intValue).toArray(); this.runs = runs.stream().mapToInt(Integer::intValue).toArray(); this.subjects = subjects.stream().mapToInt(Integer::intValue).toArray(); this.subjectControls = ArrayUtils.toPrimitive(subjectControls.toArray(new Boolean[subjectControls.size()])); if (this.abundances.length == 0) { featureCount = 0; subjectCount = 0; runCount = 0; } else { if (Arrays.stream(this.features).min().getAsInt() < 0 || Arrays.stream(this.runs).min().getAsInt() < 0 || Arrays.stream(this.subjects).min().getAsInt() < 0) { throw new IllegalArgumentException("Cannot be negative"); } featureCount = Arrays.stream(this.features).max().getAsInt() + 1; subjectCount = Arrays.stream(this.subjects).max().getAsInt() + 1; runCount = Arrays.stream(this.runs).max().getAsInt() + 1; } if (this.subjectControls.length != subjectCount) { throw new IllegalArgumentException("Wrong number of subjects"); } }
From source file:com.hortonworks.streamline.streams.service.ClusterCatalogResource.java
private Response buildClustersGetResponse(Collection<Cluster> clusters, Boolean detail) { if (BooleanUtils.isTrue(detail)) { List<CatalogResourceUtil.ClusterServicesImportResult> clustersWithServices = clusters.stream() .map(c -> CatalogResourceUtil.enrichCluster(c, environmentService)) .collect(Collectors.toList()); return WSUtils.respondEntities(clustersWithServices, OK); } else {/*from ww w. ja v a 2 s. c om*/ return WSUtils.respondEntities(clusters, OK); } }
From source file:com.thinkbiganalytics.feedmgr.service.feed.FeedModelTransform.java
/** * Transforms the specified Metadata feeds to Feed Manager feed summaries. * * @param domain the Metadata feed/*from w w w . j ava 2 s.c o m*/ * @return the Feed Manager feed summaries */ @Nonnull public List<FeedSummary> domainToFeedSummary(@Nonnull final Collection<? extends Feed> domain) { return domain.stream().map(this::domainToFeedSummary).filter(feedSummary -> feedSummary != null) .collect(Collectors.toList()); }
From source file:com.example.app.profile.model.location.LocationDAO.java
/** * Delete the given Locations from the database * * @param locations the locations to delete *///from w ww .j a va 2s. c om public void deleteLocations(final Collection<? extends Location> locations) { doInTransaction(session -> { final String hql = "update " + Location.class.getSimpleName() + " location" + " set location." + SoftDeleteEntity.SOFT_DELETE_COLUMN_PROP + " = true" + " where location in :locations"; session.createQuery(hql) .setParameterList("locations", locations.stream().map(Location::getId).toArray(Integer[]::new)) .executeUpdate(); }); }
From source file:com.hortonworks.streamline.streams.service.NamespaceCatalogResource.java
private void assertNoTopologyReferringNamespaceIsRunning(Long namespaceId, String asUser) { Collection<Topology> topologies = catalogService.listTopologies(); List<Topology> runningTopologiesInNamespace = topologies.stream() .filter(t -> Objects.equals(t.getNamespaceId(), namespaceId)).filter(t -> { try { topologyActionsService.getRuntimeTopologyId(t, asUser); return true; } catch (TopologyNotAliveException | IOException e) { // if streaming engine is not accessible, we just treat it as not running return false; }//from www .j av a2 s . co m }).collect(toList()); if (!runningTopologiesInNamespace.isEmpty()) { throw BadRequestException.message( "Trying to modify mapping of streaming engine while Topology is running - namespace id: " + namespaceId); } }
From source file:com.haulmont.cuba.gui.relatedentities.RelatedEntitiesBean.java
protected List<Object> getParentIds(Collection<? extends Entity> selectedParents) { if (selectedParents.isEmpty()) { return Collections.emptyList(); } else {/*from ww w .j av a 2s.co m*/ return selectedParents.stream().map(Entity::getId).collect(Collectors.toList()); } }
From source file:ch.sdi.core.impl.data.InputTransformerProperties.java
/** * Reads the ignored fields into member myIgnoredFields and returns a collection of all raw field * names which are not filtered (sdi.normalize.ignoreField). * <p>/* w ww . ja v a 2 s. co m*/ * @param aFieldnames * the collected fieldnames * @return */ private Collection<String> getFilteredRawFieldNames(Collection<String> aFieldnames) { String value = myEnv.getProperty(SdiMainProperties.KEY_NORMALIZE_IGNORE_FIELD); if (!StringUtils.hasText(value)) { myLog.debug("no normalize field filters configured"); myIgnoredFields = new ArrayList<>(); return aFieldnames; } // if !StringUtils.hasText( value ) myIgnoredFields = Arrays.asList(value.split(",")); return aFieldnames.stream().filter(f -> !myIgnoredFields.contains(f)) .collect(Collectors.toCollection((Supplier<List<String>>) ArrayList::new)); }