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:de.se_rwth.langeditor.util.antlr.Formatting.java

public static void insertLineBreaks(TokenStreamRewriter rewriter,
        ImmutableSet<? extends ParseTree> precedingSections) {
    precedingSections.stream().map(ParseTrees::getLastToken).filter(Optional::isPresent).map(Optional::get)
            .forEach(token -> rewriter.insertAfter(token, "\n"));
}

From source file:de.se_rwth.langeditor.util.antlr.Formatting.java

public static void indent(TokenStreamRewriter rewriter, ImmutableSet<? extends ParseTree> succeedingSections,
        String indentation) {//from  w w  w  .  j  a  v  a  2 s . c  om
    succeedingSections.stream().map(ParseTrees::getFirstToken).filter(Optional::isPresent).map(Optional::get)
            .forEach(token -> rewriter.insertBefore(token, indentation));
}

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

private static Predicate<String> areAllReturnStatementsAssignable(
        ImmutableSet<ClassType> returnStatementsTypes) {
    return s -> returnStatementsTypes.stream().map(MutableMethodReturnType::getImmutableSuperTypesForClassType)
            .allMatch(c -> c.contains(s));
}

From source file:com.jeffreybosboom.lyne.Effector.java

public static Pair<Puzzle, ImmutableMap<Node, Region.Point>> parseImage(BufferedImage image) {
    ImmutableSet<Region> regions = Region.connectedComponents(image, Colors.LYNE_COLORS);
    List<Region> nodeRegions = regions.stream().filter(r -> Colors.NODE_COLORS.keySet().contains(r.color()))
            .collect(Collectors.toList());
    //terminal markers and pips are inside node regions, so must be smaller
    int maxSize = nodeRegions.stream().mapToInt(r -> r.points().size()).max().getAsInt();
    List<Region> terminalRegions = regions.stream().filter(r -> r.points().size() < maxSize)
            .filter(r -> r.color() == Colors.TERMINAL_CENTER).collect(Collectors.toList());
    List<Region> pipRegions = regions.stream().filter(r -> r.points().size() < maxSize)
            .filter(r -> r.color() == Colors.PIP).collect(Collectors.toList());

    RangeSet<Integer> rowRanges = TreeRangeSet.create();
    nodeRegions.stream().map(Region::centroid).mapToInt(Region.Point::y)
            .mapToObj(i -> Range.closed(i - TOLERANCE, i + TOLERANCE)).forEachOrdered(rowRanges::add);
    List<Range<Integer>> rows = rowRanges.asRanges().stream().collect(Collectors.toList());
    RangeSet<Integer> colRanges = TreeRangeSet.create();
    nodeRegions.stream().map(Region::centroid).mapToInt(Region.Point::x)
            .mapToObj(i -> Range.closed(i - TOLERANCE, i + TOLERANCE)).forEachOrdered(colRanges::add);
    List<Range<Integer>> cols = colRanges.asRanges().stream().collect(Collectors.toList());

    Node[][] puzzle = new Node[rows.size()][cols.size()];
    ImmutableMap.Builder<Node, Region.Point> mapBuilder = ImmutableMap.builder();
    for (Region r : nodeRegions) {
        Region.Point c = r.centroid();
        Rectangle b = r.boundingBox();
        int row = rows.indexOf(rowRanges.rangeContaining(c.y()));
        int col = cols.indexOf(colRanges.rangeContaining(c.x()));
        Node.Kind kind = Colors.NODE_COLORS.get(r.color());
        Node node;/* w ww . j a v a2s .  c om*/
        if (kind == Node.Kind.OCTAGON) {
            int pips = (int) pipRegions.stream().filter(p -> b.contains(p.boundingBox())).count();
            node = Node.octagon(row, col, pips);
        } else {
            boolean terminal = terminalRegions.stream().anyMatch(t -> b.contains(t.boundingBox()));
            node = terminal ? Node.terminal(row, col, kind) : Node.nonterminal(row, col, kind);
        }
        puzzle[row][col] = node;
        mapBuilder.put(node, c);
    }
    return new Pair<>(new Puzzle(puzzle), mapBuilder.build());
}

From source file:dagger.internal.codegen.DuplicateBindingsValidator.java

private static ImmutableSet<Equivalence.Wrapper<Binding>> equivalentSetIgnoringComponentPath(
        ImmutableSet<Binding> resolvedBindings) {
    return resolvedBindings.stream().map(IGNORING_COMPONENT_PATH::wrap).collect(toImmutableSet());
}

From source file:com.facebook.buck.ide.intellij.BaseIjModuleRule.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
 *///from   w  w  w  . jav a 2  s  .  co  m
protected 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));
}

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

/**
 * Compares two {@link ImmutableMap} of {@link Ds3Type}
 * @param oldTypes Map of {@link Ds3Type} from the older API
 * @param newTypes Map of {@link Ds3Type} from the newer API
 *//*from   w  ww .  jav  a  2 s .  c om*/
static ImmutableList<AbstractDs3TypeDiff> compareDs3Types(final ImmutableMap<String, Ds3Type> oldTypes,
        final ImmutableMap<String, Ds3Type> newTypes) {
    final ImmutableSet<String> typeNames = getTypeNameUnion(oldTypes, newTypes);
    final Ds3TypeComparator comparator = new Ds3TypeComparatorImpl();
    return typeNames.stream().map(name -> comparator.compare(oldTypes.get(name), newTypes.get(name)))
            .collect(GuavaCollectors.immutableList());
}

From source file:com.jeffreybosboom.lyne.Solver.java

/**
 * Returns the paths through the given solved puzzle, one per color, or null
 * if the solution paths are unsatisfying.
 * @param puzzle a solved puzzle/*from w ww  .java 2  s .  co m*/
 * @return the solution paths, one per color, or null
 */
private static Set<List<Node>> solutionPaths(Puzzle puzzle) {
    puzzle.getClass();
    checkArgument(puzzle.edges().allMatch(a -> puzzle.possibilities(a.first, a.second).size() == 1));
    ImmutableSet.Builder<List<Node>> pathsBuilder = ImmutableSet.builder();
    for (Iterator<Pair<Node, Node>> it = puzzle.terminals().iterator(); it.hasNext();) {
        Pair<Node, Node> pair = it.next();
        List<Node> path = new ArrayList<>();
        path.add(pair.first);
        path = findPath(puzzle, path, pair.second, new HashSet<>());
        if (path == null)
            return null;
        pathsBuilder.add(path);
    }
    ImmutableSet<List<Node>> paths = pathsBuilder.build();
    Multiset<Node> counts = HashMultiset.create();
    paths.stream().forEachOrdered(counts::addAll);
    //ensure each node appears enough times over all the paths
    //TODO: we check colored node appearances in findPath, so this could be
    //just octagons?
    if (!puzzle.nodes().allMatch(n -> counts.count(n) == (n.desiredEdges() + 1) / 2))
        return null;
    return paths;
}

From source file:io.flood.rpc.registry.ResourceRegistry.java

private synchronized static Registry getRegistry() {
    final ClassLoader loader = Thread.currentThread().getContextClassLoader();

    try {// w ww . j a va2  s . co m
        ImmutableSet<ClassPath.ClassInfo> classes = ClassPath.from(loader).getTopLevelClasses("io.flood");
        Optional<ClassPath.ClassInfo> registryClassInfoOp = classes.stream().filter(classInfo -> {
            if (classInfo.getClass().getAnnotation(RegistryAction.class) != null) {
                return true;
            }
            return false;
        }).sorted(((cla, clb) -> {
            RegistryAction aa = cla.getClass().getAnnotation(RegistryAction.class);
            RegistryAction ab = clb.getClass().getAnnotation(RegistryAction.class);
            return aa.order() - ab.order();
        })).findFirst();

        ClassPath.ClassInfo registryClassInfo = registryClassInfoOp.orElseThrow(Exception::new);
        RegistryAction action = registryClassInfo.getClass().getAnnotation(RegistryAction.class);

        Registry registry = (Registry) Class.forName(registryClassInfo.getName()).<Registry>newInstance();
        Configuration.configObject(registry);
        LOG.info("instance {} registry", action.value());
        return registry;

    } catch (Exception e) {
        LOG.error("");
        System.exit(-1);
    }

    return null;
}

From source file:me.finalchild.nashornbukkit.util.BukkitImporter.java

public static Map<String, ClassPath.ClassInfo> getTypes(boolean cache) {
    if (typesCache != null) {
        return typesCache;
    }//  w ww  . ja  va2  s.c om

    ClassPath classpath;
    try {
        classpath = ClassPath.from(NashornBukkit.class.getClassLoader());
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
    ImmutableSet<ClassPath.ClassInfo> result = classpath.getTopLevelClassesRecursive("org.bukkit");
    Map<String, ClassPath.ClassInfo> types = result.stream()
            .filter(e -> !(e.getName().startsWith("org.bukkit.craftbukkit")))
            .filter(e -> !(e.getSimpleName().equals("package-info")))
            .collect(Collectors.toMap(ClassPath.ClassInfo::getSimpleName, Function.identity(), (a, b) -> {
                NashornBukkit.getInstance().getLogger()
                        .info("Duplicate class name: " + a.getName() + " and " + b.getName());
                return a;
            }));

    if (cache) {
        typesCache = types;
    }
    return Collections.unmodifiableMap(types);
}