@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())); }
/** * Given a filter and a set of rows, returns the subset of rows that match the filter * * @param filter The filter that should be matched * @param inputRows The input set of rows * @return A new set with matching rows */ @VisibleForTesting static Multiset<Row> filterRows(Filter filter, Multiset<Row> inputRows) { return inputRows.stream() .filter(filter::matches) .collect(ImmutableMultiset.toImmutableMultiset()); }
@Override public void visit(BuiltinSet builtinSet) { builtinSet.elements().stream().forEach(this::visitNode); builtinSet.baseTerms().stream().forEach(this::visitNode); visit((Collection) builtinSet); }
@Override public Set<String> tokens(Iterable<?> iterable) { Multiset<String> tokens = HashMultiset.create(); int index = 0; for (Object item : iterable) { tokens.add(String.valueOf(index++)); tokens.addAll(fieldValues(item)); } return tokens.stream() .filter(token -> tokens.count(token) == 1) .collect(toImmutableSet()); }
@Override public void visit(BuiltinMap builtinMap) { builtinMap.getEntries().entrySet().stream().forEach(e -> { visitNode(e.getKey()); visitNode(e.getValue()); }); builtinMap.baseTerms().stream().forEach(this::visitNode); visit((Collection) builtinMap); }
/** * Selects specified columns from the Multiset of rows that is provided as input. A new set is * created and returned, and the input is not modified. * * @param columns The columns to select * @param inputRows The input set. * @returns A new set of rows with specified columns */ @VisibleForTesting static Multiset<Row> selectColumns(Set<String> columns, Multiset<Row> inputRows) { return inputRows.stream() .map(row -> Row.builder().putAll(row, columns).build()) .collect(ImmutableMultiset.toImmutableMultiset()); } }
@Override public boolean matches(@Nonnull OWLEntity entity) { // Count languages by property Map<OWLAnnotationProperty, Multiset<String>> prop2Langs = new HashMap<>(); axiomsIndex.getAnnotationAssertionAxioms(entity.getIRI()) .filter(ax -> propertyMatcher.matches(ax.getProperty())) .filter(ax -> ax.getValue() instanceof OWLLiteral) .forEach(ax -> { Multiset<String> langs = prop2Langs.computeIfAbsent(ax.getProperty(), p -> HashMultiset.create()); String lang = ((OWLLiteral) ax.getValue()).getLang(); langs.add(lang); }); return prop2Langs.values().stream() .anyMatch(langsForProp -> langsForProp.stream().anyMatch(lang -> langsForProp.count(lang) > 1)); } }
return table.getRows().getData().stream() .map(rowToInteger) .filter(Objects::nonNull)
@Override public AnswerElement answer() { IpsecSessionStatusQuestion question = (IpsecSessionStatusQuestion) _question; Map<String, Configuration> configurations = _batfish.loadConfigurations(); NetworkConfigurations networkConfigurations = NetworkConfigurations.of(configurations); ValueGraph<IpsecPeerConfigId, IpsecSession> ipsecTopology = IpsecUtil.initIpsecTopology(configurations); Set<String> initiatorNodes = question.getInitiatorRegex().getMatchingNodes(_batfish); Set<String> responderNodes = question.getResponderRegex().getMatchingNodes(_batfish); TableAnswerElement answerElement = new TableAnswerElement(createTableMetaData(question)); Multiset<IpsecSessionInfo> ipsecSessionInfos = rawAnswer(networkConfigurations, ipsecTopology, initiatorNodes, responderNodes); answerElement.postProcessAnswer( question, ipsecSessionInfos.stream() .filter( ipsecSessionInfo -> question.matchesStatus(ipsecSessionInfo.getIpsecSessionStatus())) .map(IpsecSessionStatusAnswerer::toRow) .collect(Collectors.toCollection(HashMultiset::create))); return answerElement; }