List of usage examples for com.google.common.collect ImmutableMap entrySet
public final ImmutableSet<Entry<K, V>> entrySet()
From source file:com.facebook.buck.features.lua.LuaUtil.java
public static ImmutableMap<String, SourcePath> toModuleMap(BuildTarget target, SourcePathResolver resolver, String parameter, String baseModule, Iterable<SourceSortedSet> inputs) { ImmutableMap.Builder<String, SourcePath> moduleNamesAndSourcePaths = ImmutableMap.builder(); for (SourceSortedSet input : inputs) { ImmutableMap<String, SourcePath> namesAndSourcePaths; if (input.getUnnamedSources().isPresent()) { namesAndSourcePaths = resolver.getSourcePathNames(target, parameter, input.getUnnamedSources().get()); } else {/*from w w w . j a va2 s. c o m*/ namesAndSourcePaths = input.getNamedSources().get(); } for (ImmutableMap.Entry<String, SourcePath> entry : namesAndSourcePaths.entrySet()) { String name = entry.getKey(); if (!baseModule.isEmpty()) { name = baseModule + '/' + name; } moduleNamesAndSourcePaths.put(name, entry.getValue()); } } return moduleNamesAndSourcePaths.build(); }
From source file:com.google.devtools.build.java.turbine.javac.JavacTurbine.java
private static ImmutableMap<String, JarOwner> parseJarsToTargets(ImmutableMap<String, String> input) { ImmutableMap.Builder<String, JarOwner> result = ImmutableMap.builder(); for (Map.Entry<String, String> entry : input.entrySet()) { result.put(entry.getKey(), parseJarOwner(entry.getKey())); }/*from www .j av a 2 s .c o m*/ return result.build(); }
From source file:se.sics.caracaldb.global.SchemaData.java
static void serialiseSchema(ByteBuf buf, ByteBuffer id, String name, ImmutableMap<String, String> metaData) { buf.writeInt(id.array().length);/*from w w w. j av a2 s. co m*/ buf.writeBytes(id.array()); byte[] nameB = name.getBytes(CHARSET); buf.writeInt(nameB.length); buf.writeBytes(nameB); buf.writeInt(metaData.size()); for (Entry<String, String> e : metaData.entrySet()) { byte[] keyB = e.getKey().getBytes(CHARSET); byte[] valB = e.getValue().getBytes(CHARSET); buf.writeInt(keyB.length); buf.writeBytes(keyB); buf.writeInt(valB.length); buf.writeBytes(valB); } }
From source file:com.facebook.buck.python.PythonUtil.java
public static PythonPackageComponents getAllComponents(BuildRuleParams params, BuildRuleResolver ruleResolver, SourcePathResolver pathResolver, SourcePathRuleFinder ruleFinder, final PythonPackageComponents packageComponents, final PythonPlatform pythonPlatform, CxxBuckConfig cxxBuckConfig, final CxxPlatform cxxPlatform, ImmutableList<? extends Arg> extraLdflags, final NativeLinkStrategy nativeLinkStrategy, final ImmutableSet<BuildTarget> preloadDeps) throws NoSuchBuildTargetException { final PythonPackageComponents.Builder allComponents = new PythonPackageComponents.Builder( params.getBuildTarget());/* www.j a v a 2s.co m*/ final Map<BuildTarget, CxxPythonExtension> extensions = new LinkedHashMap<>(); final Map<BuildTarget, NativeLinkable> nativeLinkableRoots = new LinkedHashMap<>(); final OmnibusRoots.Builder omnibusRoots = OmnibusRoots.builder(cxxPlatform, preloadDeps); // Add the top-level components. allComponents.addComponent(packageComponents, params.getBuildTarget()); // Walk all our transitive deps to build our complete package that we'll // turn into an executable. new AbstractBreadthFirstThrowingTraversal<BuildRule, NoSuchBuildTargetException>(params.getDeps()) { private final ImmutableList<BuildRule> empty = ImmutableList.of(); @Override public Iterable<BuildRule> visit(BuildRule rule) throws NoSuchBuildTargetException { 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 : rule.getDeps()) { if (dep instanceof CxxPythonExtension) { cxxpydeps.add(dep); } } deps = cxxpydeps; } else if (rule instanceof PythonPackagable) { PythonPackagable packagable = (PythonPackagable) rule; PythonPackageComponents comps = packagable.getPythonPackageComponents(pythonPlatform, cxxPlatform); allComponents.addComponent(comps, rule.getBuildTarget()); if (comps.hasNativeCode(cxxPlatform)) { for (BuildRule dep : rule.getDeps()) { if (dep instanceof NativeLinkable) { NativeLinkable linkable = (NativeLinkable) dep; nativeLinkableRoots.put(linkable.getBuildTarget(), linkable); omnibusRoots.addExcludedRoot(linkable); } } } deps = rule.getDeps(); } 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(params, ruleResolver, pathResolver, 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", params.getBuildTarget(), root.getKey()); NativeLinkTargetMode mode = target.getNativeLinkTargetMode(cxxPlatform); String soname = Preconditions.checkNotNull(mode.getLibraryName().orElse(null), "%s: omnibus library for %s was built without soname", params.getBuildTarget(), 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(), params.getBuildTarget()); } } 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), entry.getValue().getBuildTarget()); extensionNativeDeps.putAll(Maps.uniqueIndex( entry.getValue().getNativeLinkTarget(pythonPlatform).getNativeLinkTargetDeps(cxxPlatform), HasBuildTarget::getBuildTarget)); } // Add all the native libraries. ImmutableMap<BuildTarget, NativeLinkable> nativeLinkables = NativeLinkables .getTransitiveNativeLinkables(cxxPlatform, Iterables.concat(nativeLinkableRoots.values(), extensionNativeDeps.values())); for (NativeLinkable nativeLinkable : nativeLinkables.values()) { NativeLinkable.Linkage linkage = nativeLinkable.getPreferredLinkage(cxxPlatform); if (nativeLinkableRoots.containsKey(nativeLinkable.getBuildTarget()) || linkage != NativeLinkable.Linkage.STATIC) { ImmutableMap<String, SourcePath> libs = nativeLinkable.getSharedLibraries(cxxPlatform); for (Map.Entry<String, SourcePath> ent : libs.entrySet()) { allComponents.addNativeLibraries(Paths.get(ent.getKey()), ent.getValue(), nativeLinkable.getBuildTarget()); } } } } return allComponents.build(); }
From source file:com.spectralogic.ds3autogen.Ds3SpecConverter.java
/** * Converts the contract names of all type names, elements and enum constants * to the SDK naming scheme, as defined within the NameMapper *//*from w w w . j ava 2 s. com*/ protected static ImmutableMap<String, Ds3Type> convertTypes(final ImmutableMap<String, Ds3Type> types, final NameMapper nameMapper) { if (isEmpty(types)) { return types; } final ImmutableMap.Builder<String, Ds3Type> builder = ImmutableMap.builder(); for (final ImmutableMap.Entry<String, Ds3Type> entry : types.entrySet()) { final Ds3Type ds3Type = new Ds3Type(toSdkName(entry.getValue().getName(), nameMapper), toNameToMarshal(entry.getValue().getNameToMarshal()), convertAllElements(entry.getValue().getElements(), nameMapper), convertAllEnumConstants(entry.getValue().getEnumConstants(), nameMapper)); builder.put(toSdkName(entry.getKey(), nameMapper), ds3Type); } return builder.build(); }
From source file:com.spectralogic.ds3autogen.converters.RemoveDollarSignConverter.java
/** * Removes all instances of '$' from Type Map, including the key value and * the Ds3Type. This also checks to see if the renaming of a type conflicts * with any other type within the map. If there is a conflict, an exception * is thrown./*w ww .jav a 2 s. c o m*/ */ public static ImmutableMap<String, Ds3Type> removeDollarSignFromTypeMap( final ImmutableMap<String, Ds3Type> map) { if (isEmpty(map)) { return ImmutableMap.of(); } final ImmutableMap.Builder<String, Ds3Type> builder = ImmutableMap.builder(); for (final Map.Entry<String, Ds3Type> entry : map.entrySet()) { final String typeName = removeDollarSignFromName(entry.getKey()); final Ds3Type type = removeDollarSignFromType(entry.getValue()); if (!containsType(typeName, entry.getValue(), builder.build())) { builder.put(typeName, type); } } return builder.build(); }
From source file:com.facebook.buck.cxx.toolchain.nativelink.NativeLinkables.java
/** * Collect all the shared libraries generated by {@link NativeLinkable}s found by transitively * traversing all unbroken dependency chains of {@link NativeLinkable} objects found via the * passed in {@link BuildRule} roots./*from w ww. java2 s . c om*/ * * @param alwaysIncludeRoots whether to include shared libraries from roots, even if they prefer * static linkage. * @return a mapping of library name to the library {@link SourcePath}. */ public static <T> ImmutableSortedMap<String, SourcePath> getTransitiveSharedLibraries(CxxPlatform cxxPlatform, ActionGraphBuilder graphBuilder, Iterable<? extends T> inputs, Function<? super T, Optional<Iterable<? extends T>>> passthrough, boolean alwaysIncludeRoots) { ImmutableMap<BuildTarget, NativeLinkable> roots = getNativeLinkableRoots(inputs, passthrough); ImmutableMap<BuildTarget, NativeLinkable> nativeLinkables = getTransitiveNativeLinkables(cxxPlatform, graphBuilder, roots.values()); SharedLibrariesBuilder builder = new SharedLibrariesBuilder(); nativeLinkables.entrySet().stream().filter( e -> e.getValue().getPreferredLinkage(cxxPlatform, graphBuilder) != NativeLinkable.Linkage.STATIC || (alwaysIncludeRoots && roots.containsKey(e.getKey()))) .forEach(e -> builder.add(cxxPlatform, e.getValue(), graphBuilder)); return builder.build(); }
From source file:com.facebook.buck.features.haskell.HaskellGhciDescription.java
/** Whether the nativeLinkable should be linked shared or othewise */ public static boolean isPrebuiltSO(NativeLinkable nativeLinkable, CxxPlatform cxxPlatform, ActionGraphBuilder graphBuilder) { if (nativeLinkable instanceof PrebuiltCxxLibraryGroupDescription.CustomPrebuiltCxxLibrary) { return true; }// w w w . j a va 2s. c o m if (!(nativeLinkable instanceof PrebuiltCxxLibrary)) { return false; } ImmutableMap<String, SourcePath> sharedLibraries = nativeLinkable.getSharedLibraries(cxxPlatform, graphBuilder); for (Map.Entry<String, SourcePath> ent : sharedLibraries.entrySet()) { if (!(ent.getValue() instanceof PathSourcePath)) { return false; } } return true; }
From source file:io.mesosphere.mesos.frameworks.cassandra.scheduler.CassandraScheduler.java
@NotNull @VisibleForTesting/* w ww .j a v a 2 s . c o m*/ static List<Resource> ports(@NotNull final Iterable<Long> ports, @NotNull final String mesosRole, Offer offer) { final ListMultimap<String, Resource> resourcesForRoleAndOffer = resourcesForRoleAndOffer(mesosRole, offer); ImmutableMap<String, Collection<Long>> portsByRole = from(ports).index(byRole(resourcesForRoleAndOffer)) .asMap(); return from(portsByRole.entrySet()).transform(roleAndPortsToResource()).toList(); }
From source file:no.ssb.vtl.model.DataStructure.java
private static IdentityHashMap<Component, String> computeInverseCache( ImmutableMap<String, Component> delegate) { IdentityHashMap<Component, String> map = Maps.newIdentityHashMap(); for (Entry<String, Component> entry : delegate.entrySet()) { map.put(entry.getValue(), entry.getKey()); }/*w ww.j ava 2 s. c o m*/ return map; }