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:com.facebook.buck.android.exopackage.NativeExoHelper.java

/**
 * @return a mapping from destinationPathOnDevice -> contents of file for all native-libs metadata
 *     files (one per abi)/*w w w  .  ja  va  2 s . co  m*/
 */
public ImmutableMap<Path, String> getMetadataToInstall() throws IOException {
    ImmutableMap<String, ImmutableMultimap<String, Path>> filesByHashForAbis = getFilesByHashForAbis();
    ImmutableMap.Builder<Path, String> metadataBuilder = ImmutableMap.builder();
    for (String abi : filesByHashForAbis.keySet()) {
        ImmutableMultimap<String, Path> filesByHash = Objects.requireNonNull(filesByHashForAbis.get(abi));
        Path abiDir = NATIVE_LIBS_DIR.resolve(abi);
        metadataBuilder.put(abiDir.resolve("metadata.txt"), getNativeLibraryMetadataContents(filesByHash));
    }
    return metadataBuilder.build();
}

From source file:com.opengamma.strata.pricer.sensitivity.RatesFiniteDifferenceSensitivityCalculator.java

private <T> CurrencyParameterSensitivities sensitivity(ImmutableLegalEntityDiscountingProvider provider,
        Function<ImmutableLegalEntityDiscountingProvider, CurrencyAmount> valueFn,
        MetaProperty<ImmutableMap<Pair<T, Currency>, DiscountFactors>> metaProperty, CurrencyAmount valueInit) {

    ImmutableMap<Pair<T, Currency>, DiscountFactors> baseCurves = metaProperty.get(provider);
    CurrencyParameterSensitivities result = CurrencyParameterSensitivities.empty();
    for (Pair<T, Currency> key : baseCurves.keySet()) {
        DiscountFactors discountFactors = baseCurves.get(key);
        Curve curve = checkDiscountFactors(discountFactors);
        int paramCount = curve.getParameterCount();
        double[] sensitivity = new double[paramCount];
        for (int i = 0; i < paramCount; i++) {
            Curve dscBumped = curve.withParameter(i, curve.getParameter(i) + shift);
            Map<Pair<T, Currency>, DiscountFactors> mapBumped = new HashMap<>(baseCurves);
            mapBumped.put(key, createDiscountFactors(discountFactors, dscBumped));
            ImmutableLegalEntityDiscountingProvider providerDscBumped = provider.toBuilder()
                    .set(metaProperty, mapBumped).build();
            sensitivity[i] = (valueFn.apply(providerDscBumped).getAmount() - valueInit.getAmount()) / shift;
        }/*from   w w w  .  j  av  a 2  s . com*/
        result = result.combinedWith(
                curve.createParameterSensitivity(valueInit.getCurrency(), DoubleArray.copyOf(sensitivity)));
    }
    return result;
}

From source file:com.b2international.snowowl.snomed.datastore.index.change.RelationshipChangeProcessor.java

@Override
public void process(ICDOCommitChangeSet commitChangeSet, RevisionSearcher searcher) throws IOException {
    final Multimap<String, RefSetMemberChange> referringRefSets = memberChangeProcessor.process(commitChangeSet,
            searcher);// w  ww. j  a va  2s . c o  m

    deleteRevisions(SnomedRelationshipIndexEntry.class,
            commitChangeSet.getDetachedComponents(SnomedPackage.Literals.RELATIONSHIP));

    final Map<String, Relationship> newRelationshipsById = StreamSupport
            .stream(commitChangeSet.getNewComponents(Relationship.class).spliterator(), false)
            .collect(Collectors.toMap(relationship -> relationship.getId(), relationship -> relationship));

    for (Relationship relationship : commitChangeSet.getNewComponents(Relationship.class)) {
        final Builder doc = SnomedRelationshipIndexEntry.builder(relationship);
        indexNewRevision(relationship.cdoID(), doc.build());
    }

    final Map<String, Relationship> changedRelationshipsById = StreamSupport
            .stream(commitChangeSet.getDirtyComponents(Relationship.class).spliterator(), false)
            .collect(Collectors.toMap(relationship -> relationship.getId(), relationship -> relationship));

    final Set<String> changedRelationshipIds = newHashSet(changedRelationshipsById.keySet());
    final Set<String> referencedRelationshipIds = newHashSet(referringRefSets.keySet());
    referencedRelationshipIds.removeAll(newRelationshipsById.keySet());
    changedRelationshipIds.addAll(referencedRelationshipIds);

    final Query<SnomedRelationshipIndexEntry> query = Query.select(SnomedRelationshipIndexEntry.class)
            .where(SnomedRelationshipIndexEntry.Expressions.ids(changedRelationshipIds))
            .limit(changedRelationshipIds.size()).build();

    final Hits<SnomedRelationshipIndexEntry> changedRelationshipHits = searcher.search(query);
    final ImmutableMap<String, SnomedRelationshipIndexEntry> changedRelationshipRevisionsById = Maps
            .uniqueIndex(changedRelationshipHits, ComponentUtils.<String>getIdFunction());

    for (final String id : changedRelationshipIds) {
        final SnomedRelationshipIndexEntry currentDoc = changedRelationshipRevisionsById.get(id);
        if (currentDoc == null) {
            throw new IllegalStateException(
                    String.format("Current relationship revision should not be null for %s", id));
        }

        final Relationship relationship = changedRelationshipsById.get(id);
        final Builder doc;
        if (relationship != null) {
            doc = SnomedRelationshipIndexEntry.builder(relationship);
        } else {
            doc = SnomedRelationshipIndexEntry.builder(currentDoc);
        }

        final Collection<String> currentMemberOf = currentDoc.getMemberOf();
        final Collection<String> currentActiveMemberOf = currentDoc.getActiveMemberOf();
        new ReferenceSetMembershipUpdater(referringRefSets.removeAll(id), currentMemberOf,
                currentActiveMemberOf).update(doc);

        indexChangedRevision(currentDoc.getStorageKey(), doc.build());
    }
}

From source file:org.jclouds.aws.ec2.compute.suppliers.EC2LocationSupplier.java

@Override
public Set<? extends Location> get() {
    Location ec2 = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null);
    Set<Location> locations = newLinkedHashSet();
    for (String region : newLinkedHashSet(availabilityZoneToRegionMap.values())) {
        locations.add(new LocationImpl(LocationScope.REGION, region, region, ec2));
    }/*from w w w  . java2s  . c  om*/
    ImmutableMap<String, Location> idToLocation = uniqueIndex(locations, new Function<Location, String>() {
        @Override
        public String apply(Location from) {
            return from.getId();
        }
    });
    for (String zone : availabilityZoneToRegionMap.keySet()) {
        locations.add(new LocationImpl(LocationScope.ZONE, zone, zone,
                idToLocation.get(availabilityZoneToRegionMap.get(zone))));
    }
    return locations;
}

From source file:org.artifactory.storage.StorageServiceImpl.java

@Override
public StorageSummaryInfo getStorageSummaryInfo() {
    Set<RepoStorageSummary> summaries = fileService.getRepositoriesStorageSummary();
    List<RepoDescriptor> repos = Lists.newArrayList();
    repos.addAll(repositoryService.getLocalAndCachedRepoDescriptors());
    repos.addAll(repositoryService.getVirtualRepoDescriptors());
    final ImmutableMap<String, RepoDescriptor> reposMap = Maps.uniqueIndex(repos,
            new Function<RepoDescriptor, String>() {
                @Nullable/*from   w w  w  .  j a v a 2 s. c  o m*/
                @Override
                public String apply(@Nullable RepoDescriptor input) {
                    if (input == null) {
                        return null;
                    }
                    return input.getKey();
                }
            });
    Iterable<RepoStorageSummaryInfo> infos = Iterables.transform(summaries,
            new Function<RepoStorageSummary, RepoStorageSummaryInfo>() {
                @Override
                public RepoStorageSummaryInfo apply(RepoStorageSummary r) {
                    RepositoryType repoType = getRepoType(r.getRepoKey(), reposMap);
                    return new RepoStorageSummaryInfo(r.getRepoKey(), repoType, r.getFoldersCount(),
                            r.getFilesCount(), r.getUsedSpace());
                }

                private RepositoryType getRepoType(String repoKey,
                        ImmutableMap<String, RepoDescriptor> repoDescriptors) {
                    RepoDescriptor repoDescriptor = repoDescriptors.get(repoKey);
                    if (repoDescriptor == null) {
                        return RepositoryType.BROKEN;
                    } else if (repoDescriptor instanceof RemoteRepoDescriptor) {
                        return RepositoryType.REMOTE;
                    } else if (repoDescriptor instanceof VirtualRepoDescriptor) {
                        return RepositoryType.VIRTUAL;
                    } else if (repoDescriptor instanceof LocalCacheRepoDescriptor) {
                        return RepositoryType.CACHE;
                    } else if (repoDescriptor instanceof LocalRepoDescriptor) {
                        return RepositoryType.LOCAL;
                    } else {
                        return RepositoryType.NA;
                    }
                }
            });

    BinariesInfo binariesInfo = binaryStore.getBinariesInfo();

    return new StorageSummaryInfo(Sets.newHashSet(infos), binariesInfo);
}

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());
    }// ww w.j a  va2 s. c  o 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:com.edmunds.zookeeper.treewatcher.ZooKeeperTreeDelta.java

private void walkChildren(ImmutableMap<String, ZooKeeperTreeNode> oldChildren,
        ImmutableMap<String, ZooKeeperTreeNode> newChildren, ZooKeeperTreeDeltaResult result) {

    for (Map.Entry<String, ZooKeeperTreeNode> entry : newChildren.entrySet()) {
        final ZooKeeperTreeNode oldValue = oldChildren.get(entry.getKey());
        if (oldValue != null) {
            walkTree(oldValue, entry.getValue(), result);
        }/*from w  ww  . j a v  a 2s .c  om*/
    }
}

From source file:org.onosproject.segmentrouting.cli.LinkStateCommand.java

private void printLinkState(ImmutableMap<Link, Boolean> seenLinks,
        ImmutableMap<DeviceId, Set<PortNumber>> downedPortState) {
    List<Link> a = Lists.newArrayList();
    a.addAll(seenLinks.keySet());/*from   ww  w  . jav  a  2s  .  c o m*/
    a.sort(new CompLinks());

    StringBuilder slbldr = new StringBuilder();
    slbldr.append("\n Seen Links: ");
    for (int i = 0; i < a.size(); i++) {
        slbldr.append("\n " + (seenLinks.get(a.get(i)) == Boolean.TRUE ? "  up : " : "down : "));
        slbldr.append(a.get(i).src() + " --> " + a.get(i).dst());
    }
    print(FORMAT_MAPPING, slbldr.toString());

    StringBuilder dpbldr = new StringBuilder();
    dpbldr.append("\n\n Administratively Disabled Ports: ");
    downedPortState.entrySet().forEach(entry -> dpbldr.append("\n " + entry.getKey() + entry.getValue()));
    print(FORMAT_MAPPING, dpbldr.toString());
}

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

private void collectPackagesUnder(WalkableGraph graph, ExtendedEventHandler eventHandler,
        final RepositoryName repository, Set<TraversalInfo> traversals,
        ImmutableList.Builder<PathFragment> builder) throws InterruptedException {
    Map<TraversalInfo, SkyKey> traversalToKeyMap = Maps.asMap(traversals,
            new Function<TraversalInfo, SkyKey>() {
                @Override//  w ww  .j  a  v a2s.c om
                public SkyKey apply(TraversalInfo traversalInfo) {
                    return CollectPackagesUnderDirectoryValue.key(repository, traversalInfo.rootedDir,
                            traversalInfo.blacklistedSubdirectories);
                }
            });
    Map<SkyKey, SkyValue> values = graph.getSuccessfulValues(traversalToKeyMap.values());

    ImmutableSet.Builder<TraversalInfo> subdirTraversalBuilder = ImmutableSet.builder();
    for (Map.Entry<TraversalInfo, SkyKey> entry : traversalToKeyMap.entrySet()) {
        TraversalInfo info = entry.getKey();
        SkyKey key = entry.getValue();
        SkyValue val = values.get(key);
        CollectPackagesUnderDirectoryValue collectPackagesValue = (CollectPackagesUnderDirectoryValue) val;
        if (collectPackagesValue != null) {
            if (collectPackagesValue.isDirectoryPackage()) {
                builder.add(info.rootedDir.getRootRelativePath());
            }

            if (collectPackagesValue.getErrorMessage() != null) {
                eventHandler.handle(Event.error(collectPackagesValue.getErrorMessage()));
            }

            ImmutableMap<RootedPath, Boolean> subdirectoryTransitivelyContainsPackages = collectPackagesValue
                    .getSubdirectoryTransitivelyContainsPackagesOrErrors();
            for (RootedPath subdirectory : subdirectoryTransitivelyContainsPackages.keySet()) {
                if (subdirectoryTransitivelyContainsPackages.get(subdirectory)) {
                    PathFragment subdirectoryRelativePath = subdirectory.getRootRelativePath();
                    ImmutableSet<PathFragment> blacklistedSubdirectoriesBeneathThisSubdirectory = info.blacklistedSubdirectories
                            .stream().filter(pathFragment -> pathFragment.startsWith(subdirectoryRelativePath))
                            .collect(toImmutableSet());
                    ImmutableSet<PathFragment> excludedSubdirectoriesBeneathThisSubdirectory = info.excludedSubdirectories
                            .stream().filter(pathFragment -> pathFragment.startsWith(subdirectoryRelativePath))
                            .collect(toImmutableSet());
                    if (!excludedSubdirectoriesBeneathThisSubdirectory.contains(subdirectoryRelativePath)) {
                        subdirTraversalBuilder.add(new TraversalInfo(subdirectory,
                                blacklistedSubdirectoriesBeneathThisSubdirectory,
                                excludedSubdirectoriesBeneathThisSubdirectory));
                    }
                }
            }
        }
    }

    ImmutableSet<TraversalInfo> subdirTraversals = subdirTraversalBuilder.build();
    if (!subdirTraversals.isEmpty()) {
        collectPackagesUnder(graph, eventHandler, repository, subdirTraversals, builder);
    }
}

From source file:com.baasbox.service.push.providers.APNServer.java

@Override
public void setConfiguration(ImmutableMap<ConfigurationKeys, String> configuration) {
    String json = configuration.get(ConfigurationKeys.IOS_CERTIFICATE);
    String name = null;//from   ww  w. ja v  a2s  .c  o m
    ObjectMapper mp = new ObjectMapper();
    try {
        ConfigurationFileContainer cfc = mp.readValue(json, ConfigurationFileContainer.class);
        if (cfc == null) {
            isInit = false;
            return;
        }
        name = cfc.getName();
    } catch (Exception e) {
        BaasBoxLogger.error(ExceptionUtils.getMessage(e));
        throw new RuntimeException(e);
    }
    if (name != null && !name.equals("null")) {
        File f = IosCertificateHandler.getCertificate(name);
        this.certificate = f.getAbsolutePath();
    }
    password = configuration.get(ConfigurationKeys.IOS_CERTIFICATE_PASSWORD);
    sandbox = configuration.get(ConfigurationKeys.IOS_SANDBOX).equalsIgnoreCase("true");
    timeout = Integer.parseInt(configuration.get(ConfigurationKeys.APPLE_TIMEOUT));
    isInit = StringUtils.isNotEmpty(this.certificate) && StringUtils.isNotEmpty(password);
}