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.zulily.omicron.crontab.Crontab.java

private String getOverrideMapString(final ImmutableMap<ConfigKey, String> overrideMap) {
    return COMMA_JOINER.join(overrideMap.entrySet().stream()
            .map(entry -> entry.getKey().getRawName() + "->" + entry.getValue()).collect(Collectors.toList()));
}

From source file:com.astonish.dropwizard.routing.hibernate.AbstractHibernateDAORouter.java

/**
 * @param sessionFactoryMap/*www  .  ja v  a  2  s .  com*/
 *            map of route keys to their corresponding {@link SessionFactory}.
 * @throws NullPointerException
 *             if sessionFactoryMap is null or any {@link Entry} in sessionFactoryMap has a null value with a
 *             non-null key
 * @throws IllegalStateException
 *             if sessionFactoryMap is empty
 */
public AbstractHibernateDAORouter(final ImmutableMap<String, SessionFactory> sessionFactoryMap) {
    checkNotNull(sessionFactoryMap);
    checkState(!sessionFactoryMap.isEmpty());

    final Map<String, ImmutableMap<Class<?>, Object>> daosByRoute = new LinkedHashMap<>();
    for (Entry<String, SessionFactory> e : sessionFactoryMap.entrySet()) {
        SessionFactory factory = checkNotNull(e.getValue());
        daosByRoute.put(e.getKey(), constructDAOs(factory));
    }

    this.daosByRoute = ImmutableMap.copyOf(daosByRoute);
}

From source file:org.openo.sdno.testframework.moco.responsehandler.MocoResponseHandler.java

@Override
public void writeToResponse(SessionContext context) {

    DefaultHttpRequest inHttpRequest = (DefaultHttpRequest) context.getRequest();
    DefaultMutableHttpResponse outHttpResponse = (DefaultMutableHttpResponse) context.getResponse();

    HttpRequest request = new HttpRequest();
    request.setUri(inHttpRequest.getUri());
    request.setMethod(inHttpRequest.getMethod().toString().toLowerCase());
    request.setHeaders(inHttpRequest.getHeaders());

    ImmutableMap<String, String[]> queryMap = inHttpRequest.getQueries();
    if (null != queryMap) {
        Map<String, String> newMap = new HashMap<String, String>();
        for (Map.Entry<String, String[]> curEntity : queryMap.entrySet()) {
            newMap.put(curEntity.getKey(), curEntity.getValue()[0]);
        }//from  w  w w .  j a va  2s.c o  m
        request.setQueries(newMap);
    }

    request.setData(inHttpRequest.getContent().toString());

    // create new response data
    HttpResponse response = new HttpResponse();
    response.copyBasicData(responseObject);

    HttpRquestResponse httpObject = new HttpRquestResponse(request, response);

    processRequestandResponse(httpObject);

    outHttpResponse.setStatus(response.getStatus());
    Map<String, String> headers = response.getHeaders();
    if (null != headers) {
        for (Map.Entry<String, String> entity : headers.entrySet()) {
            outHttpResponse.addHeader(entity.getKey(), entity.getValue());
        }
    }
    outHttpResponse.setContent(MessageContent.content(response.getData()));
}

From source file:org.apache.james.jmap.methods.SetMailboxesDestructionProcessor.java

public SetMailboxesResponse process(SetMailboxesRequest request, MailboxSession mailboxSession) {
    ImmutableMap<MailboxId, Mailbox> idToMailbox = mapDestroyRequests(request, mailboxSession);

    SetMailboxesResponse.Builder builder = SetMailboxesResponse.builder();
    sortingHierarchicalCollections.sortFromLeafToRoot(idToMailbox.entrySet())
            .forEach(entry -> destroyMailbox(entry, mailboxSession, builder));

    notDestroyedRequests(request, idToMailbox, builder);
    return builder.build();
}

From source file:com.google.devtools.build.lib.skyframe.actiongraph.ActionGraphDump.java

private void dumpSingleAction(ConfiguredTarget configuredTarget, ActionAnalysisMetadata action)
        throws CommandLineExpansionException {
    Preconditions.checkState(configuredTarget instanceof RuleConfiguredTarget);
    RuleConfiguredTarget ruleConfiguredTarget = (RuleConfiguredTarget) configuredTarget;
    AnalysisProtos.Action.Builder actionBuilder = AnalysisProtos.Action.newBuilder()
            .setMnemonic(action.getMnemonic())
            .setTargetId(knownRuleConfiguredTargets.dataToId(ruleConfiguredTarget));

    if (action instanceof ActionExecutionMetadata) {
        ActionExecutionMetadata actionExecutionMetadata = (ActionExecutionMetadata) action;
        actionBuilder.setActionKey(actionExecutionMetadata.getKey(getActionKeyContext()))
                .setDiscoversInputs(actionExecutionMetadata.discoversInputs());
    }/* ww w.  j a  va2  s  .  c om*/

    // store environment
    if (action instanceof SpawnAction) {
        SpawnAction spawnAction = (SpawnAction) action;
        // TODO(twerth): This handles the fixed environment. We probably want to output the inherited
        // environment as well.
        ImmutableMap<String, String> fixedEnvironment = spawnAction.getEnvironment().getFixedEnv();
        for (Map.Entry<String, String> environmentVariable : fixedEnvironment.entrySet()) {
            AnalysisProtos.KeyValuePair.Builder keyValuePairBuilder = AnalysisProtos.KeyValuePair.newBuilder();
            keyValuePairBuilder.setKey(environmentVariable.getKey()).setValue(environmentVariable.getValue());
            actionBuilder.addEnvironmentVariables(keyValuePairBuilder.build());
        }

        if (includeActionCmdLine) {
            actionBuilder.addAllArguments(spawnAction.getArguments());
        }
    }

    ActionOwner actionOwner = action.getOwner();
    if (actionOwner != null) {
        BuildEvent event = actionOwner.getConfiguration();
        actionBuilder.setConfigurationId(knownConfigurations.dataToId(event));

        // store aspect
        for (AspectDescriptor aspectDescriptor : actionOwner.getAspectDescriptors()) {
            actionBuilder.addAspectDescriptorIds(knownAspectDescriptors.dataToId(aspectDescriptor));
        }
    }

    // store inputs
    Iterable<Artifact> inputs = action.getInputs();
    if (!(inputs instanceof NestedSet)) {
        inputs = NestedSetBuilder.wrap(Order.STABLE_ORDER, inputs);
    }
    NestedSetView<Artifact> nestedSetView = new NestedSetView<>((NestedSet<Artifact>) inputs);
    if (nestedSetView.directs().size() > 0 || nestedSetView.transitives().size() > 0) {
        actionBuilder.addInputDepSetIds(knownNestedSets.dataToId(nestedSetView));
    }

    // store outputs
    for (Artifact artifact : action.getOutputs()) {
        actionBuilder.addOutputIds(knownArtifacts.dataToId(artifact));
    }

    actionGraphBuilder.addActions(actionBuilder.build());
}

From source file:com.facebook.buck.python.PexStep.java

private ImmutableMap<Path, Path> getExpandedSourcePaths(ImmutableMap<Path, Path> paths) throws IOException {
    ImmutableMap.Builder<Path, Path> sources = ImmutableMap.builder();

    for (ImmutableMap.Entry<Path, Path> ent : paths.entrySet()) {
        if (ent.getValue().toString().endsWith(SRC_ZIP)) {
            Path destinationDirectory = filesystem.resolve(tempDir.resolve(ent.getKey()));
            Files.createDirectories(destinationDirectory);

            ImmutableList<Path> zipPaths = Unzip.extractZipFile(filesystem.resolve(ent.getValue()),
                    destinationDirectory, Unzip.ExistingFileMode.OVERWRITE);
            for (Path path : zipPaths) {
                Path modulePath = destinationDirectory.relativize(path);
                sources.put(modulePath, path);
            }/*from  ww  w  .java 2 s .co m*/
        } else {
            sources.put(ent.getKey(), ent.getValue());
        }
    }

    return sources.build();
}

From source file:com.google.devtools.build.lib.rules.objc.RuleType.java

/**
 * Generates the String necessary to define a target of this rule type.
 *
 * @param packageDir the package in which to create the target
 * @param name the name of the target/*from   w  w w  . ja  v  a2  s. co  m*/
 * @param checkSpecificAttrs alternating name/values of attributes to add to the rule that are
 *     required for the check being performed to be defined a certain way. Pass
 *     {@link #OMIT_REQUIRED_ATTR} for a value to prevent an attribute from being automatically
 *     defined.
 */
final String target(Scratch scratch, String packageDir, String name, String... checkSpecificAttrs)
        throws IOException {
    ImmutableMap<String, String> checkSpecific = map(checkSpecificAttrs);
    StringBuilder target = new StringBuilder(ruleTypeName).append("(name = '").append(name).append("',");
    for (Map.Entry<String, String> entry : checkSpecific.entrySet()) {
        if (entry.getValue().equals(OMIT_REQUIRED_ATTR)) {
            continue;
        }
        target.append(entry.getKey()).append("=").append(entry.getValue()).append(",");
    }
    Joiner.on(",").appendTo(target, requiredAttributes(scratch, packageDir, checkSpecific.keySet()));
    target.append(')');
    return target.toString();

}

From source file:org.grycap.gpf4med.rest.Gpf4MedResourcePartialImpl.java

@Override
public AvailableGraphs listGraphs() {
    final AvailableGraphs graphs = new AvailableGraphs();
    graphs.setPaths(new ArrayList<String>());
    final ImmutableMap<String, GraphConnector> connectors = GraphConnectorManager.INSTANCE.listConnectors();
    if (connectors != null) {
        for (final Map.Entry<String, GraphConnector> entry : connectors.entrySet()) {
            graphs.getPaths().add(entry.getValue().path());
        }//from w w  w  .j ava2  s  .c  om
    }
    return graphs;
}

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

public <A extends Comparable<?>, B> Optional<ImmutableMap<A, B>> translateMap(ImmutableMap<A, B> val) {
    boolean modified = false;
    ImmutableMap.Builder<A, B> builder = ImmutableMap.builder();
    for (Map.Entry<A, B> ent : val.entrySet()) {
        Optional<A> key = translate(ent.getKey());
        Optional<B> value = translate(ent.getValue());
        modified = modified || key.isPresent() || value.isPresent();
        builder.put(key.orElse(ent.getKey()), value.orElse(ent.getValue()));
    }/*from  ww  w  . j  a  va 2 s  .c om*/
    return modified ? Optional.of(builder.build()) : Optional.empty();
}

From source file:com.facebook.buck.android.StringResources.java

private void writePlurals(DataOutputStream outputStream) throws IOException {
    outputStream.writeInt(plurals.size());
    if (plurals.isEmpty()) {
        return;/*from ww w  .  ja v  a2  s  .c o  m*/
    }
    int previousResourceId = plurals.firstKey();
    outputStream.writeInt(previousResourceId);

    try (ByteArrayOutputStream dataStream = new ByteArrayOutputStream()) {
        for (Map.Entry<Integer, ImmutableMap<String, String>> entry : plurals.entrySet()) {
            writeShort(outputStream, entry.getKey() - previousResourceId);
            ImmutableMap<String, String> categoryMap = entry.getValue();
            outputStream.writeByte(categoryMap.size());

            for (Map.Entry<String, String> cat : categoryMap.entrySet()) {
                outputStream.writeByte(PLURAL_CATEGORY_MAP.get(cat.getKey()).byteValue());
                byte[] pluralValue = getUnescapedStringBytes(cat.getValue());
                writeShort(outputStream, pluralValue.length);
                dataStream.write(pluralValue);
            }

            previousResourceId = entry.getKey();
        }

        outputStream.write(dataStream.toByteArray());
    }
}