List of usage examples for java.util.stream Collectors groupingBy
public static <T, K> Collector<T, ?, Map<K, List<T>>> groupingBy(Function<? super T, ? extends K> classifier)
From source file:com.github.horrorho.inflatabledonkey.cloud.AuthorizeAssets.java
Map<ByteString, List<Asset>> downloadables(Collection<Asset> assets) { return assets.stream().filter(this::isDownloadable) .collect(Collectors.groupingBy(a -> ByteString.copyFrom(a.fileSignature().get()))); }
From source file:com.hurence.logisland.plugin.PluginManager.java
private static Map<ModuleInfo, List<String>> findPluginMeta() { return PluginLoader.getRegistry().entrySet().stream() .map(e -> new Tuple<>(((PluginClassLoader) e.getValue()).getModuleInfo(), e.getKey())) .collect(Collectors.groupingBy(t -> t.getKey().getArtifact())).entrySet().stream() .collect(Collectors.toMap(e -> e.getValue().stream().findFirst().get().getKey(), e -> e.getValue().stream().map(Tuple::getValue).sorted().collect(Collectors.toList()))); }
From source file:com.github.horrorho.inflatabledonkey.BackupAssistant.java
public Map<Device, List<Snapshot>> deviceSnapshots(HttpClient httpClient, Collection<Device> devices) throws IOException { Map<SnapshotID, Device> snapshotDevice = devices.stream().distinct() .flatMap(d -> d.snapshotIDs().stream().map(s -> new SimpleImmutableEntry<>(s, d))) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); List<SnapshotID> snapshotIDs = devices.stream().map(Device::snapshotIDs).flatMap(Collection::stream) .collect(Collectors.toList()); return snapshots(httpClient, snapshotIDs).stream() .collect(Collectors.groupingBy(s -> snapshotDevice.get(s.snapshotID()))); }
From source file:com.gs.collections.impl.jmh.AnagramBagTest.java
@Benchmark public void serial_lazy_jdk() { Map<Alphagram, List<String>> groupBy = this.guavaWords.stream() .collect(Collectors.groupingBy(Alphagram::new)); groupBy.entrySet().stream().map(Map.Entry::getValue).filter(list -> list.size() >= SIZE_THRESHOLD) .sorted(Comparator.<List<String>>comparingInt(List::size).reversed()) .map(list -> list.size() + ": " + list).forEach(e -> Assert.assertFalse(e.isEmpty())); }
From source file:alfio.controller.api.admin.ExtensionApiController.java
@RequestMapping(value = "/setting/system", method = RequestMethod.GET) public Map<Integer, List<ExtensionParameterMetadataAndValue>> getParametersFor(Principal principal) { ensureAdmin(principal);/*from w ww .j ava2s . com*/ return extensionService.getConfigurationParametersFor("-", "-%", "SYSTEM").stream() .collect(Collectors.groupingBy(ExtensionParameterMetadataAndValue::getExtensionId)); }
From source file:org.obiba.mica.dataset.search.rest.AbstractPublishedDatasetResource.java
protected Mica.DatasetVariablesDto getDatasetVariableDtosInternal(String rql, int from, int limit, @Nullable String sort, @Nullable String order) { String rqlSort = ""; if (!Strings.isNullOrEmpty(sort)) { String orderOp = !Strings.isNullOrEmpty(order) && "DESC".equals(order.toUpperCase()) ? "-" : ""; rqlSort = String.format(",sort(%s)", orderOp + sort); }/*from w w w .ja v a 2 s .c o m*/ String query = String.format("variable(%s,limit(%s,%s)%s)", rql, from, limit, rqlSort); Searcher.DocumentResults results = searcher.find(Indexer.PUBLISHED_VARIABLE_INDEX, Indexer.VARIABLE_TYPE, query); Mica.DatasetVariablesDto.Builder builder = Mica.DatasetVariablesDto.newBuilder() .setTotal(Long.valueOf(results.getTotal()).intValue()).setFrom(from).setLimit(limit); List<Taxonomy> taxonomies = getTaxonomies(); Map<String, List<DatasetVariable>> studyIdVariableMap = results.getDocuments().stream().map(res -> { try { return objectMapper.readValue(res.getSourceInputStream(), DatasetVariable.class); } catch (IOException e) { log.error("Failed retrieving {}", DatasetVariable.class.getSimpleName(), e); return null; } }).filter(Objects::nonNull).collect(Collectors.groupingBy(DatasetVariable::getStudyId)); builder.addAllVariables(dtos.asDtos(studyIdVariableMap, taxonomies)); log.info("Response /{}/{}", Indexer.PUBLISHED_VARIABLE_INDEX, Indexer.VARIABLE_TYPE); return builder.build(); }
From source file:com.ikanow.aleph2.data_import_manager.analytics.utils.TestAnalyticTriggerCrudUtils.java
@Test public void test_storeOrUpdateTriggerStage_relativeCheckTime() throws InterruptedException { assertEquals(0, _test_crud.countObjects().join().intValue()); // Same as start to test_storeOrUpdateTriggerStage_updateActivation, except check that the next check isn't scheduled immediately final DataBucketBean bucket = BeanTemplateUtils.clone(buildBucket("/test/store/trigger", true)) .with(DataBucketBean::poll_frequency, "2am tomorrow").done(); // Save a bucket {//from w w w .j av a2 s .co m final Stream<AnalyticTriggerStateBean> test_stream = AnalyticTriggerBeanUtils .generateTriggerStateStream(bucket, false, Optional.empty()); final List<AnalyticTriggerStateBean> test_list = test_stream.collect(Collectors.toList()); System.out.println("Resources = \n" + test_list.stream() .map(t -> BeanTemplateUtils.toJson(t).toString()).collect(Collectors.joining("\n"))); assertEquals(8L, test_list.size()); //(8 not 7 cos haven't dedup'd yet) // 4 internal dependencies assertEquals(4L, test_list.stream().filter(t -> null != t.job_name()).count()); // 4 external dependencies assertEquals(4L, test_list.stream().filter(t -> null == t.job_name()).count()); final Map<Tuple2<String, String>, List<AnalyticTriggerStateBean>> grouped_triggers = test_list.stream() .collect(Collectors.groupingBy(t -> Tuples._2T(t.bucket_name(), null))); AnalyticTriggerCrudUtils.storeOrUpdateTriggerStage(bucket, _test_crud, grouped_triggers).join(); assertEquals(7L, _test_crud.countObjects().join().intValue()); // Only the internal triggers are scheduled for an immediate check assertEquals(4L, _test_crud .countObjectsBySpec(CrudUtils.allOf(AnalyticTriggerStateBean.class) .rangeBelow(AnalyticTriggerStateBean::next_check, new Date(), false)) .join().intValue()); } }
From source file:com.hack23.cia.web.impl.ui.application.views.common.chartfactory.impl.DocumentChartDataManagerImpl.java
/** * Gets the view riksdagen org document daily summary map. * * @return the view riksdagen org document daily summary map *///from ww w .ja v a 2s . c o m private Map<String, List<ViewRiksdagenOrgDocumentDailySummary>> getViewRiksdagenOrgDocumentDailySummaryMap() { final DataContainer<ViewRiksdagenOrgDocumentDailySummary, RiksdagenDocumentOrgSummaryEmbeddedId> politicianBallotSummaryDailyDataContainer = applicationManager .getDataContainer(ViewRiksdagenOrgDocumentDailySummary.class); return politicianBallotSummaryDailyDataContainer.getAll().parallelStream() .filter(t -> t != null && !t.getEmbeddedId().getPublicDate().startsWith(YEAR_PREFIX)) .collect(Collectors.groupingBy( t -> StringEscapeUtils.unescapeHtml4(t.getEmbeddedId().getOrg()).toUpperCase(Locale.ENGLISH) .replace(UNDER_SCORE, EMPTY_STRING).replace(MINUS_SIGN, EMPTY_STRING).trim())); }
From source file:com.cocktail.initializer.CocktailInitializer.java
/** * Sets the cocktail steps./*from w w w .jav a2 s. com*/ * * @param cocktails * the cocktails * @param stepData * the step data */ private void setCocktailSteps(List<Cocktail> cocktails, List<StepData> stepData) { Map<String, List<StepData>> groupedSteps = stepData.stream() .collect(Collectors.groupingBy(p -> p.getCocktail().toUpperCase())); for (Cocktail cocktail : cocktails) { List<Step> steps = new ArrayList<>(); groupedSteps.get(cocktail.getName().toUpperCase()).forEach(s -> steps.add(s.getStep())); cocktail.setSteps(steps); } }
From source file:com.gs.collections.impl.jmh.AnagramBagTest.java
@Benchmark public void parallel_lazy_jdk() { Map<Alphagram, List<String>> groupBy = this.guavaWords.parallelStream() .collect(Collectors.groupingBy(Alphagram::new)); groupBy.entrySet().parallelStream().map(Map.Entry::getValue).filter(list -> list.size() >= SIZE_THRESHOLD) .sorted(Comparator.<List<String>>comparingInt(List::size).reversed()) .map(list -> list.size() + ": " + list).forEach(e -> Assert.assertFalse(e.isEmpty())); }