Java Code Examples for com.google.common.collect.Streams#stream()
The following examples show how to use
com.google.common.collect.Streams#stream() .
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: FileSystemReader.java From geowave with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") private CloseableIterator<T> wrapResults( final Closeable closeable, final Iterator<GeoWaveRow> results, final RangeReaderParams<T> params, final GeoWaveRowIteratorTransformer<T> rowTransformer, final Set<String> authorizations, final boolean visibilityEnabled) { Stream<GeoWaveRow> stream = Streams.stream(results); if (visibilityEnabled) { stream = stream.filter(new ClientVisibilityFilter(authorizations)); } final Iterator<GeoWaveRow> iterator = stream.iterator(); return new CloseableIteratorWrapper<>( closeable, rowTransformer.apply( sortBySortKeyIfRequired( params, DataStoreUtils.isMergingIteratorRequired(params, visibilityEnabled) ? new GeoWaveRowMergingIterator(iterator) : iterator))); }
Example 2
Source File: TestServer.java From presto with Apache License 2.0 | 5 votes |
private Stream<JsonResponse<QueryResults>> postQuery(Function<Request.Builder, Request.Builder> requestConfigurer) { Request.Builder request = preparePost() .setUri(uriFor("/v1/statement")) .setHeader(PRESTO_USER, "user") .setHeader(PRESTO_SOURCE, "source"); request = requestConfigurer.apply(request); JsonResponse<QueryResults> queryResults = client.execute(request.build(), createFullJsonResponseHandler(QUERY_RESULTS_CODEC)); return Streams.stream(new QueryResultsIterator(client, queryResults)); }
Example 3
Source File: GuavaStreamsUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void createStreamsWithOptional() { Stream streamFromOptional = Streams.stream(Optional.of(1)); assertNotNull(streamFromOptional); assertEquals(streamFromOptional.count(), 1); }
Example 4
Source File: GuavaStreamsUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void createStreamsWithIterable() { Iterable<Integer> numbersIterable = numbers; Stream streamFromIterable = Streams.stream(numbersIterable); assertNotNull(streamFromIterable); assertStreamEquals(streamFromIterable, numbers.stream()); }
Example 5
Source File: GuavaStreamsUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void createStreamsWithOptionalLong() { LongStream streamFromOptionalLong = Streams.stream(OptionalLong.of(1)); assertNotNull(streamFromOptionalLong); assertEquals(streamFromOptionalLong.count(), 1); }
Example 6
Source File: GenerateAllocationTokensCommand.java From nomulus with Apache License 2.0 | 5 votes |
private Stream<String> getNextTokenBatch(int tokensSaved) { if (tokenStrings != null) { return Streams.stream(Iterables.limit(Iterables.skip(tokenStrings, tokensSaved), BATCH_SIZE)); } else { return generateTokens(BATCH_SIZE).stream().limit(numTokens - tokensSaved); } }
Example 7
Source File: GuavaStreamsUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void createStreamsWithCollection() { //Deprecated API to create stream from collection Stream streamFromCollection = Streams.stream(numbers); //Assert.assertNotNull(streamFromCollection); assertStreamEquals(streamFromCollection, numbers.stream()); }
Example 8
Source File: Icd10ClassExpanderImpl.java From molgenis with GNU Lesser General Public License v3.0 | 4 votes |
private Stream<Entity> expandClass(Entity diseaseClass) { Iterable<Entity> diseaseClasses = new DiseaseClassTreeTraverser().postOrderTraversal(diseaseClass); return Streams.stream(diseaseClasses); }
Example 9
Source File: RedisReader.java From geowave with Apache License 2.0 | 4 votes |
private Iterator<GeoWaveRow> createIteratorForDataIndexReader( final RedissonClient client, final Serialization serialization, final Compression compression, final DataIndexReaderParams dataIndexReaderParams, final String namespace, final boolean visibilityEnabled) { Iterator<GeoWaveRow> retVal; if (dataIndexReaderParams.getDataIds() != null) { retVal = new DataIndexRead( client, serialization, compression, namespace, dataIndexReaderParams.getInternalAdapterStore().getTypeName( dataIndexReaderParams.getAdapterId()), dataIndexReaderParams.getAdapterId(), dataIndexReaderParams.getDataIds(), visibilityEnabled).results(); } else { retVal = new DataIndexRangeRead( client, serialization, compression, namespace, dataIndexReaderParams.getInternalAdapterStore().getTypeName( dataIndexReaderParams.getAdapterId()), dataIndexReaderParams.getAdapterId(), dataIndexReaderParams.getStartInclusiveDataId(), dataIndexReaderParams.getEndInclusiveDataId(), visibilityEnabled).results(); } if (visibilityEnabled) { Stream<GeoWaveRow> stream = Streams.stream(retVal); final Set<String> authorizations = Sets.newHashSet(dataIndexReaderParams.getAdditionalAuthorizations()); stream = stream.filter(new ClientVisibilityFilter(authorizations)); retVal = stream.iterator(); } return retVal; }
Example 10
Source File: UnconfiguredBuildTargetParser.java From buck with Apache License 2.0 | 4 votes |
/** * Parse a string representing fully qualified build target, validating build target format * * <p>Fully qualified build target format is `cell//path/to:target#flavor1,flavor2` where cell may * be an empty string, and flavors may be omitted along with `#` sign * * <p>The target must be in canonical form. Importantly, the cell name must be the canonical name. * * @param target String representing fully-qualified build target, for example "//foo/bar:bar" * @param intern Whether to intern parsed instance; once interned the instance stays in memory * forever but subsequent hash map/set operations are faster because {@link * Object#equals(Object)} is cheap * @throws BuildTargetParseException If build target format is invalid; at this moment {@link * BuildTargetParseException} is unchecked exception but we still want to declare it with the * hope to make it checked one day; this type of exception would be properly handled as user * error */ public static UnconfiguredBuildTarget parse(String target, boolean intern) throws BuildTargetParseException { int rootPos = target.indexOf(BuildTargetLanguageConstants.ROOT_SYMBOL); check( rootPos >= 0, target, "should start with either '%s' or a cell name followed by '%s'", BuildTargetLanguageConstants.ROOT_SYMBOL, BuildTargetLanguageConstants.ROOT_SYMBOL); // if build target starts with `//` then cellName would be empty string String cellName = target.substring(0, rootPos); int pathPos = rootPos + BuildTargetLanguageConstants.ROOT_SYMBOL.length(); int flavorSymbolPos = target.lastIndexOf(BuildTargetLanguageConstants.FLAVOR_SYMBOL); ImmutableSortedSet<Flavor> flavors; if (flavorSymbolPos < 0) { // assume no flavors flavorSymbolPos = target.length(); flavors = FlavorSet.NO_FLAVORS.getSet(); } else { String flavorsString = target.substring(flavorSymbolPos + 1); Stream<String> stream = Streams.stream( Splitter.on(BuildTargetLanguageConstants.FLAVOR_DELIMITER) .omitEmptyStrings() .trimResults() .split(flavorsString)); if (intern) { stream = stream.map(String::intern); } flavors = stream // potentially we could intern InternalFlavor object as well .map(flavor -> (Flavor) InternalFlavor.of(flavor)) .collect(ImmutableSortedSet.toImmutableSortedSet(FlavorSet.FLAVOR_ORDERING)); check( !flavors.isEmpty(), target, "should have flavors specified after '%s' sign", BuildTargetLanguageConstants.FLAVOR_SYMBOL); } int targetSymbolPos = target.lastIndexOf(BuildTargetLanguageConstants.TARGET_SYMBOL, flavorSymbolPos - 1); check( targetSymbolPos >= pathPos && targetSymbolPos < target.length(), target, "should have '%s' followed by target name", BuildTargetLanguageConstants.TARGET_SYMBOL); BaseName baseName = BaseName.of(target.substring(rootPos, targetSymbolPos)); String targetName = target.substring(targetSymbolPos + 1, flavorSymbolPos); check( !targetName.isEmpty(), target, "should have target name after '%s' sign", BuildTargetLanguageConstants.TARGET_SYMBOL); CanonicalCellName canonicalCellName = cellName.isEmpty() ? CanonicalCellName.rootCell() : CanonicalCellName.unsafeOf(Optional.of(cellName)); return UnconfiguredBuildTarget.of( canonicalCellName, baseName, targetName, FlavorSet.copyOf(flavors)); }
Example 11
Source File: QueryParamGetters.java From armeria with Apache License 2.0 | 4 votes |
/** * Returns a {@link Stream} that yields all values of the parameters with the specified {@code name}. */ @Override default Stream<String> valueStream(String name) { requireNonNull(name, "name"); return Streams.stream(valueIterator(name)); }
Example 12
Source File: QueryParamGetters.java From armeria with Apache License 2.0 | 4 votes |
/** * Returns a {@link Stream} that yields all parameter entries. */ @Override default Stream<Entry<String, String>> stream() { return Streams.stream(iterator()); }
Example 13
Source File: HttpHeaderGetters.java From armeria with Apache License 2.0 | 4 votes |
/** * Returns a {@link Stream} that yields all values of the headers with the specified {@code name}. */ @Override default Stream<String> valueStream(CharSequence name) { requireNonNull(name, "name"); return Streams.stream(valueIterator(name)); }
Example 14
Source File: HttpHeaderGetters.java From armeria with Apache License 2.0 | 4 votes |
/** * Returns a {@link Stream} that yields all header entries. */ @Override default Stream<Entry<AsciiString, String>> stream() { return Streams.stream(iterator()); }
Example 15
Source File: VSChunkClaim.java From Valkyrien-Skies with Apache License 2.0 | 4 votes |
/** * @return A stream of the {@link ChunkPos} of every chunk inside of this claim. */ public Stream<ChunkPos> stream() { return Streams.stream(new ChunkPosIterator()); }
Example 16
Source File: GuavaStreamsUnitTest.java From tutorials with MIT License | 3 votes |
@Test public void createStreamsWithOptionalDouble() { DoubleStream streamFromOptionalDouble = Streams.stream(OptionalDouble.of(1.0)); //Assert.assertNotNull(streamFromOptionalDouble); assertEquals(streamFromOptionalDouble.count(), 1); }
Example 17
Source File: Table.java From tablesaw with Apache License 2.0 | 2 votes |
/** * Streams over stepped sets of rows. I.e. 0 to n-1, n to 2n-1, 2n to 3n-1, etc. Only returns full * sets of rows. * * @param n the number of rows to return for each iteration */ public Stream<Row[]> steppingStream(int n) { return Streams.stream(steppingIterator(n)); }
Example 18
Source File: Table.java From tablesaw with Apache License 2.0 | 2 votes |
/** * Streams over rolling sets of rows. I.e. 0 to n-1, 1 to n, 2 to n+1, etc. * * @param n the number of rows to return for each iteration */ public Stream<Row[]> rollingStream(int n) { return Streams.stream(rollingIterator(n)); }
Example 19
Source File: Table.java From tablesaw with Apache License 2.0 | 2 votes |
/** * Streams over rolling sets of rows. I.e. 0 to n-1, 1 to n, 2 to n+1, etc. * * @param n the number of rows to return for each iteration */ public Stream<Row[]> rollingStream(int n) { return Streams.stream(rollingIterator(n)); }
Example 20
Source File: TrieNodeDecoder.java From besu with Apache License 2.0 | 2 votes |
/** * Walks the trie in a bread-first manner, returning the list of nodes encountered in order. If * any nodes are missing from the nodeLoader, those nodes are just skipped. * * @param nodeLoader The NodeLoader for looking up nodes by hash * @param rootHash The hash of the root node * @param maxDepth The maximum depth to traverse to. A value of zero will traverse the root node * only. * @return A stream non-null nodes in the breadth-first traversal order. */ public static Stream<Node<Bytes>> breadthFirstDecoder( final NodeLoader nodeLoader, final Bytes32 rootHash, final int maxDepth) { checkArgument(maxDepth >= 0); return Streams.stream(new BreadthFirstIterator(nodeLoader, rootHash, maxDepth)); }