Example usage for com.google.common.collect Maps transformValues

List of usage examples for com.google.common.collect Maps transformValues

Introduction

In this page you can find the example usage for com.google.common.collect Maps transformValues.

Prototype

@GwtIncompatible("NavigableMap")
public static <K, V1, V2> NavigableMap<K, V2> transformValues(NavigableMap<K, V1> fromMap,
        Function<? super V1, V2> function) 

Source Link

Document

Returns a view of a navigable map where each value is transformed by a function.

Usage

From source file:org.apache.aurora.scheduler.http.Locks.java

/**
 * Dumps existing locks./*from   w w w  .  j a  v a 2  s.  c o m*/
 *
 * @return HTTP response.
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getLocks() {
    return Response.ok(Maps.transformValues(Maps.uniqueIndex(lockManager.getLocks(), TO_LOCK_KEY), TO_BEAN))
            .build();
}

From source file:com.facebook.presto.benchmark.AverageBenchmarkResults.java

public Map<String, String> getAverageResultsStrings() {
    return Maps.transformValues(resultsSum, input -> String.format("%,3.2f", 1.0 * input / resultsCount));
}

From source file:io.airlift.discovery.store.StoreResource.java

@Inject
public StoreResource(Map<String, LocalStore> localStores, Map<String, StoreConfig> configs) {
    this.localStores = ImmutableMap.copyOf(localStores);
    this.tombstoneMaxAges = ImmutableMap
            .copyOf(Maps.transformValues(configs, new Function<StoreConfig, Duration>() {
                @Override/*from  w w  w .j  av a2s. c o m*/
                public Duration apply(@Nullable StoreConfig config) {
                    return config.getTombstoneMaxAge();
                }
            }));
}

From source file:org.sonar.ce.taskprocessor.CeTaskProcessorRepositoryImpl.java

private static Map<String, CeTaskProcessor> indexTaskProcessors(CeTaskProcessor[] taskProcessors) {
    Multimap<String, CeTaskProcessor> permissiveIndex = buildPermissiveCeTaskProcessorIndex(taskProcessors);
    checkUniqueHandlerPerCeTaskType(permissiveIndex);
    return ImmutableMap.copyOf(
            Maps.transformValues(permissiveIndex.asMap(), CeTaskProcessorCollectionToFirstElement.INSTANCE));
}

From source file:com.b2international.commons.dynamic.DynamicMapImpl.java

@SuppressWarnings("unchecked")
public DynamicMapImpl(Map<?, ?> map) {

    valueMap = ImmutableMap.copyOf((Map<String, DynamicValue>) Maps
            .transformValues(Maps.filterKeys(map, stringKeyFilter), valueConverter));
}

From source file:uk.ac.open.kmi.iserve.discovery.ranking.impl.ProviderPopularityScorer.java

@Override
public Map<URI, Double> apply(Set<URI> resources) {
    Map<URI, Object> providerObjectMap = getNfpManager().getPropertyValueOfResources(resources,
            URI.create(SCHEMA.provider.getURI()), URI.class);
    Map<URI, URI> providerMap = Maps.transformValues(providerObjectMap, new Function<Object, URI>() {
        @Override/*from  www  .  j  a va 2  s .c o m*/
        public URI apply(Object input) {
            if (input instanceof Set) {
                if (((Set) input).isEmpty()) {
                    return null;
                } else {
                    return (URI) ((Set) input).iterator().next();
                }
            } else {
                return (URI) input;
            }
        }
    });

    Map<URI, Object> popObjectsMap = getNfpManager().getPropertyValueOfResources(
            new HashSet<URI>(providerMap.values()), URI.create(MSM_NFP.hasPopularity.getURI()), Double.class);
    Map<URI, Double> popMap = Maps.transformValues(popObjectsMap, new Function<Object, Double>() {
        @Override
        public Double apply(Object input) {
            Double r;
            if (input instanceof Set) {
                if (((Set) input).isEmpty()) {
                    return new Double(0);
                } else {
                    r = (Double) ((Set) input).iterator().next();
                }
            } else {
                r = (Double) input;
            }
            if (r != null && r > 0) {
                return r / 100;
            }
            return Double.valueOf(0);
        }
    });
    Map<URI, Double> result = Maps.newHashMap();
    for (URI resource : resources) {
        if (providerMap.get(resource) == null) {
            result.put(resource, new Double(0));
        } else {
            result.put(resource, popMap.get(providerMap.get(resource)));
        }
    }

    return result;
}

From source file:org.jclouds.ec2.suppliers.DescribeRegionsForRegionURIs.java

@Singleton
@Region/*from w  ww. j av  a2 s.c  o m*/
@Override
public Map<String, Supplier<URI>> get() {
    Map<String, URI> regionToUris = client.describeRegions();
    return Maps.transformValues(regionToUris, Suppliers2.<URI>ofInstanceFunction());
}

From source file:org.jpmml.evaluator.ClassificationAggregator.java

protected <V> Map<K, V> transform(Function<DoubleVector, V> function) {
    return Maps.transformValues(this.map, function);
}

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

public RemoteStateBasedFileHashCache(final ProjectFilesystem projectFilesystem,
        BuildJobStateFileHashes remoteFileHashes) {
    this.remoteFileHashes = Maps.transformValues(
            DistBuildFileHashes.indexEntriesByPath(projectFilesystem, remoteFileHashes),
            HASH_CODE_FROM_FILE_HASH_ENTRY);
    this.remoteArchiveHashes = Maps.transformValues(
            DistBuildFileHashes.indexEntriesByArchivePath(projectFilesystem, remoteFileHashes),
            HASH_CODE_FROM_FILE_HASH_ENTRY);
}

From source file:com.googlesource.gerrit.plugins.lfs.GetLfsGlobalConfig.java

@Override
public LfsGlobalConfigInfo apply(ProjectResource resource) throws RestApiException {
    adminView.validate(resource);/*  w ww . ja  v  a 2s  .  c om*/

    LfsGlobalConfigInfo info = new LfsGlobalConfigInfo();
    LfsGlobalConfig globalConfig = lfsConfigFactory.getGlobalConfig();
    info.defaultBackendType = globalConfig.getDefaultBackend().type;
    info.backends = Maps.transformValues(globalConfig.getBackends(), b -> b.type);

    List<LfsProjectConfigSection> configSections = lfsConfigFactory.getProjectsConfig().getConfigSections();
    if (!configSections.isEmpty()) {
        info.namespaces = new HashMap<>(configSections.size());
        for (LfsProjectConfigSection section : configSections) {
            LfsProjectConfigInfo sectionInfo = new LfsProjectConfigInfo();
            sectionInfo.enabled = section.isEnabled();
            sectionInfo.maxObjectSize = section.getMaxObjectSize();
            sectionInfo.readOnly = section.isReadOnly();
            sectionInfo.backend = section.getBackend();
            info.namespaces.put(section.getNamespace(), sectionInfo);
        }
    }
    return info;
}