List of usage examples for com.google.common.collect Maps transformValues
@GwtIncompatible("NavigableMap") public static <K, V1, V2> NavigableMap<K, V2> transformValues(NavigableMap<K, V1> fromMap, Function<? super V1, V2> function)
From source file:org.jfrog.bamboo.context.Maven3BuildContext.java
public static Maven3BuildContext createMavenContextFromMap(Map<String, Object> map) { Map<String, String> transformed = Maps.transformValues(map, new Function<Object, String>() { @Override/*from www . j av a 2 s . co m*/ public String apply(Object input) { if (input == null) { return ""; } return input.toString(); } }); return new Maven3BuildContext(transformed); }
From source file:io.druid.server.http.CoordinatorResource.java
@GET @Path("/loadqueue") @Produces(MediaType.APPLICATION_JSON)// w w w . j ava 2 s.c o m 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:co.cask.cdap.internal.app.runtime.flow.DatumOutputEmitter.java
@Override public void emit(T data, Map<String, Object> partitions) { try {//from w ww . j a v a 2s . c om ByteArrayOutputStream output = new ByteArrayOutputStream(); output.write(schemaHash); writer.encode(data, new BinaryEncoder(output)); producerSupplier.get().enqueue(new QueueEntry( Maps.transformValues(partitions, PARTITION_MAP_TRANSFORMER), output.toByteArray())); } catch (IOException e) { throw Throwables.propagate(e); } }
From source file:org.jclouds.cloudstack.predicates.OSCategoryIn.java
@Override public Predicate<Template> apply(final Set<String> acceptableCategories) { final Map<String, String> categories = categoriesSupplier.get(); final Set<String> acceptableOSTypeIds = Maps.filterValues( Maps.transformValues(Maps.uniqueIndex(osTypesSupplier.get(), new Function<OSType, String>() { @Override// w w w . j a v a2 s .co m public String apply(OSType input) { return input.getId(); } }), new Function<OSType, String>() { @Override public String apply(OSType input) { return categories.get(input.getOSCategoryId()); } }), Predicates.in(acceptableCategories)).keySet(); return new Predicate<Template>() { @Override public boolean apply(Template input) { return Predicates.in(acceptableOSTypeIds).apply(input.getOSTypeId()); } @Override public String toString() { return "OSCategoryIn(" + acceptableCategories + ")"; } }; }
From source file:io.crate.expression.reference.sys.SysObjectArrayReference.java
@Override public Object[] value() { List<NestedObjectExpression> childImplementations = getChildImplementations(); Object[] values = new Object[childImplementations.size()]; int i = 0;//from w ww. j a v a 2s . c o m for (NestedObjectExpression expression : childImplementations) { Map<String, Object> map = Maps.transformValues(expression.getChildImplementations(), new Function<NestableInput, Object>() { @Nullable @Override public Object apply(@Nullable NestableInput input) { Object value = input.value(); if (value != null && value instanceof BytesRef) { return ((BytesRef) value).utf8ToString(); } else { return value; } } }); values[i++] = map; } return values; }
From source file:com.facebook.buck.core.model.FlavorDomain.java
/** Provides a convenience function to map the values of the domain. */ public <U> FlavorDomain<U> map(String name, Function<? super T, U> mapper) { return new FlavorDomain<>(name, ImmutableMap.copyOf(Maps.transformValues(translation, mapper::apply))); }
From source file:org.jclouds.openstack.keystone.v1_1.suppliers.RegionIdToURIFromAuthForServiceSupplier.java
@Override public Map<String, Supplier<URI>> get() { Auth authResponse = auth.get();//from w w w . jav a2s. c o m Collection<Endpoint> endpointsForService = authResponse.getServiceCatalog().get(apiType); Map<String, Endpoint> regionIdToEndpoint = Maps.uniqueIndex(endpointsForService, endpointToRegion); return Maps.transformValues(regionIdToEndpoint, endpointToSupplierURI); }
From source file:net.hydromatic.optiq.jdbc.OptiqSchema.java
public OptiqSchema(OptiqSchema parent, final Schema schema) { this.parent = parent; this.schema = schema; assert (parent == null) == (this instanceof OptiqRootSchema); this.compositeTableMap = CompositeMap.of(Maps.transformValues(tableMap, new Function<TableEntry, Table>() { public Table apply(TableEntry input) { return input.getTable(); }/*from w ww. j a v a 2s. co m*/ }), Maps.transformValues( Multimaps.filterEntries(tableFunctionMap, new Predicate<Map.Entry<String, TableFunctionEntry>>() { public boolean apply(Map.Entry<String, TableFunctionEntry> input) { return input.getValue().getTableFunction().getParameters().isEmpty(); } }).asMap(), new Function<Collection<TableFunctionEntry>, Table>() { public Table apply(Collection<TableFunctionEntry> input) { // At most one function with zero parameters. TableFunctionEntry entry = input.iterator().next(); return entry.getTableFunction().apply(ImmutableList.of()); } }), Compatible.INSTANCE.asMap(schema.getTableNames(), new Function<String, Table>() { public Table apply(String input) { return schema.getTable(input); } })); // TODO: include schema's table functions in this map. this.compositeTableFunctionMap = Multimaps.transformValues(tableFunctionMap, new Function<TableFunctionEntry, TableFunction>() { public TableFunction apply(TableFunctionEntry input) { return input.getTableFunction(); } }); this.compositeSubSchemaMap = CompositeMap.of(subSchemaMap, Compatible.INSTANCE .<String, OptiqSchema>asMap(schema.getSubSchemaNames(), new Function<String, OptiqSchema>() { public OptiqSchema apply(String input) { return addSchema(schema.getSubSchema(input)); } })); }
From source file:org.elasticlib.common.model.RepositoryStats.java
/** * Read a new instance from supplied map of values. * * @param map A map of values./* w w w . j av a 2 s . c o m*/ * @return A new instance. */ public static RepositoryStats fromMap(Map<String, Value> map) { Map<String, Long> metadata = Maps.transformValues(map.get(METADATA).asMap(), input -> input.asLong()); Map<Operation, Long> operations = new EnumMap<>(Operation.class); map.get(OPERATIONS).asMap().entrySet().stream() .forEach(entry -> operations.put(Operation.fromString(entry.getKey()), entry.getValue().asLong())); return new RepositoryStats(operations.get(Operation.CREATE), operations.get(Operation.UPDATE), operations.get(Operation.DELETE), metadata); }
From source file:com.twitter.aurora.scheduler.http.Quotas.java
/** * Dumps allocated resource quotas./*from www .j ava 2s . com*/ * * @return HTTP response. */ @GET @Produces(MediaType.APPLICATION_JSON) public Response getOffers(@QueryParam("role") final String role) { return storage.weaklyConsistentRead(new Work.Quiet<Response>() { @Override public Response apply(StoreProvider storeProvider) { Map<String, IQuota> quotas; if (role == null) { quotas = storeProvider.getQuotaStore().fetchQuotas(); } else { Optional<IQuota> quota = storeProvider.getQuotaStore().fetchQuota(role); if (quota.isPresent()) { quotas = ImmutableMap.of(role, quota.get()); } else { quotas = ImmutableMap.of(); } } return Response.ok(Maps.transformValues(quotas, TO_BEAN)).build(); } }); }