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.carrot2.output.metrics.IdealPartitioningBasedMetric.java

/**
 * Returns document counts for each partition.
 *//*from   w w  w. j  a va 2  s .c  o m*/
Map<Object, Integer> getDocumentCountByPartition(List<Document> documents) {
    return ImmutableMap.copyOf(Maps.transformValues(getDocumentsByPartition(documents).asMap(),
            new Function<Collection<Document>, Integer>() {
                public Integer apply(Collection<Document> documents) {
                    return documents.size();
                }
            }));
}

From source file:com.mengge.internal.JsonToMobileElementConverter.java

/**
 * This method converts a command result.
 *
 * @param result is the result of a command execution.
 * @return the result//from   w w w  .  j av a  2s  .c o m
 */
public Object apply(Object result) {
    if (result instanceof Collection<?>) {
        Collection<?> results = (Collection<?>) result;
        return Lists.newArrayList(Iterables.transform(results, this));
    }

    if (result instanceof Map<?, ?>) {
        Map<?, ?> resultAsMap = (Map<?, ?>) result;
        if (resultAsMap.containsKey("ELEMENT")) {
            MobileElement element = newMobileElement();
            element.setId(String.valueOf(resultAsMap.get("ELEMENT")));
            element.setFileDetector(driver.getFileDetector());
            return element;
        } else {
            return Maps.transformValues(resultAsMap, this);
        }
    }

    if (result instanceof Number) {
        if (result instanceof Float || result instanceof Double) {
            return ((Number) result).doubleValue();
        }
        return ((Number) result).longValue();
    }

    return result;
}

From source file:co.cask.tigon.internal.app.runtime.flow.DatumOutputEmitter.java

@Override
public void emit(T data, Map<String, Object> partitions) {
    try {/*from  w  w w.  j ava 2s. co m*/
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        output.write(schemaHash);
        writer.encode(data, new BinaryEncoder(output));
        queueProducer.enqueue(new QueueEntry(Maps.transformValues(partitions, PARTITION_MAP_TRANSFORMER),
                output.toByteArray()));
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}

From source file:org.onosproject.store.primitives.impl.DefaultDistributedDocumentTree.java

@Override
public CompletableFuture<Map<String, Versioned<V>>> getChildren(DocumentPath path) {
    return backingTree.getChildren(path)
            .thenApply(map -> Maps.transformValues(map, v -> v.map(serializer::decode)));
}

From source file:com.google.devtools.build.lib.concurrent.FastHotKeyAtomicLongMap.java

public ImmutableMap<T, Long> asImmutableMap() {
    return ImmutableMap.copyOf(Maps.transformValues(map, AtomicLong::get));
}

From source file:com.facebook.buck.core.cell.impl.DefaultCellPathResolver.java

static ImmutableMap<String, Path> getCellPathsFromConfigRepositoriesSection(Path root,
        ImmutableMap<String, String> repositoriesSection) {
    return ImmutableMap.copyOf(Maps.transformValues(repositoriesSection,
            input -> root.resolve(MorePaths.expandHomeDir(root.getFileSystem().getPath(input))).normalize()));
}

From source file:com.google.api.client.discovery.RestResource.java

/**
 * Returns a map of the sub-resources on this resource.
 *//*from ww  w . ja  v  a  2 s .  c  o  m*/
public Map<String, RestResource> getResources() {
    if (resource.getResources() == null) {
        return Collections.emptyMap();
    }

    return Maps.transformValues(resource.getResources(), new Function<Restresource, RestResource>() {
        public RestResource apply(Restresource input) {
            return new RestResource(input, topLevelSchemas);
        }
    });
}

From source file:io.atomix.core.tree.impl.TranscodingAsyncAtomicDocumentTree.java

@Override
public CompletableFuture<Map<String, Versioned<V1>>> getChildren(DocumentPath path) {
    return backingTree.getChildren(path)
            .thenApply(children -> Maps.transformValues(children, v -> v.map(valueDecoder)));
}

From source file:eu.esdihumboldt.hale.ui.service.instance.sample.internal.sampler.first.FirstSampler.java

@Override
public InstanceCollection sample(InstanceCollection instances, Value settings) {
    final int max = settings.as(Integer.class, DEFAULT_MAX);

    if (max >= 1) {
        if (instances instanceof InstanceCollection2) {
            InstanceCollection2 fic = (InstanceCollection2) instances;
            if (fic.supportsFanout()) {
                /*/*from  w  w w. jav  a 2  s.  c  om*/
                 * The instance collection supports fan-out by type -> so we
                 * apply the sampling on each instance collection
                 * individually
                 */
                Map<TypeDefinition, InstanceCollection> collections = Maps.transformValues(fic.fanout(),
                        new Function<InstanceCollection, InstanceCollection>() {

                            @Override
                            public InstanceCollection apply(InstanceCollection org) {
                                return new FirstOverallInstances(org, max);
                            }

                        });
                return new PerTypeInstanceCollection(collections);
            }
        }

        return new FirstInstancesPerType(instances, max);
    }
    return instances;
}

From source file:seaclouds.utils.toscamodel.basictypes.impl.TypeMap.java

@Override
public IValueMap instantiate(Map<String, Object> value) {
    Map<String, IValue> v = new HashMap<>();
    v.putAll(Maps.transformValues(value, i -> valueSchema.instantiate(i)));
    return new ValueMap(v);
}