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

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

Introduction

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

Prototype

public ImmutableSet<K> keySet() 

Source Link

Usage

From source file:com.google.devtools.build.lib.remote.RemoteSpawnRunner.java

private Command buildCommand(List<String> arguments, ImmutableMap<String, String> environment) {
    Command.Builder command = Command.newBuilder();
    command.addAllArgv(arguments);//  ww w. j  a  v a 2  s.c om
    // Sorting the environment pairs by variable name.
    TreeSet<String> variables = new TreeSet<>(environment.keySet());
    for (String var : variables) {
        command.addEnvironmentBuilder().setVariable(var).setValue(environment.get(var));
    }
    return command.build();
}

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

@Override
public void appendToRuleKey(RuleKeyObjectSink sink) {
    // If a sanitizer is being used for compilation, we need to record the working directory in
    // the rule key, as changing this changes the generated object file.
    if (operation == CxxPreprocessAndCompileStep.Operation.PREPROCESS_AND_COMPILE) {
        sink.setReflectively("compilationDirectory", compilerSanitizer.getCompilationDirectory());
    }//from  w  w  w. j av  a  2  s. co  m
    if (sandboxTree.isPresent()) {
        ImmutableMap<Path, SourcePath> links = sandboxTree.get().getLinks();
        for (Path path : ImmutableSortedSet.copyOf(links.keySet())) {
            SourcePath source = links.get(path);
            sink.setReflectively("sandbox(" + path.toString() + ")", source);
        }
    }
}

From source file:google.registry.xml.XmlTransformer.java

/**
 * Create a new XmlTransformer that validates using the given schemas and marshals to and from
 * classes generated off of those schemas.
 *
 * @param schemaNamesToFilenames map of schema names to filenames, immutable because ordering is
 *        significant and ImmutableMap preserves insertion order. The filenames are relative to
 *        this package.//ww  w  . ja v a2  s.c o m
 */
public XmlTransformer(Package pakkage, ImmutableMap<String, String> schemaNamesToFilenames) {
    try {
        this.jaxbContext = initJaxbContext(pakkage, schemaNamesToFilenames.keySet());
        this.schema = loadXmlSchemas(ImmutableList.copyOf(schemaNamesToFilenames.values()));
    } catch (JAXBException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.onos.yangtools.yang.parser.impl.util.URLSchemaContextResolver.java

/**
 * Try to parse all currently available yang files and build new schema context.
 * @return new schema context iif there is at least 1 yang file registered and new schema context was successfully built.
 *///from  w w w  .  ja va 2  s. c om
public synchronized Optional<SchemaContext> tryToUpdateSchemaContext() {
    if (availableSources.isEmpty()) {
        return Optional.absent();
    }
    ImmutableMap<SourceIdentifier, SourceContext> actualSources = ImmutableMap.copyOf(availableSources);
    Builder<SourceIdentifier, YangModelDependencyInfo> builder = ImmutableMap
            .<SourceIdentifier, YangModelDependencyInfo>builder();
    for (Entry<SourceIdentifier, SourceContext> entry : actualSources.entrySet()) {
        builder.put(entry.getKey(), entry.getValue().getDependencyInfo());
    }
    ImmutableMap<SourceIdentifier, YangModelDependencyInfo> sourcesMap = builder.build();
    YangSourceContext yangSourceContext = YangSourceContext.createFrom(sourcesMap, this);
    LOG.debug("Trying to create schema context from {}", sourcesMap.keySet());

    if (!yangSourceContext.getMissingDependencies().isEmpty()) {
        LOG.debug("Omitting {} because of unresolved dependencies",
                yangSourceContext.getMissingDependencies().keySet());
        LOG.debug("Missing model sources for {}", yangSourceContext.getMissingSources());
    }
    if (currentSourceContext == null
            || !yangSourceContext.getValidSources().equals(currentSourceContext.getValidSources())) {
        try {
            Collection<ByteSource> byteSources = yangSourceContext.getValidByteSources();
            YangParserImpl parser = YangParserImpl.getInstance();
            SchemaContext schemaContext = parser.parseSources(byteSources);
            currentSchemaContext = Optional.of(schemaContext);
            currentSourceContext = yangSourceContext;
            return Optional.of(schemaContext);
        } catch (Exception e) {
            LOG.error("Could not create schema context for {} ", yangSourceContext.getValidSources(), e);
            return Optional.absent();
        }
    } else {
        currentSourceContext = yangSourceContext;
        return Optional.absent();
    }
}

From source file:org.opendaylight.yangtools.yang.parser.impl.util.URLSchemaContextResolver.java

/**
 * Try to parse all currently available yang files and build new schema context.
 * @return new schema context iif there is at least 1 yang file registered and new schema context was successfully built.
 *//*  www  . j ava  2 s .c o  m*/
public synchronized Optional<SchemaContext> tryToUpdateSchemaContext() {
    if (availableSources.isEmpty()) {
        return Optional.absent();
    }
    ImmutableMap<SourceIdentifier, SourceContext> actualSources = ImmutableMap.copyOf(availableSources);
    Builder<SourceIdentifier, YangModelDependencyInfo> builder = ImmutableMap
            .<SourceIdentifier, YangModelDependencyInfo>builder();
    for (Entry<SourceIdentifier, SourceContext> entry : actualSources.entrySet()) {
        builder.put(entry.getKey(), entry.getValue().getDependencyInfo());
    }
    ImmutableMap<SourceIdentifier, YangModelDependencyInfo> sourcesMap = builder.build();
    YangSourceContext yangSourceContext = YangSourceContext.createFrom(sourcesMap, this);
    LOG.debug("Trying to create schema context from {}", sourcesMap.keySet());

    if (yangSourceContext.getMissingDependencies().size() != 0) {
        LOG.debug("Omitting {} because of unresolved dependencies",
                yangSourceContext.getMissingDependencies().keySet());
        LOG.debug("Missing model sources for {}", yangSourceContext.getMissingSources());
    }
    if (currentSourceContext == null
            || !yangSourceContext.getValidSources().equals(currentSourceContext.getValidSources())) {
        try {
            Collection<ByteSource> byteSources = yangSourceContext.getValidByteSources();
            YangParserImpl parser = YangParserImpl.getInstance();
            SchemaContext schemaContext = parser.parseSources(byteSources);
            currentSchemaContext = Optional.of(schemaContext);
            currentSourceContext = yangSourceContext;
            return Optional.of(schemaContext);
        } catch (Exception e) {
            LOG.error("Could not create schema context for {} ", yangSourceContext.getValidSources(), e);
            return Optional.absent();
        }
    } else {
        currentSourceContext = yangSourceContext;
        return Optional.absent();
    }
}

From source file:com.edmunds.zookeeper.treewatcher.ZooKeeperTreeDelta.java

private void walkTree(ZooKeeperTreeNode oldNode, ZooKeeperTreeNode newNode, ZooKeeperTreeDeltaResult result) {

    final ImmutableMap<String, ZooKeeperTreeNode> oldChildren = oldNode.getChildren();
    final ImmutableMap<String, ZooKeeperTreeNode> newChildren = newNode.getChildren();

    final ImmutableSet<String> oldKeys = oldChildren.keySet();
    final ImmutableSet<String> newKeys = newChildren.keySet();

    // Special case if the user has asked for a leaf first walk.
    if (walkPrimary == LEAF_FIRST) {
        walkChildren(oldChildren, newChildren, result);
    }//from   ww  w. j av  a2  s  .co  m

    // Calculate which nodes have been inserted.
    for (ZooKeeperTreeNode node : Maps.filterKeys(newChildren, not(in(oldKeys))).values()) {
        addNode(walkInserted, INSERT, node, result);
    }

    // The primary walk will change the order for updates so always use ROOT_ONLY
    if (!Arrays.equals(oldNode.getData(), newNode.getData())) {
        addNode(ROOT_ONLY, UPDATE, newNode, result);
    }

    // Calculate the deleted nodes.
    for (ZooKeeperTreeNode node : Maps.filterKeys(oldChildren, not(in(newKeys))).values()) {
        addNode(walkDeleted, DELETE, node, result);
    }

    // This is the normal case.
    if (walkPrimary == ROOT_FIRST) {
        walkChildren(oldChildren, newChildren, result);
    }
}

From source file:hmi.facegraphics.HMIFaceController.java

/**
 * NOTE: this function should be called in some synchronisation; to ensure that the values are not changed during the copy method!
 *//*from  ww w.j  a  v a  2  s.com*/
public synchronized void copy() {
    if (glHead != null) {
        // send the new MPEG4 configuration
        for (FAP fap : MPEG4.getFAPs().values()) {
            Integer value = currentConfig.getValue(fap.getIndex());
            if (value == null)
                continue;
            glHead.getDeformer(fap).setValue(value);
        }
        glHead.deformWhenScheduled();
    }

    ImmutableMap<String, Float> desiredMorphTargets = morphTargetHandler.getDesiredMorphTargets();
    String[] targetNames = new String[desiredMorphTargets.size()];
    float[] targetWeights = new float[desiredMorphTargets.size()];
    int i = 0;
    for (String targetName : desiredMorphTargets.keySet()) {
        targetNames[i] = targetName;
        targetWeights[i] = desiredMorphTargets.get(targetName);
        i++;
    }
    theGLScene.setMorphTargets(targetNames, targetWeights);
}

From source file:com.sourceclear.headlines.impl.CspDirectives.java

private String formatDirectives(ImmutableMap<String, ImmutableList<String>> directives) {

    // In the case of an empty map return the empty string:
    if (directives.isEmpty()) {
        return "";
    }//from  w  ww. j  ava  2  s  . c om

    StringBuilder sb = new StringBuilder();

    // Outer loop - loop through each directive
    for (String directive : directives.keySet()) {

        // Don't add a directive if it has zero elements
        if (directives.get(directive).size() == 0) {
            continue;
        }

        StringBuilder elements = new StringBuilder();

        // Inner loop = for each directive build up the element String
        for (String element : directives.get(directive)) {
            elements.append(element).append(" ");
        }

        if (sb.length() > 0) {
            sb.append(" ; ");
        }

        sb.append(directive).append(" ").append(elements.toString().trim());
    }

    return sb.toString().trim();
}

From source file:com.foudroyantfactotum.tool.structure.utility.StructureDefinitionBuilder.java

/**
 * Define what each character represents within the block map
 * @param representation char to unlocal.getZ()ed block name map
 * @exception NullPointerException thrown if block doesn't exist.
 *//*from w w  w  .j  av a 2  s.  c o  m*/
public void assignConstructionDef(ImmutableMap<Character, String> representation) {
    Builder<Character, IBlockState> builder = ImmutableMap.builder();

    for (final Character c : representation.keySet()) {
        final String blockName = representation.get(c);
        final Block block = Block.getBlockFromName(blockName);

        checkNotNull(block, "assignConstructionDef.Block does not exist " + blockName);

        builder.put(c, block.getDefaultState());
    }

    //default
    builder.put(' ', Blocks.AIR.getDefaultState());

    conDef = builder.build();
}

From source file:io.druid.indexing.overlord.setup.FillCapacityWithAffinityWorkerSelectStrategy.java

@Override
public Optional<ImmutableZkWorker> findWorkerForTask(final RemoteTaskRunnerConfig config,
        final ImmutableMap<String, ImmutableZkWorker> zkWorkers, final Task task) {
    // don't run other datasources on affinity workers; we only want our configured datasources to run on them
    ImmutableMap.Builder<String, ImmutableZkWorker> builder = new ImmutableMap.Builder<>();
    for (String workerHost : zkWorkers.keySet()) {
        if (!affinityWorkerHosts.contains(workerHost)) {
            builder.put(workerHost, zkWorkers.get(workerHost));
        }/*from  ww w  .  j ava2 s . co m*/
    }
    ImmutableMap<String, ImmutableZkWorker> eligibleWorkers = builder.build();

    List<String> workerHosts = affinityConfig.getAffinity().get(task.getDataSource());
    if (workerHosts == null) {
        return super.findWorkerForTask(config, eligibleWorkers, task);
    }

    ImmutableMap.Builder<String, ImmutableZkWorker> affinityBuilder = new ImmutableMap.Builder<>();
    for (String workerHost : workerHosts) {
        ImmutableZkWorker zkWorker = zkWorkers.get(workerHost);
        if (zkWorker != null) {
            affinityBuilder.put(workerHost, zkWorker);
        }
    }
    ImmutableMap<String, ImmutableZkWorker> affinityWorkers = affinityBuilder.build();

    if (!affinityWorkers.isEmpty()) {
        Optional<ImmutableZkWorker> retVal = super.findWorkerForTask(config, affinityWorkers, task);
        if (retVal.isPresent()) {
            return retVal;
        }
    }

    return super.findWorkerForTask(config, eligibleWorkers, task);
}