List of usage examples for java.util.stream Collectors reducing
public static <T, U> Collector<T, ?, U> reducing(U identity, Function<? super T, ? extends U> mapper, BinaryOperator<U> op)
From source file:Main.java
public static void main(String... args) { int o = Food.menu.stream().collect(Collectors.reducing(0, Food::getCalories, Integer::sum)); System.out.println(o);/*from ww w . j av a 2s .co m*/ }
From source file:Main.java
public static void main(String... args) { int o = Food.menu.stream() .collect(Collectors.reducing(0, Food::getCalories, (Integer i, Integer j) -> i + j)); System.out.println(o);/* www . ja va2 s . c o m*/ }
From source file:Main.java
public static void main(String[] args) { List<Person> roster = createRoster(); System.out.println("Total age by gender:"); Map<Person.Sex, Integer> totalAgeByGender = roster.stream().collect( Collectors.groupingBy(Person::getGender, Collectors.reducing(0, Person::getAge, Integer::sum))); List<Map.Entry<Person.Sex, Integer>> totalAgeByGenderList = new ArrayList<>(totalAgeByGender.entrySet()); totalAgeByGenderList.stream()/* w w w. ja v a 2 s. co m*/ .forEach(e -> System.out.println("Gender: " + e.getKey() + ", Total Age: " + e.getValue())); }
From source file:com.netflix.spinnaker.clouddriver.kubernetes.v2.caching.KubernetesV2SearchProvider.java
private Map<String, List<String>> getKeysRelatedToLogicalMatches(String matchQuery) { return logicalTypes.stream().map(type -> cacheUtils.getAllDataMatchingPattern(type, matchQuery).stream() .map(e -> e.getRelationships().values().stream().flatMap(Collection::stream) .filter(Objects::nonNull).map(k -> new ImmutablePair<>(k, e.getId()))) .flatMap(x -> x)).flatMap(x -> x) .collect(Collectors.groupingBy(Pair::getLeft, Collectors.reducing(Collections.emptyList(), i -> Collections.singletonList(i.getRight()), (a, b) -> { List<String> res = new ArrayList<>(); res.addAll(a);//w w w . j ava2s. c o m res.addAll(b); return res; }))); }
From source file:com.diversityarrays.kdxplore.data.kdx.CurationDataCollector.java
public CurationDataCollector(KdxploreDatabase kdxdb, Trial trial, boolean fullDetails) throws IOException, KdxploreConfigException { this.trial = trial; int trialId = trial.getTrialId(); this.deviceIdentifiers = kdxdb.getDeviceIdentifiers(); deviceIdentifierById.clear();/*from w w w . j ava 2s .c om*/ for (DeviceIdentifier d : deviceIdentifiers) { deviceIdentifierById.put(d.getDeviceIdentifierId(), d); } // ProgressUpdater progressUpdater; // kdxdb.getKDXploreKSmartDatabase().collectPlotsFor(trial, // SampleGroupChoice.ANY_SAMPLE_GROUP, // KDSmartDatabase.WithPlotAttributesOption.WITH_PLOT_ATTRIBUTES, // KDSmartDatabase.WithTraitOption.ALL_WITH_TRAITS, // progressUpdater); // // this.plots = kdxdb.getPlots(trial, SampleGroupChoice.ANY_SAMPLE_GROUP, // KDSmartDatabase.WithPlotAttributesOption.WITH_PLOT_ATTRIBUTES); Closure<Pair<WhyMissing, MediaFileRecord>> reportMissing = new Closure<Pair<WhyMissing, MediaFileRecord>>() { @Override public void execute(Pair<WhyMissing, MediaFileRecord> arg0) { // TODO Auto-generated method stub } }; Map<Integer, Plot> plotById = DatabaseUtil.collectPlotsIncludingMediaFiles( kdxdb.getKDXploreKSmartDatabase(), trialId, "CurationDataCollector", SampleGroupChoice.ANY_SAMPLE_GROUP, reportMissing); this.plots = new ArrayList<>(plotById.values()); this.countByTagLabel = Collections.unmodifiableMap(plots.stream() .flatMap(plot -> plot.getTagsBySampleGroup().entrySet().stream()) .flatMap(e -> e.getValue().stream()) .collect(Collectors.groupingBy(Tag::getLabel, Collectors.reducing(0, e -> 1, Integer::sum)))); collectPlotPositionIdentifiers(plots); trialAttributes = kdxdb.getTrialAttributes(trialId); KDSmartDatabase kdsdb = kdxdb.getKDXploreKSmartDatabase(); plotAttributes = kdsdb.getAllPlotAttributesForTrial(trialId); traitInstances = kdsdb.getTraitInstances(trialId, KDSmartDatabase.WithTraitOption.ALL_WITH_TRAITS); // tagById.clear(); // for (Tag tag : kdsdb.getAllTags()) { // tagById.put(tag.getTagId(), tag); // } // collectTagPlotUsage(trialId, kdsdb); // collectMediaFileRecords(trialId, kdsdb); loadSampleGroups(kdxdb, trialId, fullDetails); }