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

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

Introduction

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

Prototype

V get(Object key);

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

From source file:org.openengsb.core.services.internal.deployer.connector.ConnectorFile.java

public ChangeSet getChanges(File file) {
    ImmutableMap<String, String> newPropertyMap = readProperties(file);

    MapDifference<String, String> changedAttributes = Maps.difference(attributes,
            getAttributesFromMap(newPropertyMap));
    MapDifference<String, Object> changedProperties = Maps.difference(properties,
            getPropertiesFromMap(newPropertyMap));

    return new ChangeSet(newPropertyMap.get("domainType"), newPropertyMap.get("connectorType"),
            changedAttributes, changedProperties);
}

From source file:com.facebook.buck.distributed.DistBuildTargetGraphCodec.java

public TargetGraph createTargetGraph(BuildJobStateTargetGraph remoteTargetGraph,
        Function<Integer, Cell> cellLookup) throws IOException {

    ImmutableMap.Builder<BuildTarget, TargetNode<?, ?>> targetNodeIndexBuilder = ImmutableMap.builder();

    for (BuildJobStateTargetNode remoteNode : remoteTargetGraph.getNodes()) {
        Cell cell = cellLookup.apply(remoteNode.getCellIndex());
        ProjectFilesystem projectFilesystem = cell.getFilesystem();
        BuildTarget target = decodeBuildTarget(remoteNode.getBuildTarget(), cell);

        @SuppressWarnings("unchecked")
        Map<String, Object> rawNode = objectMapper.readValue(remoteNode.getRawNode(), Map.class);
        Path buildFilePath = projectFilesystem.resolve(target.getBasePath()).resolve(cell.getBuildFileName());

        TargetNode<?, ?> targetNode = parserTargetNodeFactory.createTargetNode(cell, buildFilePath, target,
                rawNode, input -> SimplePerfEvent.scope(Optional.empty(), input));
        targetNodeIndexBuilder.put(targetNode.getBuildTarget(), targetNode);
    }//from ww w. j a  v a2  s. c o  m
    ImmutableMap<BuildTarget, TargetNode<?, ?>> targetNodeIndex = targetNodeIndexBuilder.build();

    MutableDirectedGraph<TargetNode<?, ?>> mutableTargetGraph = new MutableDirectedGraph<>();
    for (TargetNode<?, ?> targetNode : targetNodeIndex.values()) {
        mutableTargetGraph.addNode(targetNode);
        for (BuildTarget dep : targetNode.getDeps()) {
            mutableTargetGraph.addEdge(targetNode, Preconditions.checkNotNull(targetNodeIndex.get(dep)));
        }
    }

    // TODO(csarbora): make this work with TargetGroups
    return new TargetGraph(mutableTargetGraph, targetNodeIndex, ImmutableSet.of());
}

From source file:org.apache.bigtop.bigpetstore.datagenerator.generators.locations.ZipcodeReader.java

public ImmutableList<Location> readData() throws FileNotFoundException {
    ImmutableMap<String, Double> incomes = readIncomeData(this.zipcodeIncomesFile);
    ImmutableMap<String, Long> populations = readPopulationData(this.zipcodePopulationFile);
    ImmutableMap<String, ZipcodeLocationRecord> coordinates = readCoordinates(this.zipcodeCoordinatesFile);

    Set<String> zipcodeSubset = new HashSet<String>(incomes.keySet());
    zipcodeSubset.retainAll(populations.keySet());
    zipcodeSubset.retainAll(coordinates.keySet());

    List<Location> table = new Vector<Location>();
    for (String zipcode : zipcodeSubset) {
        Location record = new Location(zipcode, coordinates.get(zipcode).coordinates,
                coordinates.get(zipcode).city, coordinates.get(zipcode).state, incomes.get(zipcode),
                populations.get(zipcode));
        table.add(record);/*from   w w w.ja  v a  2 s  .  com*/
    }

    return ImmutableList.copyOf(table);
}

From source file:org.zanata.client.BashCompletionGenerator.java

public BashCompletionGenerator() {
    ImmutableMap<String, Class<BasicOptions>> commands = ZanataClient.OPTIONS;
    baseCommands = ImmutableList.copyOf(commands.keySet());
    commandName = ZanataClient.COMMAND_NAME;
    commandDescription = ZanataClient.COMMAND_DESCRIPTION;
    genericOptions = getOptions(ZanataClient.class);
    allOptions.addAll(genericOptions);//from   ww w  .ja v a2 s.co m

    for (String commandName : commands.keySet()) {
        List<Option> options = getOptions(commands.get(commandName));
        // do we still want generic options to appear?
        // options.removeAll(genericOptions);
        commandOptions.put(commandName, options);
        allOptions.addAll(options);
    }
}

From source file:com.github.steveash.typedconfig.resolver.ProxyValueResolver.java

private boolean proxyEquals(Class<?> thisIface, ImmutableMap<Method, ValueResolver> thisResolvers,
        Object that) {//from  www. jav a  2s . co m

    if (!(that instanceof ProxiedConfiguration))
        return false;
    ProxiedConfiguration thatConfig = ((ProxiedConfiguration) that);

    Class<?> thatIface = thatConfig.getInterfaceClass();
    if (!thisIface.equals(thatIface))
        return false;

    ImmutableMap<Method, ValueResolver> thatResolvers = thatConfig.getResolvers();
    if (thisResolvers.size() != thatResolvers.size())
        throw new IllegalStateException("not sure how the same iface can have different resolver map");

    for (Entry<Method, ValueResolver> thisEntry : thisResolvers.entrySet()) {
        Object thisValue = thisEntry.getValue().resolve();
        Object thatValue = thatResolvers.get(thisEntry.getKey()).resolve();
        if (!thisValue.equals(thatValue))
            return false;
    }

    return true;
}

From source file:com.siemens.sw360.importer.ComponentImportUtils.java

public static RequestSummary writeAttachmentsToDatabase(
        FluentIterable<ComponentAttachmentCSVRecord> compCSVRecords, User user,
        ComponentService.Iface componentClient, AttachmentService.Iface attachmentClient) throws TException {

    final List<Component> componentDetailedSummaryForExport = componentClient
            .getComponentDetailedSummaryForExport();
    final ImmutableMap<String, Component> componentsByName = getComponentsByName(
            componentDetailedSummaryForExport);
    final Map<String, Release> releasesByIdentifier = getReleasesByIdentifier(
            componentDetailedSummaryForExport);

    final Set<String> usedAttachmentContentIds = componentClient.getUsedAttachmentContentIds();

    final Set<String> releaseIdentifiersToUpdate = new HashSet<>();
    final Set<String> componentsToUpdate = new HashSet<>();
    final Set<Attachment> attachmentStubsToDelete = new HashSet<>();

    for (ComponentAttachmentCSVRecord compCSVRecord : compCSVRecords) {
        if (compCSVRecord.isSaveableAttachment()) {
            final Attachment attachment = compCSVRecord.getAttachment();

            if (usedAttachmentContentIds.contains(attachment.getAttachmentContentId()))
                continue;

            if (compCSVRecord.isForComponent()) {
                final Component component = componentsByName.get(compCSVRecord.getComponentName());
                if (component != null) {
                    component.addToAttachments(attachment);
                    componentsToUpdate.add(component.getName());
                }//from w  ww.  j  av  a2s  .  c o m
            } else if (compCSVRecord.isForRelease()) {
                final Release release = releasesByIdentifier.get(compCSVRecord.getReleaseIdentifier());
                if (release != null) {

                    attachmentStubsToDelete
                            .addAll(removeAutogeneratedAttachments(attachmentClient, attachment, release));
                    release.addToAttachments(attachment);
                    releaseIdentifiersToUpdate.add(compCSVRecord.getReleaseIdentifier());

                }
            }
        }
    }

    final HashSet<Release> updatedReleases = getUpdatedReleases(releasesByIdentifier,
            releaseIdentifiersToUpdate);
    final RequestSummary releaseRequestSummary = componentClient.updateReleases(updatedReleases, user);

    final HashSet<Component> updatedComponents = Sets
            .newHashSet(Maps.filterKeys(componentsByName, new Predicate<String>() {
                @Override
                public boolean apply(String input) {
                    return componentsToUpdate.contains(input);
                }
            }).values());

    final RequestSummary componentRequestSummary = componentClient.updateComponents(updatedComponents, user);

    RequestSummary attachmentSummary = null;
    if (!attachmentStubsToDelete.isEmpty()) {
        attachmentSummary = attachmentClient.bulkDelete(Lists
                .transform(Lists.newArrayList(attachmentStubsToDelete), new Function<Attachment, String>() {
                    @Override
                    public String apply(Attachment input) {
                        return input.getAttachmentContentId();
                    }
                }));
    }

    RequestSummary requestSummary = CommonUtils.addRequestSummaries(releaseRequestSummary, "release",
            componentRequestSummary, "component");

    if (attachmentSummary != null) {
        requestSummary = CommonUtils.addToMessage(requestSummary, attachmentSummary, "attachment deletion");
    }

    return requestSummary;
}

From source file:nl.vumc.biomedbridges.examples.AllExamplesCheck.java

/**
 * Run all examples on a specific Galaxy server.
 *
 * @param serverUrl      the URL of the Galaxy server.
 * @param exampleClasses the example classes to run.
 * @param skipExamples   the examples to skip for specific servers.
 * @return the server report: [server URL]: [successful example count] '/' [attempt count] " [" failures "]".
 *//* ww w . j a v a2  s  .  c  om*/
private String runExamplesOnServer(final String serverUrl,
        final List<Class<? extends AbstractBaseExample>> exampleClasses,
        final ImmutableMap<String, List<Class<? extends AbstractBaseExample>>> skipExamples) {
    logger.warn("Running examples:");
    int successCount = 0;
    int skipCount = 0;
    final List<String> failures = new ArrayList<>();
    for (final Class<? extends AbstractBaseExample> exampleClass : exampleClasses) {
        if (!skipExamples.containsKey(serverUrl) || !skipExamples.get(serverUrl).contains(exampleClass)) {
            if (runExampleOnServer(serverUrl, exampleClass))
                successCount++;
            else
                failures.add(exampleClass.getSimpleName());
        } else {
            logger.warn("- The example {} is skipped for server {}.", exampleClass.getSimpleName(), serverUrl);
            skipCount++;
        }
    }
    logger.warn("");
    final String successRate = String.format("%d/%d", successCount, exampleClasses.size() - skipCount);
    logger.warn("Success rate: {}.", successRate);
    logger.warn("");
    logger.warn("");

    return serverUrl + ": " + successRate + " [" + Joiner.on(", ").join(failures) + "]";
}

From source file:org.voltdb.dtxn.SiteTracker.java

public List<Long> getHSIdsForHost(MailboxType type, int host) {
    ImmutableMap<Integer, ImmutableList<Long>> hostIdList = m_hostsToOtherHSIdsImmutable.get(type);
    if (hostIdList == null) {
        return new ArrayList<Long>();
    }//w ww.j  a  v  a2  s.co  m
    return hostIdList.get(host);
}

From source file:org.apache.flume.plugins.KafkaSink.java

@Override
public void configure(Context context) {
    this.context = context;
    ImmutableMap<String, String> props = context.getParameters();

    // base: producer.sinks.r
    //??Flume-Agentflume-conf.properties??:
    //bin/flume-ng agent --conf conf --conf-file conf/flume-conf.properties --name producer
    //--name, ??producerproducer.sinks.r
    parameters = new Properties();
    for (String key : props.keySet()) {
        String value = props.get(key);
        this.parameters.put(key, value);
    }/*w w  w  .j  av a  2  s .  c  om*/
}

From source file:org.apache.bigtop.bigpetstore.datagenerator.datareaders.ZipcodeReader.java

public ImmutableList<ZipcodeRecord> readData() throws FileNotFoundException {
    ImmutableMap<String, Double> incomes = readIncomeData(this.zipcodeIncomesFile);
    ImmutableMap<String, Long> populations = readPopulationData(this.zipcodePopulationFile);
    ImmutableMap<String, ZipcodeLocationRecord> coordinates = readCoordinates(this.zipcodeCoordinatesFile);

    Set<String> zipcodeSubset = new HashSet<String>(incomes.keySet());
    zipcodeSubset.retainAll(populations.keySet());
    zipcodeSubset.retainAll(coordinates.keySet());

    List<ZipcodeRecord> table = new Vector<ZipcodeRecord>();
    for (String zipcode : zipcodeSubset) {
        ZipcodeRecord record = new ZipcodeRecord(zipcode, coordinates.get(zipcode).coordinates,
                coordinates.get(zipcode).city, coordinates.get(zipcode).state, incomes.get(zipcode),
                populations.get(zipcode));
        table.add(record);/*from  w w w  .  ja v a2  s .com*/
    }

    return ImmutableList.copyOf(table);
}