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:com.google.devtools.build.skyframe.InMemoryGraphImpl.java

@Override
public Map<SkyKey, SkyValue> getDoneValues() {
    return Collections.unmodifiableMap(
            Maps.filterValues(Maps.transformValues(nodeMap, new Function<InMemoryNodeEntry, SkyValue>() {
                @Override//from   www  . java 2s.  com
                public SkyValue apply(InMemoryNodeEntry entry) {
                    return entry.isDone() ? entry.getValue() : null;
                }
            }), Predicates.notNull()));
}

From source file:com.google.devtools.build.skyframe.InMemoryGraph.java

/**
 * Returns a read-only live view of the done values in the graph. Dirty, changed, and error values
 * are not present in the returned map/*  w ww . j av a  2 s .  com*/
 */
Map<SkyKey, SkyValue> getDoneValues() {
    return Collections.unmodifiableMap(
            Maps.filterValues(Maps.transformValues(nodeMap, new Function<NodeEntry, SkyValue>() {
                @Override
                public SkyValue apply(NodeEntry entry) {
                    return entry.isDone() ? entry.getValue() : null;
                }
            }), Predicates.notNull()));
}

From source file:io.druid.server.listener.resource.AbstractListenerHandler.java

@Override
public final Response handlePOSTAll(final InputStream inputStream, final ObjectMapper mapper) {
    final Map<String, ObjType> inObjMap;
    try {/*from  w  w  w.j av a 2s  .c o m*/
        // This actually fails to properly convert due to type erasure. We'll try again in a second
        // This effectively just parses
        final Map<String, Object> tempMap = mapper.readValue(inputStream,
                new TypeReference<Map<String, Object>>() {
                });
        // Now do the ACTUAL conversion
        inObjMap = ImmutableMap.copyOf(Maps.transformValues(tempMap, new Function<Object, ObjType>() {
            @Override
            public ObjType apply(Object input) {
                return mapper.convertValue(input, inObjTypeRef);
            }
        }));
    } catch (final IOException ex) {
        LOG.debug(ex, "Bad request");
        return Response.status(Response.Status.BAD_REQUEST).entity(ServletResourceUtils.sanitizeException(ex))
                .build();
    }
    final Object returnObj;
    try {
        returnObj = post(inObjMap);
    } catch (Exception e) {
        LOG.error(e, "Error handling request");
        return Response.serverError().entity(ServletResourceUtils.sanitizeException(e)).build();
    }
    if (returnObj == null) {
        return Response.status(Response.Status.NOT_FOUND).build();
    } else {
        return Response.status(Response.Status.ACCEPTED).entity(returnObj).build();
    }
}

From source file:org.jclouds.examples.rackspace.clouddns.UpdateRecords.java

private void updateRecords(Domain domain) throws TimeoutException {
    System.out.format("Update Records%n");

    Set<RecordDetail> recordDetails = dnsApi.getRecordApi(domain.getId()).listByType("A").concat().toSet();
    Map<String, Record> idsToRecords = RecordFunctions.toRecordMap(recordDetails);
    Map<String, Record> updateRecords = Maps.transformValues(idsToRecords,
            updateTTLAndComment(235813, "New TTL"));

    awaitComplete(dnsApi, dnsApi.getRecordApi(domain.getId()).update(updateRecords));

    Iterable<RecordDetail> recordDetailsUpdated = dnsApi.getRecordApi(domain.getId()).listByType("A").concat();

    for (RecordDetail recordDetailUpdated : recordDetailsUpdated) {
        System.out.format("  %s%n", recordDetailUpdated);
    }//from  w  w w . j ava 2 s . c  o m
}

From source file:io.airlift.drift.codec.ArrayField.java

public Map<Short, List<Long>> getMapLongList() {
    if (mapLongArray == null) {
        return null;
    }/*from w w  w  .jav a 2s  . c o  m*/
    return Maps.transformValues(this.mapLongArray, Longs::asList);
}

From source file:com.facebook.swift.codec.ArrayField.java

public Map<Short, List<Long>> getMapLongList() {
    if (mapLongArray == null) {
        return null;
    }//from   www.j  a  v  a2 s  . com
    return Maps.transformValues(this.mapLongArray, longArrayAsList());
}

From source file:org.springframework.cloud.zookeeper.discovery.dependency.DependencyRestTemplateAutoConfiguration.java

@PostConstruct
void customizeRestTemplate() {
    this.restTemplate.getInterceptors().add(new ClientHttpRequestInterceptor() {
        @Override//from  w  w w.j a v  a 2s . co  m
        public ClientHttpResponse intercept(HttpRequest request, byte[] body,
                ClientHttpRequestExecution execution) throws IOException {
            String clientName = request.getURI().getHost();
            ZookeeperDependency dependencyForAlias = DependencyRestTemplateAutoConfiguration.this.zookeeperDependencies
                    .getDependencyForAlias(clientName);
            HttpHeaders headers = getUpdatedHeadersIfPossible(request, dependencyForAlias);
            request.getHeaders().putAll(headers);
            return execution.execute(request, body);
        }

        private HttpHeaders getUpdatedHeadersIfPossible(HttpRequest request,
                ZookeeperDependency dependencyForAlias) {
            HttpHeaders httpHeaders = new HttpHeaders();
            if (dependencyForAlias != null) {
                Map<String, Collection<String>> updatedHeaders = dependencyForAlias
                        .getUpdatedHeaders(convertHeadersFromListToCollection(request.getHeaders()));
                httpHeaders.putAll(convertHeadersFromCollectionToList(updatedHeaders));
                return httpHeaders;
            }
            httpHeaders.putAll(request.getHeaders());
            return httpHeaders;
        }

        private Map<String, Collection<String>> convertHeadersFromListToCollection(HttpHeaders headers) {
            return Maps.transformValues(headers, new Function<List<String>, Collection<String>>() {
                @Override
                public Collection<String> apply(List<String> input) {
                    return input;
                }
            });
        }

        private Map<String, List<String>> convertHeadersFromCollectionToList(
                Map<String, Collection<String>> headers) {
            return Maps.transformValues(headers, new Function<Collection<String>, List<String>>() {
                @Override
                public List<String> apply(Collection<String> input) {
                    return (List<String>) input;
                }
            });
        }
    });
}

From source file:org.apache.fluo.api.client.AbstractSnapshotBase.java

@Override
public Map<String, Map<Column, String>> gets(Collection<? extends CharSequence> rows, Set<Column> columns) {
    Map<Bytes, Map<Column, Bytes>> rcvs = get(Collections2.transform(rows, this::s2bConv), columns);
    Map<String, Map<Column, String>> ret = new HashMap<>(rcvs.size());

    for (Entry<Bytes, Map<Column, Bytes>> entry : rcvs.entrySet()) {
        ret.put(entry.getKey().toString(), Maps.transformValues(entry.getValue(), b -> b.toString()));
    }//from   w  w w. ja v  a 2 s.  co m
    return ret;
}

From source file:org.apache.druid.server.listener.resource.AbstractListenerHandler.java

@Override
public final Response handlePOSTAll(final InputStream inputStream, final ObjectMapper mapper) {
    final Map<String, ObjType> inObjMap;
    try {//w w  w  . j  ava 2  s .com
        // This actually fails to properly convert due to type erasure. We'll try again in a second
        // This effectively just parses
        final Map<String, Object> tempMap = mapper.readValue(inputStream,
                JacksonUtils.TYPE_REFERENCE_MAP_STRING_OBJECT);
        // Now do the ACTUAL conversion
        inObjMap = ImmutableMap.copyOf(Maps.transformValues(tempMap, new Function<Object, ObjType>() {
            @Override
            public ObjType apply(Object input) {
                return mapper.convertValue(input, inObjTypeRef);
            }
        }));
    } catch (final IOException ex) {
        LOG.debug(ex, "Bad request");
        return Response.status(Response.Status.BAD_REQUEST).entity(ServletResourceUtils.sanitizeException(ex))
                .build();
    }
    final Object returnObj;
    try {
        returnObj = post(inObjMap);
    } catch (Exception e) {
        LOG.error(e, "Error handling request");
        return Response.serverError().entity(ServletResourceUtils.sanitizeException(e)).build();
    }
    if (returnObj == null) {
        return Response.status(Response.Status.NOT_FOUND).build();
    } else {
        return Response.status(Response.Status.ACCEPTED).entity(returnObj).build();
    }
}

From source file:com.b2international.snowowl.snomed.datastore.taxonomy.SnomedTaxonomyUpdateRunnable.java

public SnomedTaxonomyUpdateRunnable(RevisionSearcher searcher, CDOTransaction transaction,
        ISnomedTaxonomyBuilder taxonomyBuilder, String characteristicTypeId) {

    this(searcher,
            new CDOCommitChangeSet(transaction, transaction.getSession().getUserID(),
                    transaction.getCommitComment(), transaction.getNewObjects().values(),
                    transaction.getDirtyObjects().values(),
                    Maps.transformValues(transaction.getDetachedObjects(), GET_ECLASS_FUNCTION),
                    transaction.getRevisionDeltas(), -1L),
            taxonomyBuilder, characteristicTypeId);
}