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

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

Introduction

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

Prototype

default Stream<E> stream() 

Source Link

Document

Returns a sequential Stream with this collection as its source.

Usage

From source file:com.facebook.buck.core.cell.UnknownCellException.java

private static final ImmutableList<String> generateSuggestions(Optional<String> cellName,
        ImmutableSet<String> validCellNames) {
    if (!cellName.isPresent()) {
        return ImmutableList.of();
    }/* w  ww .j ava  2 s .  c  o  m*/

    List<String> suggestions = MoreStrings.getSpellingSuggestions(cellName.get(), validCellNames, 2);

    if (!suggestions.isEmpty()) {
        return ImmutableList.copyOf(suggestions);
    }

    return validCellNames.stream().sorted().collect(ImmutableList.toImmutableList());
}

From source file:ai.grakn.graql.Autocomplete.java

/**
 * @param types the graph to find types in
 * @param query a graql query//  w  w  w .ja  va  2s . co  m
 * @param optToken the token the cursor is on in the query
 * @return a set of potential autocomplete words
 */
private static ImmutableSet<String> findCandidates(Set<String> types, String query,
        Optional<? extends Token> optToken) {
    ImmutableSet<String> allCandidates = Stream.of(GRAQL_KEYWORDS.stream(), types.stream(), getVariables(query))
            .flatMap(Function.identity()).collect(toImmutableSet());

    return optToken.map(token -> {
        ImmutableSet<String> candidates = allCandidates.stream()
                .filter(candidate -> candidate.startsWith(token.getText())).collect(toImmutableSet());

        if (candidates.size() == 1 && candidates.iterator().next().equals(token.getText())) {
            return ImmutableSet.of(" ");
        } else {
            return candidates;
        }
    }).orElse(allCandidates);
}

From source file:com.spectralogic.ds3contractcomparator.Ds3ApiSpecComparatorImpl.java

/**
 * Compares two {@link ImmutableList} of {@link Ds3Request}
 * @param oldRequests List of {@link Ds3Request} from the older API
 * @param newRequests List of {@link Ds3Request} from the newer API
 *//*from  w  w  w .j a v  a2 s .  co m*/
static ImmutableList<AbstractDs3RequestDiff> compareDs3Requests(final ImmutableList<Ds3Request> oldRequests,
        final ImmutableList<Ds3Request> newRequests) {
    final ImmutableSet<String> requestNames = getRequestNameUnion(oldRequests, newRequests);
    final ImmutableMap<String, Ds3Request> oldMap = toRequestMap(oldRequests);
    final ImmutableMap<String, Ds3Request> newMap = toRequestMap(newRequests);

    final Ds3RequestComparator comparator = new Ds3RequestComparatorImpl();
    return requestNames.stream().map(name -> comparator.compare(oldMap.get(name), newMap.get(name)))
            .collect(GuavaCollectors.immutableList());
}

From source file:com.spectralogic.ds3contractcomparator.print.simpleprinter.Ds3ElementDiffSimplePrinter.java

/**
 * Prints the changes between two {@link ImmutableList} of {@link Ds3Annotation}. If both lists are
 * empty, then nothing is printed./*w  w w .j a  va2s. c  om*/
 */
private static void printAnnotations(final ImmutableList<Ds3Annotation> oldAnnotations,
        final ImmutableList<Ds3Annotation> newAnnotations, final WriterHelper writer,
        final boolean printAllAnnotations) {
    if (isEmpty(oldAnnotations) && isEmpty(newAnnotations)) {
        //do not print empty values
        return;
    }
    writer.append(indent(INDENT + 1)).append("Annotations:").append("\n");

    final ImmutableSet<String> annotationNames = getAnnotationNameUnion(oldAnnotations, newAnnotations);
    final ImmutableMap<String, Ds3Annotation> oldParamMap = toAnnotationMap(oldAnnotations);
    final ImmutableMap<String, Ds3Annotation> newParamMap = toAnnotationMap(newAnnotations);

    annotationNames.stream()
            .filter((annotationName) -> shouldPrintAnnotation(annotationName, printAllAnnotations))
            .forEach(name -> printAnnotationDiff(oldParamMap.get(name), newParamMap.get(name), writer));
}

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

/**
 * Make sure that if any srcs elements are a build rule, we add it as a dependency, so we wait for
 * it to finish running before using the source
 *//*from w w w  . j av a 2 s . co  m*/
private static ImmutableList<BuildRule> getDependenciesFromSources(SourcePathRuleFinder ruleFinder,
        ImmutableSet<SourcePath> srcs) {
    return srcs.stream().map(ruleFinder::getRule).filter(Optional::isPresent).map(Optional::get)
            .collect(ImmutableList.toImmutableList());
}

From source file:com.facebook.buck.ide.intellij.IjProjectTemplateDataPreparer.java

public static ImmutableSet<Path> createFilesystemTraversalBoundaryPathSet(ImmutableSet<IjModule> modules) {
    return Stream.concat(modules.stream().map(IjModule::getModuleBasePath),
            Stream.of(IjProjectPaths.IDEA_CONFIG_DIR)).collect(MoreCollectors.toImmutableSet());
}

From source file:com.opengamma.collect.result.Failure.java

/**
 * Obtains a failure for a non-empty set of failure items.
 * /* w w  w . j  ava2s.  c  om*/
 * @param items  the failures, not empty
 * @return the failure
 */
static Failure of(ImmutableSet<FailureItem> items) {
    ArgChecker.notEmpty(items, "items");
    String message = items.stream().map(FailureItem::getMessage).collect(Collectors.joining(", "));
    FailureReason reason = items.stream().map(FailureItem::getReason)
            .reduce((s1, s2) -> s1 == s2 ? s1 : FailureReason.MULTIPLE).get();
    return new Failure(reason, message, items);
}

From source file:com.facebook.buck.jvm.java.intellij.IjProjectTemplateDataPreparer.java

public static ImmutableSet<Path> createFilesystemTraversalBoundaryPathSet(ImmutableSet<IjModule> modules) {
    return Stream.concat(modules.stream().map(IjModule::getModuleBasePath),
            Stream.of(IjProjectWriter.IDEA_CONFIG_DIR_PREFIX)).collect(MoreCollectors.toImmutableSet());
}

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

private static SymlinkTree makeSymlinkTree(BuildTarget buildTarget, ProjectFilesystem projectFilesystem,
        SourcePathRuleFinder ruleFinder, SourcePathResolver pathResolver, ImmutableSet<GoLinkable> linkables) {

    ImmutableMap<Path, SourcePath> treeMap;
    try {/*  w ww  .j a va  2 s .com*/
        treeMap = linkables.stream().flatMap(linkable -> linkable.getGoLinkInput().entrySet().stream())
                .collect(ImmutableMap.toImmutableMap(
                        entry -> getPathInSymlinkTree(pathResolver, entry.getKey(), entry.getValue()),
                        entry -> entry.getValue()));
    } catch (IllegalArgumentException ex) {
        throw new HumanReadableException(ex, "Multiple go targets have the same package name when compiling %s",
                buildTarget.getFullyQualifiedName());
    }

    Path root = BuildTargetPaths.getScratchPath(projectFilesystem, buildTarget, "__%s__tree");

    return new SymlinkTree("go_linkable", buildTarget, projectFilesystem, root, treeMap, ImmutableMultimap.of(),
            ruleFinder);
}

From source file:com.facebook.buck.jvm.java.intellij.IjModuleFactory.java

/**
 * Calculate the set of directories containing inputs to the target.
 *
 * @param paths inputs to a given target.
 * @return index of path to set of inputs in that path
 *//* www.j av  a2  s.  c o m*/
private static ImmutableMultimap<Path, Path> getSourceFoldersToInputsIndex(ImmutableSet<Path> paths) {
    Path defaultParent = Paths.get("");
    return paths.stream().collect(MoreCollectors.toImmutableMultimap(path -> {
        Path parent = path.getParent();
        return parent == null ? defaultParent : parent;
    }, path -> path));
}