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

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

Introduction

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

Prototype

public final ImmutableSet<Entry<K, V>> entrySet() 

Source Link

Usage

From source file:com.google.devtools.build.lib.packages.WorkspaceFactory.java

private static ClassObject newNativeModule(ImmutableMap<String, BaseFunction> workspaceFunctions,
        String version) {/*from ww  w.ja  v  a 2s .c o m*/
    ImmutableMap.Builder<String, Object> builder = new ImmutableMap.Builder<>();
    for (String nativeFunction : Runtime.getFunctionNames(SkylarkNativeModule.class)) {
        builder.put(nativeFunction, Runtime.getFunction(SkylarkNativeModule.class, nativeFunction));
    }
    for (Map.Entry<String, BaseFunction> function : workspaceFunctions.entrySet()) {
        builder.put(function.getKey(), function.getValue());
    }

    builder.put("bazel_version", version);
    return SkylarkClassObjectConstructor.STRUCT.create(builder.build(), "no native function or rule '%s'");
}

From source file:net.oneandone.troilus.WriteQueryDataImpl.java

private static Map<Object, Object> toStatementValue(UDTValueMapper udtValueMapper, Tablename tablename,
        String name, ImmutableMap<Object, Optional<Object>> map) {
    Map<Object, Object> m = Maps.newHashMap();
    for (Entry<Object, Optional<Object>> entry : map.entrySet()) {
        m.put(toStatementValue(udtValueMapper, tablename, name,
                toStatementValue(udtValueMapper, tablename, name, entry.getKey())),
                toStatementValue(udtValueMapper, tablename, name, entry.getValue().orNull()));
    }//from   www .ja v a 2 s . c  om
    return m;
}

From source file:org.apache.rya.indexing.smarturi.SmartUriAdapter.java

private static URI createTypePropertiesUri(
        final ImmutableMap<RyaURI, ImmutableMap<RyaURI, Property>> typeProperties) throws SmartUriException {
    final List<NameValuePair> nameValuePairs = new ArrayList<>();
    for (final Entry<RyaURI, ImmutableMap<RyaURI, Property>> typeProperty : typeProperties.entrySet()) {
        final RyaURI type = typeProperty.getKey();
        final Map<RyaURI, Property> propertyMap = typeProperty.getValue();
        final URI typeUri = createIndividualTypeWithPropertiesUri(type, propertyMap);
        final String keyString = type.getDataType().getLocalName();
        final String valueString = typeUri.getLocalName();
        nameValuePairs.add(new BasicNameValuePair(keyString, valueString));
    }//from w w w.j  a v a2s.c  o m

    final URIBuilder uriBuilder = new URIBuilder();
    uriBuilder.addParameters(nameValuePairs);

    String uriString;
    try {
        final java.net.URI uri = uriBuilder.build();
        final String queryString = uri.getRawSchemeSpecificPart();
        uriString = "urn:test" + queryString;
    } catch (final URISyntaxException e) {
        throw new SmartUriException("Unable to create type properties for the Smart URI", e);
    }

    return new URIImpl(uriString);
}

From source file:com.spectralogic.ds3autogen.utils.ConverterUtil.java

/**
 * Removes all unused types from the Ds3Type map. Types are considered to be used if
 * they are used within a Ds3Request, and/or if they are used within another type that
 * is also used./*from   w  w w .j  a va 2s  .c  o  m*/
 * @param types A Ds3Type map
 * @param requests A list of Ds3Requests
 */
public static ImmutableMap<String, Ds3Type> removeUnusedTypes(final ImmutableMap<String, Ds3Type> types,
        final ImmutableList<Ds3Request> requests) {
    if (isEmpty(types) || isEmpty(requests)) {
        return ImmutableMap.of();
    }

    final ImmutableSet.Builder<String> usedTypesBuilder = ImmutableSet.builder();
    usedTypesBuilder.addAll(getUsedTypesFromRequests(requests));
    usedTypesBuilder.addAll(getUsedTypesFromAllTypes(types, usedTypesBuilder.build()));
    final ImmutableSet<String> usedTypes = usedTypesBuilder.build();

    final ImmutableMap.Builder<String, Ds3Type> builder = ImmutableMap.builder();
    for (final Map.Entry<String, Ds3Type> entry : types.entrySet()) {
        if (usedTypes.contains(entry.getKey())) {
            builder.put(entry.getKey(), entry.getValue());
        }
    }
    return builder.build();
}

From source file:com.google.devtools.build.lib.bazel.rules.android.ndkcrosstools.r15.AndroidNdkCrosstoolsR15.java

private static ImmutableList<DefaultCpuToolchain> getDefaultCpuToolchains(StlImpl stlImpl,
        String clangVersion) {//from  w  w  w  . j av a 2  s . 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", "arm-linux-androideabi-clang" + clangVersion)
            .put("armeabi-v7a", "arm-linux-androideabi-clang" + clangVersion + "-v7a")
            .put("arm64-v8a", "aarch64-linux-android-clang" + clangVersion)

            // mips
            .put("mips", "mipsel-linux-android-clang" + clangVersion)
            .put("mips64", "mips64el-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:com.facebook.buck.cxx.CxxGenruleDescription.java

public static <T> ImmutableMap<T, SourcePath> fixupSourcePaths(BuildRuleResolver ruleResolver,
        SourcePathRuleFinder ruleFinder, CxxPlatform cxxPlatform, ImmutableMap<T, SourcePath> paths)
        throws NoSuchBuildTargetException {
    ImmutableMap.Builder<T, SourcePath> fixed = ImmutableMap.builder();
    for (Map.Entry<T, SourcePath> ent : paths.entrySet()) {
        fixed.put(ent.getKey(), fixupSourcePath(ruleResolver, ruleFinder, cxxPlatform, ent.getValue()));
    }//from   www. java  2s .  c  o  m
    return fixed.build();
}

From source file:com.facebook.buck.apple.AppleBundle.java

static ImmutableMap<String, String> withDefaults(ImmutableMap<String, String> map,
        ImmutableMap<String, String> defaults) {
    ImmutableMap.Builder<String, String> builder = ImmutableMap.<String, String>builder().putAll(map);
    for (ImmutableMap.Entry<String, String> entry : defaults.entrySet()) {
        if (!map.containsKey(entry.getKey())) {
            builder = builder.put(entry.getKey(), entry.getValue());
        }//  www. j av a  2s .  com
    }
    return builder.build();
}

From source file:com.facebook.buck.artifact_cache.SQLiteArtifactCache.java

@VisibleForTesting
static byte[] marshalMetadata(ImmutableMap<String, String> metadata) throws IOException {
    ByteArrayOutputStream metadataStream = new ByteArrayOutputStream();
    try (DataOutputStream out = new DataOutputStream(metadataStream)) {
        out.writeInt(metadata.size());//from   ww w .j a va2 s . c  o m
        for (Map.Entry<String, String> entry : metadata.entrySet()) {
            out.writeUTF(entry.getKey());
            byte[] value = entry.getValue().getBytes(Charsets.UTF_8);
            out.writeInt(value.length);
            out.write(value);
        }
    }
    return metadataStream.toByteArray();
}

From source file:com.facebook.buck.cxx.Omnibus.java

protected static OmnibusRoot createRoot(BuildRuleParams params, BuildRuleResolver ruleResolver,
        SourcePathResolver pathResolver, SourcePathRuleFinder ruleFinder, CxxBuckConfig cxxBuckConfig,
        CxxPlatform cxxPlatform, ImmutableList<? extends Arg> extraLdflags, OmnibusSpec spec,
        SourcePath omnibus, NativeLinkTarget root, BuildTarget rootTargetBase, Optional<Path> output)
        throws NoSuchBuildTargetException {

    ImmutableList.Builder<Arg> argsBuilder = ImmutableList.builder();

    // Add any extra flags to the link.
    argsBuilder.addAll(extraLdflags);//from   w w w  . j  av  a 2 s  .  c o  m

    // Since the dummy omnibus library doesn't actually contain any symbols, make sure the linker
    // won't drop its runtime reference to it.
    argsBuilder
            .addAll(StringArg.from(cxxPlatform.getLd().resolve(ruleResolver).getNoAsNeededSharedLibsFlags()));

    // Since we're linking against a dummy libomnibus, ignore undefined symbols.
    argsBuilder
            .addAll(StringArg.from(cxxPlatform.getLd().resolve(ruleResolver).getIgnoreUndefinedSymbolsFlags()));

    // Add the args for the root link target first.
    NativeLinkableInput input = root.getNativeLinkTargetInput(cxxPlatform);
    argsBuilder.addAll(input.getArgs());

    // Grab a topologically sorted mapping of all the root's deps.
    ImmutableMap<BuildTarget, NativeLinkable> deps = NativeLinkables.getNativeLinkables(cxxPlatform,
            root.getNativeLinkTargetDeps(cxxPlatform), Linker.LinkableDepType.SHARED);

    // Now process the dependencies in topological order, to assemble the link line.
    boolean alreadyAddedOmnibusToArgs = false;
    for (Map.Entry<BuildTarget, NativeLinkable> entry : deps.entrySet()) {
        BuildTarget target = entry.getKey();
        NativeLinkable nativeLinkable = entry.getValue();
        Linker.LinkableDepType linkStyle = NativeLinkables
                .getLinkStyle(nativeLinkable.getPreferredLinkage(cxxPlatform), Linker.LinkableDepType.SHARED);

        // If this dep needs to be linked statically, then we always link it directly.
        if (linkStyle != Linker.LinkableDepType.SHARED) {
            Preconditions.checkState(linkStyle == Linker.LinkableDepType.STATIC_PIC);
            argsBuilder.addAll(nativeLinkable.getNativeLinkableInput(cxxPlatform, linkStyle).getArgs());
            continue;
        }

        // If this dep is another root node, substitute in the custom linked library we built for it.
        if (spec.getRoots().containsKey(target)) {
            argsBuilder.add(new SourcePathArg(pathResolver,
                    new BuildTargetSourcePath(getRootTarget(params.getBuildTarget(), target))));
            continue;
        }

        // If we're linking this dep from the body, then we need to link via the giant merged
        // libomnibus instead.
        if (spec.getBody().containsKey(target)) { // && linkStyle == Linker.LinkableDepType.SHARED) {
            if (!alreadyAddedOmnibusToArgs) {
                argsBuilder.add(new SourcePathArg(pathResolver, omnibus));
                alreadyAddedOmnibusToArgs = true;
            }
            continue;
        }

        // Otherwise, this is either an explicitly statically linked or excluded node, so link it
        // normally.
        Preconditions.checkState(spec.getExcluded().containsKey(target));
        argsBuilder.addAll(nativeLinkable.getNativeLinkableInput(cxxPlatform, linkStyle).getArgs());
    }

    // Create the root library rule using the arguments assembled above.
    BuildTarget rootTarget = getRootTarget(params.getBuildTarget(), rootTargetBase);
    NativeLinkTargetMode rootTargetMode = root.getNativeLinkTargetMode(cxxPlatform);
    CxxLink rootLinkRule;
    switch (rootTargetMode.getType()) {

    // Link the root as a shared library.
    case SHARED: {
        Optional<String> rootSoname = rootTargetMode.getLibraryName();
        rootLinkRule = CxxLinkableEnhancer
                .createCxxLinkableSharedBuildRule(cxxBuckConfig, cxxPlatform, params, ruleResolver,
                        pathResolver, ruleFinder, rootTarget,
                        output.orElse(BuildTargets.getGenPath(params.getProjectFilesystem(), rootTarget, "%s")
                                .resolve(rootSoname.orElse(String.format("%s.%s", rootTarget.getShortName(),
                                        cxxPlatform.getSharedLibraryExtension())))),
                        rootSoname, argsBuilder.build());
        break;
    }

    // Link the root as an executable.
    case EXECUTABLE: {
        rootLinkRule = CxxLinkableEnhancer.createCxxLinkableBuildRule(cxxBuckConfig, cxxPlatform, params,
                ruleResolver, pathResolver, ruleFinder, rootTarget,
                output.orElse(BuildTargets.getGenPath(params.getProjectFilesystem(), rootTarget, "%s")
                        .resolve(rootTarget.getShortName())),
                argsBuilder.build(), Linker.LinkableDepType.SHARED, Optional.empty());
        break;
    }

    // $CASES-OMITTED$
    default:
        throw new IllegalStateException(String.format("%s: unexpected omnibus root type: %s %s",
                params.getBuildTarget(), root.getBuildTarget(), rootTargetMode.getType()));

    }

    ruleResolver.addToIndex(rootLinkRule);
    return OmnibusRoot.of(new BuildTargetSourcePath(rootTarget));
}

From source file:com.facebook.buck.artifact_cache.HttpArtifactCacheBinaryProtocol.java

@VisibleForTesting
static byte[] createMetadataHeader(ImmutableSet<RuleKey> ruleKeys, ImmutableMap<String, String> metadata,
        ByteSource data) throws IOException {

    ByteArrayOutputStream rawOut = new ByteArrayOutputStream();
    Hasher hasher = HASH_FUNCTION.newHasher();
    try (DataOutputStream out = new DataOutputStream(new HasherOutputStream(hasher, rawOut))) {

        // Write the rule keys to the raw metadata, including them in the end-to-end checksum.
        out.writeInt(ruleKeys.size());//from  w w w. ja v a  2 s.  c om
        for (RuleKey ruleKey : ruleKeys) {
            out.writeUTF(ruleKey.toString());
        }

        // Write out the metadata map to the raw metadata, including it in the end-to-end checksum.
        out.writeInt(metadata.size());
        for (Map.Entry<String, String> ent : metadata.entrySet()) {
            out.writeUTF(ent.getKey());
            byte[] val = ent.getValue().getBytes(Charsets.UTF_8);
            out.writeInt(val.length);
            out.write(val);
            if (out.size() > MAX_METADATA_HEADER_SIZE) {
                throw new IOException("Metadata header too big.");
            }
        }
    }

    // Add the file data contents to the end-to-end checksum.
    data.copyTo(new HasherOutputStream(hasher, ByteStreams.nullOutputStream()));

    // Finish the checksum, adding it to the raw metadata
    rawOut.write(hasher.hash().asBytes());

    // Finally, base64 encode the raw bytes to make usable in a HTTP header.
    byte[] bytes = rawOut.toByteArray();
    if (bytes.length > MAX_METADATA_HEADER_SIZE) {
        throw new IOException("Metadata header too big.");
    }
    return bytes;
}