Example usage for com.google.common.collect ImmutableMap values

List of usage examples for com.google.common.collect ImmutableMap values

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableMap values.

Prototype

public ImmutableCollection<V> values() 

Source Link

Usage

From source file:com.google.devtools.build.java.bazel.JavaBuilderConfigGenerator.java

public static void main(String[] args) {
    try {/*from www.ja v a 2s.co m*/
        InputStream stream = System.in;
        if (args.length > 0) {
            stream = new FileInputStream(args[0]);
        }
        ImmutableMap<String, JavaToolchainData> data = JavaToolchainDataParser.parse(stream);
        if (data.size() != 1) {
            die(data.isEmpty() ? "No java_toolchain found!" : "Multiple java_toolchain found!");
        }
        JavaToolchainData first = data.values().asList().get(0);
        String optsString = Joiner.on("\", \"").join(first.getJavacOptions());
        System.out.println("package com.google.devtools.build.java.bazel;");
        System.out.println("public class JavaBuilderJavacOpts {");
        System.out.println("public static final String[] DEFAULT_JAVACOPTS = {\"" + optsString + "\"};");
        System.out.println("}");
    } catch (IOException e) {
        die("Cannot load input file: " + e.getMessage());
    }
}

From source file:com.facebook.buck.core.cell.impl.DistributedCellProviderFactory.java

public static CellProvider create(DistBuildCellParams rootCell,
        ImmutableMap<Path, DistBuildCellParams> cellParams) {
    Map<String, Path> cellPaths = cellParams.values().stream().filter(p -> p.getCanonicalName().isPresent())
            .collect(Collectors.toMap(p -> p.getCanonicalName().get(), p -> p.getFilesystem().getRootPath()));
    ImmutableSet<String> declaredCellNames = ImmutableSet.copyOf(cellPaths.keySet());
    Path rootCellPath = rootCell.getFilesystem().getRootPath();
    DefaultCellPathResolver rootCellResolver = DefaultCellPathResolver.of(rootCellPath, cellPaths);

    return new CellProvider(cellProvider -> CacheLoader.from(cellPath -> {
        DistBuildCellParams cellParam = Preconditions.checkNotNull(cellParams.get(cellPath),
                "This should only be called for secondary cells.");
        Path currentCellRoot = cellParam.getFilesystem().getRootPath();
        Preconditions.checkState(!currentCellRoot.equals(rootCellPath));
        CellPathResolver currentCellResolver = rootCellResolver;
        // The CellPathResolverView is required because it makes the
        // [RootPath<->CanonicalName] resolver methods non-symmetrical to handle the
        // fact/*w w w  .ja  v  a 2 s  .  c o m*/
        // that relative main cell from inside a secondary cell resolves actually to
        // secondary cell. If the DefaultCellPathResolver is used, then it would return
        // a BuildTarget as if it belonged to the main cell.
        currentCellResolver = new CellPathResolverView(rootCellResolver, declaredCellNames, currentCellRoot);
        BuckConfig configWithResolver = cellParam.getConfig().withCellPathResolver(currentCellResolver);
        RuleKeyConfiguration ruleKeyConfiguration = ConfigRuleKeyConfigurationFactory.create(configWithResolver,
                cellParam.getBuckModuleManager());
        ToolchainProvider toolchainProvider = new DefaultToolchainProvider(cellParam.getPluginManager(),
                cellParam.getEnvironment(), configWithResolver, cellParam.getFilesystem(),
                cellParam.getProcessExecutor(), cellParam.getExecutableFinder(), ruleKeyConfiguration);

        return ImmutableCell.of(cellParams.keySet(),
                // Distributed builds don't care about cell names, use a sentinel value that
                // will show up if it actually does care about them.
                cellParam.getCanonicalName(), WatchmanFactory.NULL_WATCHMAN, cellProvider, toolchainProvider,
                ruleKeyConfiguration, cellParam.getFilesystem(), configWithResolver);
    }), cellProvider -> RootCellFactory.create(cellProvider, rootCellResolver, rootCell.getFilesystem(),
            rootCell.getBuckModuleManager(), rootCell.getPluginManager(), rootCell.getConfig(),
            rootCell.getEnvironment(), rootCell.getProcessExecutor(), rootCell.getExecutableFinder(),
            WatchmanFactory.NULL_WATCHMAN));
}

From source file:ai.grakn.graql.internal.gremlin.spanningtree.Arborescence.java

public static <T> Arborescence<T> of(ImmutableMap<T, T> parents) {
    if (parents != null && !parents.isEmpty()) {
        HashSet<T> allParents = Sets.newHashSet(parents.values());
        allParents.removeAll(parents.keySet());
        if (allParents.size() == 1) {
            return new Arborescence<>(parents, allParents.iterator().next());
        }/*from  ww w.ja  v  a 2s  .  c om*/
    }
    return new Arborescence<>(parents, null);
}

From source file:com.facebook.buck.versions.VersionedTargetGraphFactory.java

public static VersionedTargetGraph newInstance(Iterable<TargetNode<?, ?>> nodes) {
    Map<BuildTarget, TargetNode<?, ?>> builder = new HashMap<>();
    for (TargetNode<?, ?> node : nodes) {
        builder.put(node.getBuildTarget(), node);
    }//  ww w  . j  a  va2  s .  c om
    ImmutableMap<BuildTarget, TargetNode<?, ?>> map = ImmutableMap.copyOf(builder);

    MutableDirectedGraph<TargetNode<?, ?>> graph = new MutableDirectedGraph<>();
    for (TargetNode<?, ?> node : map.values()) {
        graph.addNode(node);
        for (BuildTarget dep : node.getDeps()) {
            graph.addEdge(node, Preconditions.checkNotNull(map.get(dep), dep));
        }
    }
    return new VersionedTargetGraph(graph, map, ImmutableSet.of());
}

From source file:com.facebook.buck.testutil.TargetGraphFactory.java

public static TargetGraph newInstance(Iterable<TargetNode<?, ?>> nodes) {
    Map<BuildTarget, TargetNode<?, ?>> builder = new HashMap<>();
    for (TargetNode<?, ?> node : nodes) {
        builder.put(node.getBuildTarget(), node);
        BuildTarget unflavoredTarget = BuildTarget.of(node.getBuildTarget().getUnflavoredBuildTarget());
        if (node.getBuildTarget().isFlavored() && !builder.containsKey(unflavoredTarget)) {
            builder.put(unflavoredTarget, node);
        }/*w w w.  j  av  a  2s .  co m*/
    }
    ImmutableMap<BuildTarget, TargetNode<?, ?>> map = ImmutableMap.copyOf(builder);

    MutableDirectedGraph<TargetNode<?, ?>> graph = new MutableDirectedGraph<>();
    for (TargetNode<?, ?> node : map.values()) {
        graph.addNode(node);
        for (BuildTarget dep : node.getDeps()) {
            graph.addEdge(node, Preconditions.checkNotNull(map.get(dep), dep));
        }
    }
    return new TargetGraph(graph, map, ImmutableSet.of());
}

From source file:com.facebook.buck.core.model.targetgraph.TargetGraphFactory.java

/**
 * Like {@link #newInstance(TargetNode[])} but does not also add a node for unflavored version of
 * the given node./*from   ww  w  .j  ava  2s  . c  o m*/
 */
public static TargetGraph newInstanceExact(TargetNode<?>... nodes) {
    Map<BuildTarget, TargetNode<?>> builder = new HashMap<>();
    for (TargetNode<?> node : nodes) {
        builder.put(node.getBuildTarget(), node);
    }
    ImmutableMap<BuildTarget, TargetNode<?>> map = ImmutableMap.copyOf(builder);

    MutableDirectedGraph<TargetNode<?>> graph = new MutableDirectedGraph<>();
    for (TargetNode<?> node : map.values()) {
        graph.addNode(node);
        for (BuildTarget dep : node.getBuildDeps()) {
            graph.addEdge(node, Objects.requireNonNull(map.get(dep), dep::toString));
        }
    }
    return new TargetGraph(graph, map);
}

From source file:com.facebook.buck.core.model.targetgraph.TargetGraphFactory.java

public static TargetGraph newInstance(Iterable<TargetNode<?>> nodes) {
    Map<BuildTarget, TargetNode<?>> builder = new HashMap<>();
    for (TargetNode<?> node : nodes) {
        builder.put(node.getBuildTarget(), node);
        BuildTarget unflavoredTarget = node.getBuildTarget().withoutFlavors();
        if (node.getBuildTarget().isFlavored() && !builder.containsKey(unflavoredTarget)) {
            builder.put(unflavoredTarget, node.withFlavors(ImmutableSet.of()));
        }//from   w ww  .  j  a va 2  s  .c o  m
    }
    ImmutableMap<BuildTarget, TargetNode<?>> map = ImmutableMap.copyOf(builder);

    MutableDirectedGraph<TargetNode<?>> graph = new MutableDirectedGraph<>();
    for (TargetNode<?> node : map.values()) {
        graph.addNode(node);
        for (BuildTarget dep : node.getBuildDeps()) {
            graph.addEdge(node, Objects.requireNonNull(map.get(dep), dep::toString));
        }
    }
    return new TargetGraph(graph, map);
}

From source file:com.google.caliper.runner.FullCartesianExperimentSelector.java

protected static <T> Set<List<T>> cartesian(SetMultimap<String, T> multimap) {
    @SuppressWarnings({ "unchecked", "rawtypes" }) // promised by spec
    ImmutableMap<String, Set<T>> paramsAsMap = (ImmutableMap) multimap.asMap();
    return Sets.cartesianProduct(paramsAsMap.values().asList());
}

From source file:com.facebook.buck.distributed.DistributedCellProviderFactory.java

public static CellProvider create(DistBuildCellParams rootCell,
        ImmutableMap<Path, DistBuildCellParams> cellParams, CellPathResolver rootCellPathResolver,
        UnconfiguredBuildTargetFactory unconfiguredBuildTargetFactory) {
    Map<String, Path> cellPaths = cellParams.values().stream().filter(p -> p.getCanonicalName().isPresent())
            .collect(Collectors.toMap(p -> p.getCanonicalName().get(), p -> p.getFilesystem().getRootPath()));
    ImmutableSet<String> declaredCellNames = ImmutableSet.copyOf(cellPaths.keySet());
    Path rootCellPath = rootCell.getFilesystem().getRootPath();
    DefaultCellPathResolver rootCellResolver = DefaultCellPathResolver.of(rootCellPath, cellPaths);

    return new CellProvider(cellProvider -> CacheLoader.from(cellPath -> {
        DistBuildCellParams cellParam = Objects.requireNonNull(cellParams.get(cellPath),
                "This should only be called for secondary cells.");
        Path currentCellRoot = cellParam.getFilesystem().getRootPath();
        Preconditions.checkState(!currentCellRoot.equals(rootCellPath));
        CellPathResolver currentCellResolver = rootCellResolver;
        // The CellPathResolverView is required because it makes the
        // [RootPath<->CanonicalName] resolver methods non-symmetrical to handle the
        // fact/*ww w  .ja v  a 2s  .c  o  m*/
        // that relative main cell from inside a secondary cell resolves actually to
        // secondary cell. If the DefaultCellPathResolver is used, then it would return
        // a BuildTarget as if it belonged to the main cell.
        currentCellResolver = new CellPathResolverView(rootCellResolver, declaredCellNames, currentCellRoot);
        CellPathResolver cellPathResolverForParser = currentCellResolver;
        BuckConfig configWithResolver = cellParam.getConfig()
                .withBuildTargetParser(buildTargetName -> unconfiguredBuildTargetFactory
                        .create(cellPathResolverForParser, buildTargetName));
        RuleKeyConfiguration ruleKeyConfiguration = ConfigRuleKeyConfigurationFactory.create(configWithResolver,
                cellParam.getBuckModuleManager());
        ToolchainProvider toolchainProvider = new DefaultToolchainProvider(cellParam.getPluginManager(),
                cellParam.getEnvironment(), configWithResolver, cellParam.getFilesystem(),
                cellParam.getProcessExecutor(), cellParam.getExecutableFinder(), ruleKeyConfiguration);

        return ImmutableCell.of(ImmutableSortedSet.copyOf(cellParams.keySet()),
                // Distributed builds don't care about cell names, use a sentinel value that
                // will show up if it actually does care about them.
                cellParam.getCanonicalName(), cellParam.getFilesystem(), configWithResolver, cellProvider,
                toolchainProvider, ruleKeyConfiguration, currentCellResolver);
    }), cellProvider -> RootCellFactory.create(cellProvider, rootCellResolver, rootCellPathResolver,
            rootCell.getFilesystem(), rootCell.getBuckModuleManager(), rootCell.getPluginManager(),
            rootCell.getConfig(), rootCell.getEnvironment(), rootCell.getProcessExecutor(),
            rootCell.getExecutableFinder()));
}

From source file:com.spectralogic.ds3autogen.net.generators.parsers.typeset.BaseTypeParserSetGenerator.java

/**
 * Retrieves the list of enum type names from within a Ds3Types list
 *//* w w  w  . j av  a2  s .c  o  m*/
protected static ImmutableList<String> toEnumList(final ImmutableMap<String, Ds3Type> typeMap) {
    if (isEmpty(typeMap)) {
        return ImmutableList.of();
    }
    final ImmutableList.Builder<String> builder = ImmutableList.builder();
    for (final Ds3Type ds3Type : typeMap.values().asList()) {
        if (isEnum(ds3Type) && !isChecksumType(ds3Type)) {
            builder.add(removePath(ds3Type.getName()));
        }
    }
    return builder.build();
}