List of usage examples for com.google.common.collect ImmutableMap entrySet
public final ImmutableSet<Entry<K, V>> entrySet()
From source file:no.ssb.vtl.model.DataStructure.java
private static ImmutableMap<String, Class<?>> computeTypeCache(ImmutableMap<String, Component> delegate) { ImmutableMap.Builder<String, Class<?>> builder = ImmutableMap.builder(); for (Entry<String, Component> entry : delegate.entrySet()) { builder.put(entry.getKey(), entry.getValue().getType()); }//from w w w .j a va 2s . co m return builder.build(); }
From source file:com.facebook.buck.features.python.PythonUtil.java
static PythonPackageComponents getAllComponents(CellPathResolver cellPathResolver, BuildTarget buildTarget, ProjectFilesystem projectFilesystem, BuildRuleParams params, ActionGraphBuilder graphBuilder, SourcePathRuleFinder ruleFinder, Iterable<BuildRule> deps, PythonPackageComponents packageComponents, PythonPlatform pythonPlatform, CxxBuckConfig cxxBuckConfig, CxxPlatform cxxPlatform, ImmutableList<? extends Arg> extraLdflags, NativeLinkStrategy nativeLinkStrategy, ImmutableSet<BuildTarget> preloadDeps) { PythonPackageComponents.Builder allComponents = new PythonPackageComponents.Builder(buildTarget); Map<BuildTarget, CxxPythonExtension> extensions = new LinkedHashMap<>(); Map<BuildTarget, NativeLinkable> nativeLinkableRoots = new LinkedHashMap<>(); OmnibusRoots.Builder omnibusRoots = OmnibusRoots.builder(cxxPlatform, preloadDeps, graphBuilder); // Add the top-level components. allComponents.addComponent(packageComponents, buildTarget); // Walk all our transitive deps to build our complete package that we'll // turn into an executable. new AbstractBreadthFirstTraversal<BuildRule>( Iterables.concat(deps, graphBuilder.getAllRules(preloadDeps))) { private final ImmutableList<BuildRule> empty = ImmutableList.of(); @Override/*from w ww . j av a 2 s . c o m*/ public Iterable<BuildRule> visit(BuildRule rule) { Iterable<BuildRule> deps = empty; if (rule instanceof CxxPythonExtension) { CxxPythonExtension extension = (CxxPythonExtension) rule; NativeLinkTarget target = ((CxxPythonExtension) rule).getNativeLinkTarget(pythonPlatform); extensions.put(target.getBuildTarget(), extension); omnibusRoots.addIncludedRoot(target); List<BuildRule> cxxpydeps = new ArrayList<>(); for (BuildRule dep : extension.getPythonPackageDeps(pythonPlatform, cxxPlatform, graphBuilder)) { if (dep instanceof PythonPackagable) { cxxpydeps.add(dep); } } deps = cxxpydeps; } else if (rule instanceof PythonPackagable) { PythonPackagable packagable = (PythonPackagable) rule; PythonPackageComponents comps = packagable.getPythonPackageComponents(pythonPlatform, cxxPlatform, graphBuilder); allComponents.addComponent(comps, rule.getBuildTarget()); if (packagable.doesPythonPackageDisallowOmnibus() || comps.hasNativeCode(cxxPlatform)) { for (BuildRule dep : packagable.getPythonPackageDeps(pythonPlatform, cxxPlatform, graphBuilder)) { if (dep instanceof NativeLinkable) { NativeLinkable linkable = (NativeLinkable) dep; nativeLinkableRoots.put(linkable.getBuildTarget(), linkable); omnibusRoots.addExcludedRoot(linkable); } } } deps = packagable.getPythonPackageDeps(pythonPlatform, cxxPlatform, graphBuilder); } else if (rule instanceof NativeLinkable) { NativeLinkable linkable = (NativeLinkable) rule; nativeLinkableRoots.put(linkable.getBuildTarget(), linkable); omnibusRoots.addPotentialRoot(linkable); } return deps; } }.start(); // For the merged strategy, build up the lists of included native linkable roots, and the // excluded native linkable roots. if (nativeLinkStrategy == NativeLinkStrategy.MERGED) { OmnibusRoots roots = omnibusRoots.build(); OmnibusLibraries libraries = Omnibus.getSharedLibraries(buildTarget, projectFilesystem, params, cellPathResolver, graphBuilder, ruleFinder, cxxBuckConfig, cxxPlatform, extraLdflags, roots.getIncludedRoots().values(), roots.getExcludedRoots().values()); // Add all the roots from the omnibus link. If it's an extension, add it as a module. // Otherwise, add it as a native library. for (Map.Entry<BuildTarget, OmnibusRoot> root : libraries.getRoots().entrySet()) { CxxPythonExtension extension = extensions.get(root.getKey()); if (extension != null) { allComponents.addModule(extension.getModule(), root.getValue().getPath(), root.getKey()); } else { NativeLinkTarget target = Preconditions.checkNotNull( roots.getIncludedRoots().get(root.getKey()), "%s: linked unexpected omnibus root: %s", buildTarget, root.getKey()); NativeLinkTargetMode mode = target.getNativeLinkTargetMode(cxxPlatform); String soname = Preconditions.checkNotNull(mode.getLibraryName().orElse(null), "%s: omnibus library for %s was built without soname", buildTarget, root.getKey()); allComponents.addNativeLibraries(Paths.get(soname), root.getValue().getPath(), root.getKey()); } } // Add all remaining libraries as native libraries. for (OmnibusLibrary library : libraries.getLibraries()) { allComponents.addNativeLibraries(Paths.get(library.getSoname()), library.getPath(), buildTarget); } } else { // For regular linking, add all extensions via the package components interface. Map<BuildTarget, NativeLinkable> extensionNativeDeps = new LinkedHashMap<>(); for (Map.Entry<BuildTarget, CxxPythonExtension> entry : extensions.entrySet()) { allComponents.addComponent( entry.getValue().getPythonPackageComponents(pythonPlatform, cxxPlatform, graphBuilder), entry.getValue().getBuildTarget()); extensionNativeDeps.putAll(Maps.uniqueIndex(entry.getValue().getNativeLinkTarget(pythonPlatform) .getNativeLinkTargetDeps(cxxPlatform, graphBuilder), NativeLinkable::getBuildTarget)); } // Add all the native libraries. ImmutableMap<BuildTarget, NativeLinkable> nativeLinkables = NativeLinkables .getTransitiveNativeLinkables(cxxPlatform, graphBuilder, Iterables.concat(nativeLinkableRoots.values(), extensionNativeDeps.values())); for (NativeLinkable nativeLinkable : nativeLinkables.values()) { NativeLinkable.Linkage linkage = nativeLinkable.getPreferredLinkage(cxxPlatform, graphBuilder); if (nativeLinkableRoots.containsKey(nativeLinkable.getBuildTarget()) || linkage != NativeLinkable.Linkage.STATIC) { ImmutableMap<String, SourcePath> libs = nativeLinkable.getSharedLibraries(cxxPlatform, graphBuilder); for (Map.Entry<String, SourcePath> ent : libs.entrySet()) { allComponents.addNativeLibraries(Paths.get(ent.getKey()), ent.getValue(), nativeLinkable.getBuildTarget()); } } } } return allComponents.build(); }
From source file:no.ssb.vtl.model.DataStructure.java
private static ImmutableMap<String, Component.Role> computeRoleCache(ImmutableMap<String, Component> delegate) { ImmutableMap.Builder<String, Component.Role> builder = ImmutableMap.builder(); for (Entry<String, Component> entry : delegate.entrySet()) { builder.put(entry.getKey(), entry.getValue().getRole()); }/*from w w w .j av a 2 s .c o m*/ return builder.build(); }
From source file:com.facebook.buck.cxx.CxxPreprocessables.java
/** * Resolve the map of name to {@link SourcePath} to a map of full header name to * {@link SourcePath}./*from w w w . ja v a 2 s.c o m*/ */ public static ImmutableMap<Path, SourcePath> resolveHeaderMap(Path basePath, ImmutableMap<String, SourcePath> headers) { ImmutableMap.Builder<Path, SourcePath> headerMap = ImmutableMap.builder(); // Resolve the "names" of the headers to actual paths by prepending the base path // specified by the build target. for (ImmutableMap.Entry<String, SourcePath> ent : headers.entrySet()) { Path path = basePath.resolve(ent.getKey()); headerMap.put(path, ent.getValue()); } return headerMap.build(); }
From source file:com.facebook.buck.android.AndroidNativeLibsPackageableGraphEnhancer.java
private static ImmutableMap<StripLinkable, StrippedObjectDescription> generateStripRules( BuildRuleParams buildRuleParams, SourcePathRuleFinder ruleFinder, BuildRuleResolver ruleResolver, BuildTarget appRuleTarget, ImmutableMap<NdkCxxPlatforms.TargetCpuType, NdkCxxPlatform> nativePlatforms, ImmutableMap<Pair<NdkCxxPlatforms.TargetCpuType, String>, SourcePath> libs) { ImmutableMap.Builder<StripLinkable, StrippedObjectDescription> result = ImmutableMap.builder(); for (Map.Entry<Pair<NdkCxxPlatforms.TargetCpuType, String>, SourcePath> entry : libs.entrySet()) { SourcePath sourcePath = entry.getValue(); NdkCxxPlatforms.TargetCpuType targetCpuType = entry.getKey().getFirst(); NdkCxxPlatform platform = Preconditions.checkNotNull(nativePlatforms.get(targetCpuType)); // To be safe, default to using the app rule target as the base for the strip rule. // This will be used for stripping the C++ runtime. We could use something more easily // shareable (like just using the app's containing directory, or even the repo root), // but stripping the C++ runtime is pretty fast, so just keep the safe old behavior for now. BuildTarget baseBuildTarget = appRuleTarget; // But if we're stripping a cxx_library, use that library as the base of the target // to allow sharing the rule between all apps that depend on it. if (sourcePath instanceof BuildTargetSourcePath) { baseBuildTarget = ((BuildTargetSourcePath) sourcePath).getTarget(); }/* www .j ava2 s . c o m*/ String sharedLibrarySoName = entry.getKey().getSecond(); BuildTarget targetForStripRule = BuildTarget.builder(baseBuildTarget) .addFlavors(ImmutableFlavor.of("android-strip")) .addFlavors(ImmutableFlavor.of(Flavor.replaceInvalidCharacters(sharedLibrarySoName))) .addFlavors(ImmutableFlavor.of(Flavor.replaceInvalidCharacters(targetCpuType.name()))).build(); Optional<BuildRule> previouslyCreated = ruleResolver.getRuleOptional(targetForStripRule); StripLinkable stripLinkable; if (previouslyCreated.isPresent()) { stripLinkable = (StripLinkable) previouslyCreated.get(); } else { BuildRuleParams paramsForStripLinkable = buildRuleParams.copyWithChanges(targetForStripRule, Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder() .addAll(ruleFinder.filterBuildRuleInputs(ImmutableList.of(sourcePath))).build()), /* extraDeps */ Suppliers.ofInstance(ImmutableSortedSet.of())); stripLinkable = new StripLinkable(paramsForStripLinkable, platform.getCxxPlatform().getStrip(), sourcePath, sharedLibrarySoName); ruleResolver.addToIndex(stripLinkable); } result.put(stripLinkable, StrippedObjectDescription.builder() .setSourcePath(new BuildTargetSourcePath(stripLinkable.getBuildTarget())) .setStrippedObjectName(sharedLibrarySoName).setTargetCpuType(targetCpuType).build()); } return result.build(); }
From source file:net.techcable.pineapple.collect.ImmutableMaps.java
@SuppressWarnings("unchecked") public static <K, V> void forEach(ImmutableMap<K, V> map, BiConsumer<? super K, ? super V> action) { checkNotNull(map, "Null map"); if (ENTRIES_ARRAY_FIELD != null && ENTRIES_ARRAY_FIELD.getDeclaringClass().isInstance(map)) { for (Map.Entry<K, V> entry : ENTRIES_ARRAY_FIELD.get(map)) { K key = entry.getKey();/*from ww w.j a va 2 s. c o m*/ V value = entry.getValue(); checkNotNull(action, "Null action").accept(key, value); } } else { ImmutableList<Map.Entry<K, V>> entryList = map.entrySet().asList(); // Since they don't support forEach this is the fastest way to iterate for (int i = 0; i < entryList.size(); i++) { Map.Entry<K, V> entry = entryList.get(i); action.accept(entry.getKey(), entry.getValue()); } } }
From source file:com.facebook.buck.cli.Config.java
private static ImmutableMap<String, ImmutableMap<String, String>> sectionToEntriesFromMaps( ImmutableList<ImmutableMap<String, ImmutableMap<String, String>>> maps) { Map<String, Map<String, String>> sectionToEntries = new LinkedHashMap<>(); for (ImmutableMap<String, ImmutableMap<String, String>> map : maps) { for (Map.Entry<String, ImmutableMap<String, String>> section : map.entrySet()) { if (!sectionToEntries.containsKey(section.getKey())) { sectionToEntries.put(section.getKey(), new LinkedHashMap<String, String>()); }//from ww w. j a v a 2 s . c o m Map<String, String> entries = Preconditions.checkNotNull(sectionToEntries.get(section.getKey())); for (Map.Entry<String, String> entry : section.getValue().entrySet()) { entries.put(entry.getKey(), entry.getValue()); } } } ImmutableMap.Builder<String, ImmutableMap<String, String>> builder = ImmutableMap.builder(); for (Map.Entry<String, Map<String, String>> entry : sectionToEntries.entrySet()) { builder.put(entry.getKey(), ImmutableMap.copyOf(entry.getValue())); } return builder.build(); }
From source file:com.facebook.buck.io.watchman.WatchmanWatcher.java
@VisibleForTesting static ImmutableMap<Path, WatchmanQuery> createQueries(ImmutableMap<Path, ProjectWatch> projectWatches, ImmutableSet<PathMatcher> ignorePaths, Set<Capability> watchmanCapabilities) { ImmutableMap.Builder<Path, WatchmanQuery> watchmanQueryBuilder = ImmutableMap.builder(); for (Map.Entry<Path, ProjectWatch> entry : projectWatches.entrySet()) { watchmanQueryBuilder.put(entry.getKey(), createQuery(entry.getValue(), ignorePaths, watchmanCapabilities)); }/* w ww.j ava2 s . c o m*/ return watchmanQueryBuilder.build(); }
From source file:com.google.devtools.build.lib.bazel.rules.android.ndkcrosstools.r17.AndroidNdkCrosstoolsR17.java
private static ImmutableList<DefaultCpuToolchain> getDefaultCpuToolchains(StlImpl stlImpl, String clangVersion) {//w w w . j av a 2s . c o m // TODO(bazel-team): It would be better to auto-generate this somehow. ImmutableMap<String, String> defaultCpus = ImmutableMap.<String, String>builder() // arm .put("armeabi-v7a", "arm-linux-androideabi-clang" + clangVersion + "-v7a") .put("arm64-v8a", "aarch64-linux-android-clang" + clangVersion) // x86 .put("x86", "x86-clang" + clangVersion).put("x86_64", "x86_64-clang" + clangVersion).build(); ImmutableList.Builder<DefaultCpuToolchain> defaultCpuToolchains = ImmutableList.builder(); for (Map.Entry<String, String> defaultCpu : defaultCpus.entrySet()) { defaultCpuToolchains.add(DefaultCpuToolchain.newBuilder().setCpu(defaultCpu.getKey()) .setToolchainIdentifier(defaultCpu.getValue() + "-" + stlImpl.getName()).build()); } return defaultCpuToolchains.build(); }
From source file:org.apache.calcite.schema.Schemas.java
private static CalciteConnectionConfig mutate(CalciteConnectionConfig config, ImmutableMap<CalciteConnectionProperty, String> propValues) { for (Map.Entry<CalciteConnectionProperty, String> e : propValues.entrySet()) { config = ((CalciteConnectionConfigImpl) config).set(e.getKey(), e.getValue()); }/*from w w w . ja v a 2 s .c o m*/ return config; }