Java Code Examples for java.util.stream.Stream#distinct()
The following examples show how to use
java.util.stream.Stream#distinct() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MetadataTransformer.java From extract with MIT License | 6 votes |
private void transform(final String normalisedName, String[] values, final ValueArrayConsumer consumer) throws IOException { Stream<String> stream = Arrays.stream(values); // Remove empty values. stream = stream.filter(value -> null != value && !value.isEmpty()); // Remove duplicates. // Normalised to lowercase so that "GENERATOR" matches "Generator" (these inconsistent names can come from // HTML documents). if (values.length > 1 && deduplicateProperties.contains(fieldMap.get(normalisedName) .toLowerCase(Locale.ENGLISH))) { stream = stream.distinct(); } values = stream.toArray(String[]::new); if (values.length > 0) { consumer.accept(normalisedName, values); } }
Example 2
Source File: ModulePatcher.java From Bytecoder with Apache License 2.0 | 5 votes |
@Override public Stream<String> list() throws IOException { Stream<String> s = delegate().list(); for (ResourceFinder finder : finders) { s = Stream.concat(s, finder.list()); } return s.distinct(); }
Example 3
Source File: ModulePatcher.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override public Stream<String> list() throws IOException { Stream<String> s = delegate().list(); for (ResourceFinder finder : finders) { s = Stream.concat(s, finder.list()); } return s.distinct(); }
Example 4
Source File: BaseProofMapIndexProxyIntegrationTestable.java From exonum-java-binding with Apache License 2.0 | 5 votes |
/** * Creates map entries with the given keys. Uses values * from {@linkplain TestStorageItems#values} in a round-robin fashion. */ List<MapEntry<HashCode, String>> createMapEntries(Stream<HashCode> proofKeys) { Stream<HashCode> keys = proofKeys.distinct(); Stream<String> roundRobinValues = IntStream.range(0, Integer.MAX_VALUE) .mapToObj(i -> values.get(i % values.size())); return Streams.zip(keys, roundRobinValues, MapEntry::valueOf) .collect(toList()); }
Example 5
Source File: OrderIterator.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
private Stream<BindingSet> sort(Collection<BindingSet> collection) { BindingSet[] array = collection.toArray(new BindingSet[collection.size()]); Arrays.parallelSort(array, comparator); Stream<BindingSet> stream = Stream.of(array); if (distinct) { stream = stream.distinct(); } if (limit < Integer.MAX_VALUE) { stream = stream.limit(limit); } return stream; }
Example 6
Source File: Echo.java From demo-java-x with MIT License | 5 votes |
private static Stream<String> modifyStream(String arg, Stream<String> input) { switch (arg){ case "--sort": return input.sorted(); case "--unique": return input.distinct(); case "--reverse": return reverse(input); default: { System.out.println("Unknown argument '" + arg + "'."); return input; } } }
Example 7
Source File: UnionExecutionStep.java From vertexium with Apache License 2.0 | 5 votes |
@Override public VertexiumCypherResult execute(VertexiumCypherQueryContext ctx, VertexiumCypherResult source) { LinkedHashSet<String> columnNames = new LinkedHashSet<>(); Stream<CypherResultRow> rows = Stream.of(); for (ExecutionStep step : getChildSteps().collect(Collectors.toList())) { VertexiumCypherResult result = step.execute(ctx, null); columnNames.addAll(result.getColumnNames()); rows = Stream.concat(rows, result); } if (!all) { rows = rows.distinct(); } return new VertexiumCypherResult(rows, columnNames); }
Example 8
Source File: WorkMgr.java From batfish with Apache License 2.0 | 5 votes |
@VisibleForTesting @Nonnull TableAnswerElement processAnswerTable(TableAnswerElement rawTable, AnswerRowsOptions options) { Map<String, ColumnMetadata> rawColumnMap = rawTable.getMetadata().toColumnMap(); List<Row> filteredRows = rawTable.getRowsList().stream() .filter(row -> options.getFilters().stream().allMatch(filter -> filter.matches(row))) .collect(ImmutableList.toImmutableList()); Stream<Row> rowStream = filteredRows.stream(); if (!options.getSortOrder().isEmpty()) { // sort using specified sort order rowStream = rowStream.sorted(buildComparator(rawColumnMap, options.getSortOrder())); } TableAnswerElement table; if (options.getColumns().isEmpty()) { table = new TableAnswerElement(rawTable.getMetadata()); } else { // project to desired columns rowStream = rowStream.map(rawRow -> Row.builder().putAll(rawRow, options.getColumns()).build()); Map<String, ColumnMetadata> columnMap = new LinkedHashMap<>(rawColumnMap); columnMap.keySet().retainAll(options.getColumns()); List<ColumnMetadata> columnMetadata = columnMap.values().stream().collect(ImmutableList.toImmutableList()); table = new TableAnswerElement( new TableMetadata(columnMetadata, rawTable.getMetadata().getTextDesc())); } if (options.getUniqueRows()) { // uniquify if desired rowStream = rowStream.distinct(); } // offset, truncate, and add to table rowStream.skip(options.getRowOffset()).limit(options.getMaxRows()).forEach(table::addRow); table.setSummary(rawTable.getSummary() != null ? rawTable.getSummary() : new AnswerSummary()); table.getSummary().setNumResults(filteredRows.size()); return table; }
Example 9
Source File: Uniq.java From unix-stream with MIT License | 4 votes |
@Override public Stream<T> apply(Stream<T> input) { return input.distinct(); }
Example 10
Source File: StreamUtils.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
public static <T> Stream<T> distinct( Stream<T> stream ) { return stream.distinct(); }