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

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

Introduction

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

Prototype

default Stream<E> stream() 

Source Link

Document

Returns a sequential Stream with this collection as its source.

Usage

From source file:com.spectralogic.ds3autogen.python.generators.request.BaseRequestGenerator.java

/**
 * Creates python documentation for the request constructor
 * @param requestName The normalized request name without path
 *//*from w w w .  ja  va2 s .  c o m*/
protected static String toDocumentation(final String requestName, final ImmutableList<String> constructorParams,
        final Ds3DocSpec docSpec) {
    if (isEmpty(constructorParams)) {
        return "";
    }
    final ImmutableList<String> normalizedParams = constructorParams.stream().map(i -> i.replace("=None", ""))
            .collect(GuavaCollectors.immutableList());
    return toConstructorDocs(requestName, normalizedParams, docSpec, 1);
}

From source file:com.spectralogic.ds3autogen.net.generators.clientmodels.BaseClientGenerator.java

/**
 * Gets the value of the HttpStatusCode associated with the void response type.
 * code > 300: empty string (error)//  w  ww.  j av a  2s  .c  o  m
 * code == 204: HttpStatusCode.NoContent
 * Else: HttpStatusCode.OK
 */
protected static String getHttpStatusCode(final ImmutableList<Ds3ResponseCode> responseCodes) {
    if (isEmpty(responseCodes)) {
        LOG.error("There are no response codes");
        return "";
    }
    final ImmutableList<Integer> codes = responseCodes.stream()
            .filter(responseCode -> ResponsePayloadUtil.isNonErrorCode(responseCode.getCode()))
            .map(Ds3ResponseCode::getCode).collect(GuavaCollectors.immutableList());
    if (isEmpty(codes)) {
        LOG.error("There are no non-error response codes within the list: " + codes.toString());
        return "";
    }
    if (codes.contains(204)) {
        return "NoContent";
    }
    return "OK";
}

From source file:com.google.javascript.jscomp.Promises.java

/**
 * Synthesizes a type representing the legal types of a return expression within async code
 * (i.e.`Promise` callbacks, async functions) based on the expected return type of that code.
 *
 * <p>The return type will generally be a union but may not be in the case of top-like types. If
 * the expected return type is a union, any synchronous elements will be dropped, since they can
 * never occur. For example:/* w  ww  .j a va2  s . c o  m*/
 *
 * <ul>
 *   <li>`!Promise<number>` => `number|!IThenable<number>`
 *   <li>`number` => `?`
 *   <li>`number|!Promise<string>` => `string|!IThenable<string>`
 *   <li>`!IThenable<number>|!Promise<string>` => `number|string|!IThenable<number|string>`
 *   <li>`!IThenable<number|string>` => `number|string|!IThenable<number|string>`
 *   <li>`?` => `?`
 *   <li>`*` => `?`
 * </ul>
 */
static final JSType createAsyncReturnableType(JSTypeRegistry registry, JSType maybeThenable) {
    JSType unknownType = registry.getNativeType(JSTypeNative.UNKNOWN_TYPE);
    ObjectType iThenableType = registry.getNativeObjectType(JSTypeNative.I_THENABLE_TYPE);

    JSType iThenableOfUnknownType = registry.createTemplatizedType(iThenableType, unknownType);

    ImmutableList<JSType> alternates = maybeThenable.isUnionType()
            ? maybeThenable.toMaybeUnionType().getAlternates()
            : ImmutableList.of(maybeThenable);
    ImmutableList<JSType> asyncTemplateAlternates = alternates.stream()
            .filter((t) -> t.isSubtypeOf(iThenableOfUnknownType)) // Discard "synchronous" types.
            .map((t) -> getTemplateTypeOfThenable(registry, t)) // Unwrap "asynchronous" types.
            .collect(toImmutableList());

    if (asyncTemplateAlternates.isEmpty()) {
        return unknownType;
    }

    JSType asyncTemplateUnion = registry.createUnionType(asyncTemplateAlternates);
    return registry.createUnionType(asyncTemplateUnion,
            registry.createTemplatizedType(iThenableType, asyncTemplateUnion));
}

From source file:grakn.core.graql.reasoner.plan.GraqlTraversalPlanner.java

/**
 *
 * @param atoms list of current atoms of interest
 * @param queryPattern corresponding pattern
 * @return an optimally ordered list of provided atoms
 *///from   ww  w.ja  va 2s  . com
private static ImmutableList<Atom> planFromTraversal(List<Atom> atoms, Conjunction<?> queryPattern,
        TransactionOLTP tx) {
    Multimap<VarProperty, Atom> propertyMap = HashMultimap.create();
    atoms.stream().filter(atom -> !(atom instanceof OntologicalAtom))
            .forEach(atom -> atom.getVarProperties().forEach(property -> propertyMap.put(property, atom)));
    Set<VarProperty> properties = propertyMap.keySet();

    GraqlTraversal graqlTraversal = TraversalPlanner.createTraversal(queryPattern, tx);
    ImmutableList<Fragment> fragments = Iterables.getOnlyElement(graqlTraversal.fragments());

    List<Atom> atomList = new ArrayList<>();

    atoms.stream().filter(atom -> atom instanceof OntologicalAtom).forEach(atomList::add);

    fragments.stream().map(Fragment::varProperty).filter(Objects::nonNull).filter(properties::contains)
            .distinct().flatMap(property -> propertyMap.get(property).stream()).distinct()
            .forEach(atomList::add);

    //add any unlinked items (disconnected and indexed for instance)
    propertyMap.values().stream().filter(at -> !atomList.contains(at)).forEach(atomList::add);
    return ImmutableList.copyOf(atomList);
}

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

private static String suggestedNameFollowedWithT(String identifier) {
    Preconditions.checkArgument(!identifier.isEmpty());

    // Some early checks:
    // TFoo => FooT
    if (identifier.length() > 2 && identifier.charAt(0) == 'T' && Ascii.isUpperCase(identifier.charAt(1))
            && Ascii.isLowerCase(identifier.charAt(2))) {
        // splitToLowercaseTerms thinks "TFooBar" is ["tfoo", "bar"], so we remove "t", have it parse
        // as ["foo", "bar"], then staple "t" back on the end.
        ImmutableList<String> tokens = NamingConventions.splitToLowercaseTerms(identifier.substring(1));
        return Streams.concat(tokens.stream(), Stream.of("T")).map(TypeParameterNaming::upperCamelToken)
                .collect(Collectors.joining());
    }// w  w w.  j ava2 s.c  om

    ImmutableList<String> tokens = NamingConventions.splitToLowercaseTerms(identifier);

    // UPPERCASE => UppercaseT
    if (tokens.size() == 1) {
        String token = tokens.get(0);
        if (Ascii.toUpperCase(token).equals(identifier)) {
            return upperCamelToken(token) + "T";
        }
    }

    // FooType => FooT
    if (Iterables.getLast(tokens).equals("type")) {
        return Streams.concat(tokens.subList(0, tokens.size() - 1).stream(), Stream.of("T"))
                .map(TypeParameterNaming::upperCamelToken).collect(Collectors.joining());
    }

    return identifier + "T";
}

From source file:com.spectralogic.ds3autogen.net.generators.clientmodels.BaseClientGenerator.java

/**
 * Retrieves a list of Ds3Requests that either have no payload, or which have payload, based
 * on hasPayload parameter.//  w  ww  . ja  va2 s.  co  m
 */
protected static ImmutableList<Ds3Request> getRequestsBasedOnResponsePayload(
        final ImmutableList<Ds3Request> ds3Requests, final boolean hasPayload) {
    if (isEmpty(ds3Requests)) {
        LOG.debug("There were no Ds3Requests to generate the client");
        return ImmutableList.of();
    }
    return ds3Requests.stream().filter(request -> requestPayloadStatus(request, hasPayload))
            .collect(GuavaCollectors.immutableList());
}

From source file:com.spectralogic.ds3autogen.python.PythonCodeGenerator.java

/**
 * Generates the python models for the client commands
 *//*  w w w  . j  a v a2 s. com*/
protected static ImmutableList<BaseClient> toClientCommands(final ImmutableList<Ds3Request> ds3Requests,
        final Ds3DocSpec docSpec) {
    if (isEmpty(ds3Requests)) {
        return ImmutableList.of();
    }
    return ds3Requests.stream().map(request -> toClientCommand(request, docSpec))
            .collect(GuavaCollectors.immutableList());
}

From source file:com.spectralogic.ds3autogen.python.PythonCodeGenerator.java

/**
 * Converts all Ds3Requests into the python request handler models
 *//* w w w . j  a  va  2 s  .  com*/
protected static ImmutableList<BaseRequest> toRequestModelList(final ImmutableList<Ds3Request> ds3Requests,
        final Ds3DocSpec docSpec) {
    if (isEmpty(ds3Requests)) {
        return ImmutableList.of();
    }
    return ds3Requests.stream().map(request -> toRequestModel(request, docSpec))
            .collect(GuavaCollectors.immutableList());
}

From source file:com.spectralogic.ds3autogen.java.helpers.JavaHelper.java

/**
 * Removes a specified variable from a list of variables
 *///  w  w  w.  ja va  2s  .c om
public static ImmutableList<Variable> removeVariable(final ImmutableList<Variable> vars, final String varName) {
    if (isEmpty(vars)) {
        return ImmutableList.of();
    }
    return vars.stream().filter(var -> !var.getName().equals(varName)).collect(GuavaCollectors.immutableList());
}

From source file:com.facebook.buck.cxx.toolchain.nativelink.NativeLinkables.java

/** @return the nodes found from traversing the given roots in topologically sorted order. */
public static ImmutableList<NativeLinkable> getTopoSortedNativeLinkables(
        Iterable<? extends NativeLinkable> roots,
        Function<? super NativeLinkable, Stream<? extends NativeLinkable>> depsFn) {

    Map<BuildTarget, NativeLinkable> nativeLinkables = new HashMap<>();
    for (NativeLinkable nativeLinkable : roots) {
        nativeLinkables.put(nativeLinkable.getBuildTarget(), nativeLinkable);
    }//  w  w w .ja  va 2s  . c o  m

    MutableDirectedGraph<BuildTarget> graph = new MutableDirectedGraph<>();
    AbstractBreadthFirstTraversal<BuildTarget> visitor = new AbstractBreadthFirstTraversal<BuildTarget>(
            nativeLinkables.keySet()) {
        @Override
        public ImmutableSet<BuildTarget> visit(BuildTarget target) {
            NativeLinkable nativeLinkable = Objects.requireNonNull(nativeLinkables.get(target));
            graph.addNode(target);

            // Process all the traversable deps.
            ImmutableSet.Builder<BuildTarget> deps = ImmutableSet.builder();
            depsFn.apply(nativeLinkable).forEach(dep -> {
                BuildTarget depTarget = dep.getBuildTarget();
                graph.addEdge(target, depTarget);
                deps.add(depTarget);
                nativeLinkables.put(depTarget, dep);
            });
            return deps.build();
        }
    };
    visitor.start();

    // Topologically sort the rules.
    ImmutableList<BuildTarget> ordered = TopologicalSort.sort(graph).reverse();
    return ordered.stream().map(nativeLinkables::get).collect(ImmutableList.toImmutableList());
}