List of usage examples for com.google.common.collect Maps transformEntries
@GwtIncompatible("NavigableMap") public static <K, V1, V2> NavigableMap<K, V2> transformEntries(NavigableMap<K, V1> fromMap, EntryTransformer<? super K, ? super V1, V2> transformer)
From source file:io.mandrel.data.analysis.AnalysisService.java
protected Analysis buildReport(Spider spider, Blob blob) { Analysis report;//from w ww .j ava2s. c o m if (blob.getMetadata().getUri().getScheme().startsWith("http")) { HttpAnalysis temp = new HttpAnalysis(); // Robots.txt Uri pageURL = blob.getMetadata().getUri(); String robotsTxtUrl = pageURL.getScheme() + "://" + pageURL.getHost() + ":" + pageURL.getPort() + "/robots.txt"; ExtendedRobotRules robotRules = RobotsTxtUtils.getRobotRules(robotsTxtUrl); temp.robotRules(robotRules); // Sitemaps if (robotRules != null && robotRules.getSitemaps() != null) { Map<String, List<AbstractSiteMap>> sitemaps = new HashMap<>(); robotRules.getSitemaps().forEach(url -> { List<AbstractSiteMap> results = getSitemapsForUrl(url); sitemaps.put(url, results); }); temp.sitemaps(sitemaps); } report = temp; } else { report = new Analysis(); } if (spider.getExtractors() != null) { Map<String, Instance<?>> cachedSelectors = new HashMap<>(); // Page extraction if (spider.getExtractors().getData() != null) { Map<String, List<Document>> documentsByExtractor = spider.getExtractors().getData().stream().map( ex -> Pair.of(ex.getName(), extractorService.extractThenFormat(cachedSelectors, blob, ex))) .filter(pair -> pair != null && pair.getKey() != null && pair.getValue() != null) .collect(Collectors.toMap(key -> key.getLeft(), value -> value.getRight())); report.documents(documentsByExtractor); } // Link extraction if (spider.getExtractors().getOutlinks() != null) { Map<String, Pair<Set<Link>, Set<Link>>> outlinksByExtractor = spider.getExtractors().getOutlinks() .stream().map(ol -> { return Pair.of(ol.getName(), extractorService.extractAndFilterOutlinks(spider, blob.getMetadata().getUri(), cachedSelectors, blob, ol)); }).collect(Collectors.toMap(key -> key.getLeft(), value -> value.getRight())); report.outlinks(Maps.transformEntries(outlinksByExtractor, (key, entries) -> entries.getLeft())); report.filteredOutlinks( Maps.transformEntries(outlinksByExtractor, (key, entries) -> entries.getRight())); } } report.metadata(blob.getMetadata()); return report; }
From source file:biz.dfch.j.graylog2.plugin.alarm.dfchBizExecScript.java
@Override public Map<String, Object> getAttributes() { return Maps.transformEntries(_configuration.getSource(), new Maps.EntryTransformer<String, Object, Object>() { @Override//w w w .jav a 2s. c o m public Object transformEntry(String key, Object value) { return key + "-" + value; } }); }
From source file:org.apache.twill.internal.state.SystemMessages.java
private static Map<String, String> convertLogEntryToString(Map<String, LogEntry.Level> logLevels) { return Maps.transformEntries(logLevels, new Maps.EntryTransformer<String, LogEntry.Level, String>() { @Override/*w w w .j a v a2 s .c o m*/ public String transformEntry(String loggerName, LogEntry.Level level) { return level == null ? null : level.name(); } }); }
From source file:org.apache.beam.runners.spark.metrics.WithMetricsSupport.java
private Function<Map.Entry<String, Metric>, Map<String, Gauge>> aggregatorMetricToGauges() { return new Function<Map.Entry<String, Metric>, Map<String, Gauge>>() { @Override/*from w w w .ja va2 s . c o m*/ public Map<String, Gauge> apply(final Map.Entry<String, Metric> entry) { final NamedAggregators agg = ((AggregatorMetric) entry.getValue()).getNamedAggregators(); final String parentName = entry.getKey(); final Map<String, Gauge> gaugeMap = Maps.transformEntries(agg.renderAll(), toGauge()); final Map<String, Gauge> fullNameGaugeMap = Maps.newLinkedHashMap(); for (Map.Entry<String, Gauge> gaugeEntry : gaugeMap.entrySet()) { fullNameGaugeMap.put(parentName + "." + gaugeEntry.getKey(), gaugeEntry.getValue()); } return Maps.filterValues(fullNameGaugeMap, Predicates.notNull()); } }; }
From source file:org.apache.james.rrt.memory.MemoryRecipientRewriteTable.java
@Override protected Map<String, Mappings> getAllMappingsInternal() throws RecipientRewriteTableException { if (mappingEntries.isEmpty()) { return null; }//from ww w. ja v a 2 s .c o m Map<String, Collection<Mappings>> userMappingsMap = Multimaps .transformEntries(Multimaps.index(mappingEntries, new Function<InMemoryMappingEntry, String>() { public String apply(InMemoryMappingEntry mappingEntry) { return mappingEntry.asKey(); } }), new Maps.EntryTransformer<String, InMemoryMappingEntry, Mappings>() { public Mappings transformEntry(String s, InMemoryMappingEntry mappingEntry) { return MappingsImpl.fromRawString(mappingEntry.getMapping()); } }).asMap(); return Maps.transformEntries(userMappingsMap, new Maps.EntryTransformer<String, Collection<Mappings>, Mappings>() { public Mappings transformEntry(String s, Collection<Mappings> mappingsList) { Mappings result = MappingsImpl.empty(); for (Mappings mappings : mappingsList) { result = result.union(mappings); } return result; } }); }
From source file:org.graylog2.restclient.models.api.results.MessageResult.java
public Map<String, Object> getFormattedFields() { final DecimalFormat doubleFormatter = new DecimalFormat("#.###"); return Maps.transformEntries(getFilteredFields(), new Maps.EntryTransformer<String, Object, Object>() { @Override//w ww. ja v a 2 s . c o m public Object transformEntry(@Nullable String key, @Nullable Object value) { // Get rid of .0 of doubles. 9001.0 becomes "9001", 9001.25 becomes "9001.25" // Never format a double in scientific notation. if (value instanceof Double) { Double d = (Double) value; if (d.longValue() == d) { // preserve the "numberness" of the value, so the field mappers can take this into account // basically wait with stringification until the last moment in the template value = d.longValue(); } else { value = doubleFormatter.format(d); } } return fieldMapper.map(key, value); } }); }
From source file:com.pentaho.big.data.bundles.impl.shim.hbase.mapping.MappingImpl.java
@Override public void setMappedColumns(Map<String, HBaseValueMetaInterface> cols) { delegate.setMappedColumns(new HashMap<String, HBaseValueMeta>(Maps.transformEntries(cols, new Maps.EntryTransformer<String, HBaseValueMetaInterface, HBaseValueMeta>() { @Override/*from ww w . j a va 2s .com*/ public HBaseValueMeta transformEntry(String key, HBaseValueMetaInterface value) { if (value instanceof HBaseValueMeta) { return (HBaseValueMeta) value; } return hBaseValueMetaInterfaceFactory.copy(value); } }))); }
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(); }/*from ww w . j a va2s. c o m*/ 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; }
From source file:org.lanternpowered.server.game.registry.PluginCatalogRegistryModule.java
@Override public Map<String, T> provideCatalogMap() { final Map<String, Tuple<T, Integer>> mappings = new HashMap<>(); for (T type : this.types.values()) { final String mapping; final String id = type.getId().toLowerCase(Locale.ENGLISH); final int index = id.indexOf(':'); final String pluginId = id.substring(0, index); if (this.mappingProvider != null) { final String mapping1 = this.mappingProvider.apply(type); if (mapping1 == null) { continue; }/*ww w .j a v a 2s . c om*/ mapping = mapping1.toLowerCase(Locale.ENGLISH); } else { mapping = id.substring(index + 1); } final int priority = InternalPluginsInfo.IDENTIFIERS.indexOf(pluginId); if (mappings.containsKey(mapping)) { if (priority == -1) { continue; } final int lastPriority = mappings.get(mapping).getSecond(); if (lastPriority != -1 && priority > lastPriority) { continue; } } mappings.put(mapping, new Tuple<>(type, priority)); } //noinspection ConstantConditions return Maps.transformEntries(mappings, (key, value) -> value.getFirst()); }
From source file:com.tacitknowledge.flip.servlet.FlipOverrideFilter.java
/** * Moves the features descriptors generated on request parameters to the {@link FeatureDescriptorsMap}. * /*from w w w . j a va2s. co m*/ * @param request the request where to extract the request parameters. * @param featureDescriptors the {@link FeatureDescriptorsMap} where to store the {@link FeatureDescriptor} objects. */ private void applyRequestFeaturesToFeatureDescriptorsMap(final ServletRequest request, final FeatureDescriptorsMap featureDescriptors) { final Map<String, FeatureDescriptor> transformedParamMap = Maps.transformEntries(request.getParameterMap(), new RequestParametersTransformer()); final Map<String, FeatureDescriptor> parameterMap = Maps.filterEntries(transformedParamMap, new RequestParametersFilter()); for (final FeatureDescriptor descriptor : parameterMap.values()) { featureDescriptors.put(descriptor.getName(), descriptor); } }