Example usage for com.google.common.collect Streams stream

List of usage examples for com.google.common.collect Streams stream

Introduction

In this page you can find the example usage for com.google.common.collect Streams stream.

Prototype

public static DoubleStream stream(OptionalDouble optional) 

Source Link

Document

If a value is present in optional , returns a stream containing only that element, otherwise returns an empty stream.

Usage

From source file:com.google.cloud.runtimes.tomcat.session.DatastoreStore.java

/**
 * Returns an array containing the session identifiers of all Sessions currently saved in this
 * Store. If there are no such Sessions, a zero-length array is returned.
 *
 * <p>This operation may be slow if a large number of sessions is persisted.
 * Note that the number of keys returned may be bounded by the Datastore configuration.</p>
 *
 * @return The ids of all persisted sessions
 *//*from w ww . j a  v  a 2s.  c  o  m*/
@Override
public String[] keys() throws IOException {
    String[] keys;

    Query<Key> query = Query.newKeyQueryBuilder().build();
    QueryResults<Key> results = datastore.run(query);
    keys = Streams.stream(results).map(key -> key.getNameOrId().toString()).toArray(String[]::new);

    if (keys == null) {
        keys = new String[0];
    }

    return keys;
}

From source file:org.lanternpowered.server.fluid.LanternFluidStackSnapshot.java

@Override
public Optional<FluidStackSnapshot> with(Iterable<ImmutableDataManipulator<?, ?>> valueContainers) {
    final LanternFluidStack copy = this.fluidStack.copy();
    if (copy.offerFast(Streams.stream(valueContainers).map(ImmutableDataManipulator::asMutable)
            .collect(Collectors.toList()))) {
        return Optional.of(new LanternFluidStackSnapshot(copy));
    }/* w  w w. ja  v  a 2  s  .c  o m*/
    return Optional.empty();
}

From source file:ec.tss.tsproviders.utils.UriBuilder.java

@Nullable
private static String[] splitToArray(@Nonnull CharSequence input) {
    return Streams.stream(PATH_SPLITTER.split(input)).map(UriBuilder::decodeUrlUtf8).toArray(String[]::new);
}

From source file:com.google.errorprone.bugpatterns.UnsafeFinalization.java

private static Stream<VarSymbol> getFields(TypeSymbol s) {
    return Streams.stream(s.members().getSymbols(m -> m.getKind() == ElementKind.FIELD))
            .map(VarSymbol.class::cast);
}

From source file:com.google.devtools.build.lib.skyframe.ActionFileSystem.java

ActionFileSystem(FileSystem delegate, Path execRoot, ImmutableList<Root> sourceRoots,
        InputArtifactData inputArtifactData, Iterable<Artifact> allowedInputs,
        Iterable<Artifact> outputArtifacts) {
    try {/*  w  w w. j a v a 2s  .  c  om*/
        Profiler.instance().startTask(ProfilerTask.ACTION_FS_STAGING, "staging");
        this.delegate = delegate;

        this.execRootFragment = execRoot.asFragment();
        this.execRootPath = getPath(execRootFragment);
        this.sourceRoots = sourceRoots.stream().map(root -> root.asPath().asFragment())
                .collect(ImmutableList.toImmutableList());

        validateRoots();

        this.inputArtifactData = inputArtifactData;

        this.optionalInputs = new HashMap<>();
        for (Artifact input : allowedInputs) {
            // Skips staging source artifacts as a performance optimization. We may want to stage them
            // if we want stricter enforcement of source sandboxing.
            //
            // TODO(shahan): there are no currently known cases where metadata is requested for an
            // optional source input. If there are any, we may want to stage those.
            if (input.isSourceArtifact() || inputArtifactData.contains(input)) {
                continue;
            }
            optionalInputs.computeIfAbsent(input.getExecPath(), unused -> new OptionalInputMetadata(input));
        }

        this.optionalInputsByDigest = new ConcurrentHashMap<>();

        this.outputs = Streams.stream(outputArtifacts)
                .collect(ImmutableMap.toImmutableMap(a -> a.getExecPath(), a -> new OutputMetadata(a)));
    } finally {
        Profiler.instance().completeTask(ProfilerTask.ACTION_FS_STAGING);
    }
}

From source file:org.lanternpowered.server.inventory.LanternItemStackSnapshot.java

@Override
public Optional<ItemStackSnapshot> with(Iterable<ImmutableDataManipulator<?, ?>> valueContainers) {
    final LanternItemStack copy = this.itemStack.copy();
    if (copy.offerFast(Streams.stream(valueContainers).map(ImmutableDataManipulator::asMutable)
            .collect(Collectors.toList()))) {
        return Optional.of(new LanternItemStackSnapshot(copy));
    }// w w w  . jav a2  s . c  o  m
    return Optional.empty();
}

From source file:com.google.errorprone.bugpatterns.TypeNameShadowing.java

/** Iterate through a list of type parameters, looking for type names shadowed by any of them. */
private Description findShadowedTypes(Tree tree, List<? extends TypeParameterTree> typeParameters,
        VisitorState state) {/* w w w.  j a v a2  s.  co m*/

    Env<AttrContext> env = Enter.instance(state.context)
            .getEnv(ASTHelpers.getSymbol(state.findEnclosing(ClassTree.class)));

    Symtab symtab = state.getSymtab();
    PackageSymbol javaLang = symtab.enterPackage(symtab.java_base, Names.instance(state.context).java_lang);

    Iterable<Symbol> enclosingTypes = typesInEnclosingScope(env, javaLang);

    List<Symbol> shadowedTypes = typeParameters.stream()
            .map(param -> Iterables
                    .tryFind(enclosingTypes,
                            sym -> sym.getSimpleName().equals(ASTHelpers.getType(param).tsym.getSimpleName()))
                    .orNull())
            .filter(Objects::nonNull).collect(ImmutableList.toImmutableList());

    if (shadowedTypes.isEmpty()) {
        return Description.NO_MATCH;
    }

    Description.Builder descBuilder = buildDescription(tree);

    descBuilder.setMessage(buildMessage(shadowedTypes));

    Set<String> visibleNames = Streams.stream(Iterables.concat(env.info.getLocalElements(), enclosingTypes))
            .map(sym -> sym.getSimpleName().toString()).collect(ImmutableSet.toImmutableSet());

    SuggestedFix.Builder fixBuilder = SuggestedFix.builder();
    shadowedTypes.stream()
            .filter(tv -> TypeParameterNamingClassification.classify(tv.name.toString()).isValidName())
            .map(tv -> TypeParameterShadowing.renameTypeVariable(
                    TypeParameterShadowing.typeParameterInList(typeParameters, tv), tree,
                    TypeParameterShadowing.replacementTypeVarName(tv.name, visibleNames), state))
            .forEach(fixBuilder::merge);

    descBuilder.addFix(fixBuilder.build());
    return descBuilder.build();
}

From source file:io.prestosql.plugin.jmx.JmxMetadata.java

private String toPattern(String tableName) throws MalformedObjectNameException {
    if (!tableName.contains("*")) {
        return Pattern.quote(new ObjectName(tableName).getCanonicalName());
    }//  w ww .jav  a  2s.  c o m
    return Streams.stream(Splitter.on('*').split(tableName)).map(Pattern::quote)
            .collect(Collectors.joining(".*"));
}

From source file:com.google.devtools.build.lib.query2.ParallelVisitor.java

void visitAndWaitForCompletion(Iterable<SkyKey> keys) throws QueryException, InterruptedException {
    Streams.stream(preprocessInitialVisit(keys)).forEachOrdered(processingQueue::add);
    executor.visitAndWaitForCompletion();
}

From source file:com.facebook.buck.rules.coercer.StringWithMacrosTypeCoercer.java

@Override
public StringWithMacros concat(Iterable<StringWithMacros> elements) {
    Stream<Either<String, MacroContainer>> parts = Streams.stream(elements).map(StringWithMacros::getParts)
            .flatMap(List::stream);

    return StringWithMacros.of(mergeStringParts(parts));
}