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.linecorp.armeria.server.docs.ServiceSpecification.java

/**
 * Creates a new instance./* w ww  .  j  av  a2  s .c om*/
 */
public ServiceSpecification(Iterable<ServiceInfo> services, Iterable<ClassInfo> classes) {
    this.services = Streams.stream(requireNonNull(services, "services"))
            .collect(toImmutableSortedMap(Comparator.naturalOrder(), ServiceInfo::name, Function.identity()));
    this.classes = Streams.stream(requireNonNull(classes, "classes"))
            .collect(toImmutableSortedMap(Comparator.naturalOrder(), ClassInfo::name, Function.identity()));
}

From source file:com.linecorp.armeria.server.docs.EndpointInfo.java

/**
 * Creates a new instance.//  w  ww .j  a  v  a2s .  c  om
 */
public EndpointInfo(String hostnamePattern, String path, String fragment, SerializationFormat defaultFormat,
        Iterable<SerializationFormat> availableFormats) {

    this.hostnamePattern = requireNonNull(hostnamePattern, "hostnamePattern");
    this.path = requireNonNull(path, "path");
    this.fragment = requireNonNull(fragment, "fragment");
    defaultMimeType = requireNonNull(defaultFormat, "defaultFormat").mediaType().toString();

    availableMimeTypes = Streams.stream(availableFormats).map(SerializationFormat::mediaType)
            .map(Object::toString).collect(toImmutableSortedSet(Comparator.naturalOrder()));
}

From source file:com.linecorp.armeria.server.docs.ServiceInfo.java

/**
 * Creates a new instance.// ww w.j a  va2  s .c o m
 */
public ServiceInfo(String name, Iterable<FunctionInfo> functions, Iterable<ClassInfo> classes,
        Iterable<EndpointInfo> endpoints, @Nullable String docString, @Nullable String sampleHttpHeaders) {

    this.name = requireNonNull(name, "name");

    requireNonNull(functions, "functions");
    requireNonNull(classes, "classes");
    requireNonNull(endpoints, "endpoints");

    this.functions = Streams.stream(functions)
            .collect(toImmutableSortedMap(Comparator.naturalOrder(), FunctionInfo::name, Function.identity()));
    this.classes = Streams.stream(classes)
            .collect(toImmutableSortedMap(Comparator.naturalOrder(), ClassInfo::name, Function.identity()));
    this.endpoints = Streams.stream(endpoints).collect(toImmutableSortedMap(Comparator.naturalOrder(),
            e -> e.hostnamePattern() + ':' + e.path(), Function.identity()));
    this.docString = docString;
    this.sampleHttpHeaders = sampleHttpHeaders;
}

From source file:com.google.devtools.build.lib.rules.java.JavaPackageConfigurationProvider.java

/**
 * Returns true if this configuration matches the current label: that is, if the label's package
 * is contained by any of the {@link #packageSpecifications}.
 *//*www . ja  va 2s. c om*/
public boolean matches(Label label) {
    return packageSpecifications().stream().flatMap(p -> Streams.stream(p.getPackageSpecifications()))
            .anyMatch(p -> p.containsPackage(label.getPackageIdentifier()));
}

From source file:com.linecorp.armeria.common.util.AbstractOptions.java

/**
 * Creates a new instance.//from   w w w.ja  v a 2s .c  om
 *
 * @param <T> the type of the {@link AbstractOptionValue}
 * @param valueFilter the {@link Function} to apply to the elements of the specified {@code values}
 * @param values the option values
 */
protected <T extends AbstractOptionValue<?, ?>> AbstractOptions(Function<T, T> valueFilter,
        Iterable<T> values) {
    requireNonNull(valueFilter, "valueFilter");
    requireNonNull(values, "values");

    valueMap = new IdentityHashMap<>();
    putAll(valueFilter, Streams.stream(values));
}

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

@Override
public Description matchClass(ClassTree tree, VisitorState state) {
    ClassSymbol origin = getSymbol(tree);
    Types types = state.getTypes();
    Iterable<Symbol> members = types.membersClosure(getType(tree), /*skipInterface=*/ false).getSymbols();

    // collect declared and inherited methods, grouped by reference descriptor
    Map<String, List<MethodSymbol>> methods = Streams.stream(members).filter(MethodSymbol.class::isInstance)
            .map(MethodSymbol.class::cast).filter(m -> m.isConstructor() || m.owner.equals(origin))
            .collect(groupingBy(m -> methodReferenceDescriptor(types, m), toCollection(ArrayList::new)));

    // look for groups of ambiguous method references
    for (Tree member : tree.getMembers()) {
        if (!(member instanceof MethodTree)) {
            continue;
        }/*from ww  w.  j  a v a 2s. co m*/
        MethodSymbol msym = getSymbol((MethodTree) member);
        if (isSuppressed(msym)) {
            continue;
        }
        List<MethodSymbol> clash = methods.remove(methodReferenceDescriptor(types, msym));
        if (clash == null) {
            continue;
        }
        // If the clashing group has 1 or 0 non-private methods, method references outside the file
        // are unambiguous.
        int nonPrivateMethodCount = 0;
        for (MethodSymbol method : clash) {
            if (!method.isPrivate()) {
                nonPrivateMethodCount++;
            }
        }
        if (nonPrivateMethodCount < 2) {
            continue;
        }
        clash.remove(msym);
        // ignore overridden inherited methods and hidden interface methods
        clash.removeIf(m -> types.isSubSignature(msym.type, m.type));
        if (clash.isEmpty()) {
            continue;
        }
        String message = String.format(
                "This method's reference is ambiguous, its name and functional interface type"
                        + " are the same as: %s",
                clash.stream().map(m -> Signatures.prettyMethodSignature(origin, m)).collect(joining(", ")));
        state.reportMatch(buildDescription(member).setMessage(message).build());
    }
    return NO_MATCH;
}

From source file:com.facebook.buck.features.go.GoTestMainStep.java

@Override
protected ImmutableList<String> getShellCommandInternal(ExecutionContext context) {
    ImmutableList.Builder<String> command = ImmutableList.<String>builder().addAll(generatorCommandPrefix)
            .add("--output", output.toString()).add("--import-path", packageName.toString())
            .add("--cover-mode", coverageMode.getMode());

    Set<Path> filteredFileNames = Streams.stream(testFiles).map(Path::getFileName).collect(Collectors.toSet());
    for (Map.Entry<Path, ImmutableMap<String, Path>> pkg : coverageVariables.entrySet()) {
        if (pkg.getValue().isEmpty()) {
            continue;
        }/*from   ww  w . j a  v a  2  s.c o m*/

        StringBuilder pkgFlag = new StringBuilder();
        pkgFlag.append(pkg.getKey());
        pkgFlag.append(':');

        boolean first = true;
        for (Map.Entry<String, Path> pkgVars : pkg.getValue().entrySet()) {
            if (filteredFileNames.contains(pkgVars.getValue())) {
                if (!first) {
                    pkgFlag.append(',');
                }
                first = false;
                pkgFlag.append(pkgVars.getKey());
                pkgFlag.append('=');
                pkgFlag.append(pkgVars.getValue());
            }
        }

        command.add("--cover-pkgs", pkgFlag.toString());
    }

    for (Path source : testFiles) {
        command.add(source.toString());
    }

    return command.build();
}

From source file:org.lenskit.util.io.AbstractObjectStream.java

private Stream<T> stream() {
    if (stream == null) {
        stream = Streams.stream(iterator());
    }
    return stream;
}

From source file:de.learnlib.oracle.equivalence.IncrementalWMethodEQOracle.java

@Override
protected Stream<Word<I>> generateTestWords(A hypothesis, Collection<? extends I> inputs) {
    // FIXME: warn about inputs being ignored?
    incrementalWMethodIt.update(hypothesis);

    return Streams.stream(incrementalWMethodIt);
}

From source file:de.learnlib.oracle.equivalence.WpMethodEQOracle.java

@Override
protected Stream<Word<I>> generateTestWords(A hypothesis, Collection<? extends I> inputs) {
    return Streams.stream(new WpMethodTestsIterator<>(hypothesis, inputs, maxDepth));
}