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.isotrol.impe3.pms.core.impl.PageManagerImpl.java

/**
 * @see com.isotrol.impe3.pms.core.PageManager#copyDfn(com.isotrol.impe3.pms.model.PageDfn,
 * com.isotrol.impe3.pms.model.PageEntity)
 */// w  ww . ja  va2 s  .c  o m
@Transactional(rollbackFor = Throwable.class)
public PageDfn copyDfn(PageDfn from, PageEntity to) {
    final PageDfn dfn = new PageDfn();
    dfn.setPage(to);
    dfn.setName(from.getName());
    dfn.setDescription(from.getDescription());
    dfn.setTag(from.getTag());
    dfn.setCategory(from.getCategory());
    dfn.setContentType(from.getContentType());
    dfn.setUmbrella(from.isUmbrella());
    dfn.setTemplate(from.getTemplate());
    dfn.getComponents().putAll(Maps.transformValues(from.getComponents(), cvDup));
    dfn.getLayout().putAll(Maps.transformValues(from.getLayout(), lvDup));
    try {
        saveNewEntity(dfn);
    } catch (PMSException e) {
        throw new IllegalStateException(e); // TODO
    }
    return dfn;
}

From source file:org.jclouds.openstack.keystone.v2_0.suppliers.LocationIdToURIFromAccessForTypeAndVersionSupplier.java

@Override
public Map<String, Supplier<URI>> get() {
    Access accessResponse = access.get();
    Service service = null;/*from w  w  w .  j  a v a2  s  . c  om*/
    try {
        service = Iterables.find(accessResponse.getServiceCatalog(), new Predicate<Service>() {

            @Override
            public boolean apply(Service input) {
                return input.getType().equals(apiType);
            }

        });
    } catch (NoSuchElementException e) {
        throw new NoSuchElementException(String.format("apiType %s not found in catalog %s", apiType,
                accessResponse.getServiceCatalog()));
    }
    Map<String, Endpoint> locationIdToEndpoint = Maps
            .uniqueIndex(Iterables.filter(service.getEndpoints(), new Predicate<Endpoint>() {

                @Override
                public boolean apply(Endpoint input) {
                    if (input.getVersionId() == null) {
                        return true;
                    }
                    return input.getVersionId().equals(apiVersion);
                }

            }), endpointToLocationId);
    return Maps.transformValues(locationIdToEndpoint, endpointToSupplierURI);
}

From source file:org.apache.druid.server.http.CoordinatorResource.java

@GET
@Path("/loadqueue")
@ResourceFilters(StateResourceFilter.class)
@Produces(MediaType.APPLICATION_JSON)/*from  w  w w .ja  va2  s. c  om*/
public Response getLoadQueue(@QueryParam("simple") String simple, @QueryParam("full") String full) {
    if (simple != null) {
        return Response.ok(Maps.transformValues(coordinator.getLoadManagementPeons(),
                new Function<LoadQueuePeon, Object>() {
                    @Override
                    public Object apply(LoadQueuePeon input) {
                        long loadSize = 0;
                        for (DataSegment dataSegment : input.getSegmentsToLoad()) {
                            loadSize += dataSegment.getSize();
                        }

                        long dropSize = 0;
                        for (DataSegment dataSegment : input.getSegmentsToDrop()) {
                            dropSize += dataSegment.getSize();
                        }

                        return new ImmutableMap.Builder<>()
                                .put("segmentsToLoad", input.getSegmentsToLoad().size())
                                .put("segmentsToDrop", input.getSegmentsToDrop().size())
                                .put("segmentsToLoadSize", loadSize).put("segmentsToDropSize", dropSize)
                                .build();
                    }
                })).build();
    }

    if (full != null) {
        return Response.ok(coordinator.getLoadManagementPeons()).build();
    }

    return Response.ok(
            Maps.transformValues(coordinator.getLoadManagementPeons(), new Function<LoadQueuePeon, Object>() {
                @Override
                public Object apply(LoadQueuePeon input) {
                    return new ImmutableMap.Builder<>().put("segmentsToLoad", Collections2
                            .transform(input.getSegmentsToLoad(), new Function<DataSegment, Object>() {
                                @Override
                                public String apply(DataSegment segment) {
                                    return segment.getIdentifier();
                                }
                            })).put("segmentsToDrop", Collections2.transform(input.getSegmentsToDrop(),
                                    new Function<DataSegment, Object>() {
                                        @Override
                                        public String apply(DataSegment segment) {
                                            return segment.getIdentifier();
                                        }
                                    }))
                            .build();
                }
            })).build();
}

From source file:org.elasticsearch.search.aggregations.InternalAggregations.java

/**
 * Returns the {@link Aggregation}s keyed by map.
 */// www. ja  v a 2s .c o  m
public Map<String, Aggregation> getAsMap() {
    if (aggregationsAsMap == null) {
        Map<String, InternalAggregation> aggregationsAsMap = newHashMap();
        for (InternalAggregation aggregation : aggregations) {
            aggregationsAsMap.put(aggregation.getName(), aggregation);
        }
        this.aggregationsAsMap = aggregationsAsMap;
    }
    return Maps.transformValues(aggregationsAsMap, SUPERTYPE_CAST);
}

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

@Override
public Map<String, Supplier<Set<String>>> get() {
    Builder<String, Set<String>> map = ImmutableMap.builder();
    HttpResponseException exception = null;
    // TODO: this should be parallel
    for (String region : regions.get()) {
        try {/*  w  w w.  ja  v  a 2 s. c  o m*/
            ImmutableSet<String> zones = ImmutableSet
                    .copyOf(Iterables.transform(client.describeAvailabilityZonesInRegion(region),
                            new Function<AvailabilityZoneInfo, String>() {

                                @Override
                                public String apply(AvailabilityZoneInfo arg0) {
                                    return arg0.getZone();
                                }

                            }));
            if (zones.size() > 0)
                map.put(region, zones);
        } catch (HttpResponseException e) {
            // TODO: this should be in retry handler, not here.
            if (e.getMessage().contains("Unable to tunnel through proxy")) {
                exception = e;
                logger.error(e, "Could not describe availability zones in Region: %s", region);
            } else {
                throw e;
            }
        }
    }
    ImmutableMap<String, Set<String>> result = map.build();
    if (result.isEmpty() && exception != null) {
        throw exception;
    }
    return Maps.transformValues(result, Suppliers2.<Set<String>>ofInstanceFunction());
}

From source file:eu.project.ttc.models.Context.java

public Map<String, Double> getOccurrenceVector() {
    return Maps.transformValues(occurrences, DoubleMutator);
}

From source file:org.basepom.mojo.propertyhelper.beans.PropertyGroup.java

public Map<String, String> getProperties() {
    return ImmutableMap.copyOf(Maps.transformValues(
            Maps.uniqueIndex(Arrays.asList(properties), getNameFunction()), getValueFunction()));
}

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

public Map<Short, List<Integer>> getMapIntegerList() {
    if (mapIntArray == null) {
        return null;
    }/*w  w  w.  j  a v a 2 s. c o  m*/
    return Maps.transformValues(mapIntArray, intArrayAsList());
}

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

public Map<Short, List<Integer>> getMapIntegerList() {
    if (mapIntArray == null) {
        return null;
    }//w  w  w  .  j a v a  2s . c  o  m
    return Maps.transformValues(mapIntArray, Ints::asList);
}

From source file:com.google.gerrit.metrics.dropwizard.BucketedCallback.java

@Override
public Map<Object, Metric> getCells() {
    return Maps.transformValues(cells, in -> (Metric) in);
}