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.apache.crunch.types.writable.Writables.java
static void serializeWritableComparableCodes(Configuration conf) throws IOException { Map<Integer, String> codeToClassNameMap = Maps.transformValues(WRITABLE_CODES, new Function<Class<? extends Writable>, String>() { @Override//from w ww. j a va2s . c o m public String apply(Class<? extends Writable> input) { return input.getName(); } }); conf.set(WRITABLE_COMPARABLE_CODES, Joiner.on(';').withKeyValueSeparator(":").join(codeToClassNameMap)); }
From source file:org.janusgraph.graphdb.olap.computer.FulgoraVertexMemory.java
public Map<Long, Map<String, Object>> getMutableVertexProperties() { return Maps.transformValues(vertexStates, vs -> { Map<String, Object> map = new HashMap<>(elementKeyMap.size()); for (String key : elementKeyMap.keySet()) { Object v = vs.getProperty(key, elementKeyMap); if (v != null) map.put(key, v);/*from ww w . ja v a2 s.com*/ } return map; }); }
From source file:org.n52.sos.util.JSONUtils.java
public static ObjectNode toJSON(Map<String, ?> map) { ObjectNode node = nodeFactory().objectNode(); if (map != null) { node.putAll(Maps.transformValues(map, TO_JSON_STRING)); }// www . j a va 2s . c o m return node; }
From source file:io.hops.transaction.context.BaseEntityContext.java
final Collection<Entity> getRemoved() { Collection<Entity> entities = Maps.transformValues(contextEntities, new Function<ContextEntity, Entity>() { @Override//from www .ja va 2s. c om public Entity apply(ContextEntity input) { if (input.getState() == State.REMOVED && input.firstState != State.ADDED) { return input.getEntity(); } return null; } }).values(); return Collections2.filter(entities, Predicates.notNull()); }
From source file:com.google.api.client.discovery.RestDiscovery.java
private Map<String, DiscoveryType> transformSchemaMap(Map<String, Jsonschema> input) { if (input == null) { return Collections.emptyMap(); }/*www . jav a2 s.c om*/ return Maps.transformValues(input, new Function<Jsonschema, DiscoveryType>() { public DiscoveryType apply(Jsonschema value) { return DiscoveryType.createTypeFromSchemaNode(value, document.getSchemas()); } }); }
From source file:com.adobe.acs.commons.wcm.properties.shared.impl.SharedComponentPropertiesPageInfoProvider.java
/** * Add a "sharedComponentProperties" section to pageInfo so that JS libs in the authoring interface * can determine whether or not to enable shared/global properties for a component on a site. *///from w w w . jav a 2s .c om @Override public void updatePageInfo(SlingHttpServletRequest request, JSONObject info, Resource resource) throws JSONException { if (scheduledSharedComponentsMapUpdate > 0 && System.currentTimeMillis() > scheduledSharedComponentsMapUpdate) { scheduledSharedComponentsMapUpdate = -1L; updateSharedComponentsMap(); } JSONObject props = new JSONObject(); props.put("enabled", false); Page page = pageRootProvider.getRootPage(resource); if (page != null) { Session session = request.getResourceResolver().adaptTo(Session.class); try { AccessControlManager accessControlManager = AccessControlUtil.getAccessControlManager(session); Privilege privilegeAddChild = accessControlManager.privilegeFromName("jcr:addChildNodes"); Privilege privilegeModifyProps = accessControlManager.privilegeFromName("jcr:modifyProperties"); Privilege[] requiredPrivs = new Privilege[] { privilegeAddChild, privilegeModifyProps }; if (accessControlManager.hasPrivileges(page.getPath() + "/jcr:content", requiredPrivs)) { props.put("enabled", true); props.put("root", page.getPath()); props.put("components", Maps.transformValues(componentsWithSharedProperties, (Function<List<Boolean>, Object>) JSONArray::new)); } else { log.debug("User does not have [ {} ] on [ {} ]", requiredPrivs, page.getPath() + "/jcr:content"); } } catch (RepositoryException e) { log.error("Unexpected error checking permissions to modify shared component properties", e); } } else { log.debug("No Page Root could be found for [ {} ]", resource.getPath()); } info.put("sharedComponentProperties", props); }
From source file:org.nmdp.service.epitope.service.EpitopeServiceImpl.java
/** * {@inheritDoc}/*from w w w . j av a 2s . c om*/ */ @Override public Map<Allele, Integer> getGroupsForAllAlleles() { return Maps.transformValues(Multimaps.asMap(alleleGroupMap), l -> l.get(0)); }
From source file:com.threewks.thundr.bigquery.BigQueryPushServiceImpl.java
/** * BigQuery tasks are added to the queue with the parameters 'tableId' and 'data'. * tableId is the id of the table and data is a csv representation of the data to * be added to the table./* w w w . ja va 2s . c o m*/ * * @param a collection of tasks to extract the data from. * @return a map of table ids to csv data. */ private Map<String, String> buildReportData(Collection<TaskHandle> tasks) { Map<String, StringBuilder> reportData = new LinkedHashMap<String, StringBuilder>(); for (TaskHandle task : tasks) { String tableId = getParam(task, "tableId"); String data = getParam(task, "data"); if (StringUtil.isNotBlank(data)) { if (!reportData.containsKey(tableId)) { StringBuilder csv = new StringBuilder(); reportData.put(tableId, csv); } reportData.get(tableId).append(String.format("%s\n", data)); } } // convert the CSV StringBuilders to strings before returning return new LinkedHashMap<String, String>( Maps.transformValues(reportData, new Function<StringBuilder, String>() { public String apply(StringBuilder s) { return s.toString(); } })); }
From source file:gobblin.metrics.reporter.MetricReportReporter.java
/** * Serializes metrics and pushes the byte arrays to Kafka. Uses the serialize* methods in {@link MetricReportReporter}. * * @param gauges map of {@link com.codahale.metrics.Gauge} to report and their name. * @param counters map of {@link com.codahale.metrics.Counter} to report and their name. * @param histograms map of {@link com.codahale.metrics.Histogram} to report and their name. * @param meters map of {@link com.codahale.metrics.Meter} to report and their name. * @param timers map of {@link com.codahale.metrics.Timer} to report and their name. *///from w ww .ja v a2 s .c o m @Override protected void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers, Map<String, Object> tags) { List<Metric> metrics = Lists.newArrayList(); for (Map.Entry<String, Gauge> gauge : gauges.entrySet()) { metrics.addAll(serializeGauge(gauge.getKey(), gauge.getValue())); } for (Map.Entry<String, Counter> counter : counters.entrySet()) { metrics.addAll(serializeCounter(counter.getKey(), counter.getValue())); } for (Map.Entry<String, Histogram> histogram : histograms.entrySet()) { metrics.addAll(serializeSnapshot(histogram.getKey(), histogram.getValue().getSnapshot())); metrics.addAll(serializeCounter(histogram.getKey(), histogram.getValue())); } for (Map.Entry<String, Meter> meter : meters.entrySet()) { metrics.addAll(serializeMetered(meter.getKey(), meter.getValue())); } for (Map.Entry<String, Timer> timer : timers.entrySet()) { metrics.addAll(serializeSnapshot(timer.getKey(), timer.getValue().getSnapshot())); metrics.addAll(serializeMetered(timer.getKey(), timer.getValue())); metrics.addAll(serializeSingleValue(timer.getKey(), timer.getValue().getCount(), Measurements.COUNT.getName())); } Map<String, Object> allTags = Maps.newHashMap(); allTags.putAll(tags); allTags.putAll(this.tags); Map<String, String> allTagsString = Maps.transformValues(allTags, new Function<Object, String>() { @Nullable @Override public String apply(Object input) { return input.toString(); } }); MetricReport report = new MetricReport(allTagsString, System.currentTimeMillis(), metrics); emitReport(report); }
From source file:com.palantir.atlasdb.stream.AbstractPersistentStreamStore.java
@Override public Map<Long, Sha256Hash> storeStreams(final Transaction t, final Map<Long, InputStream> streams) { if (streams.isEmpty()) { return ImmutableMap.of(); }// w ww. ja v a2 s .com Map<Long, StreamMetadata> idsToEmptyMetadata = Maps.transformValues(streams, Functions.constant(getEmptyMetadata())); putMetadataAndHashIndexTask(t, idsToEmptyMetadata); Map<Long, StreamMetadata> idsToMetadata = Maps.transformEntries(streams, new Maps.EntryTransformer<Long, InputStream, StreamMetadata>() { @Override public StreamMetadata transformEntry(Long id, InputStream stream) { return storeBlocksAndGetFinalMetadata(t, id, stream); } }); putMetadataAndHashIndexTask(t, idsToMetadata); Map<Long, Sha256Hash> hashes = Maps.transformValues(idsToMetadata, new Function<StreamMetadata, Sha256Hash>() { @Override public Sha256Hash apply(StreamMetadata metadata) { return new Sha256Hash(metadata.getHash().toByteArray()); } }); return hashes; }