本文整理了Java中scala.collection.JavaConverters.mapAsJavaMapConverter()
方法的一些代码示例,展示了JavaConverters.mapAsJavaMapConverter()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JavaConverters.mapAsJavaMapConverter()
方法的具体详情如下:
包路径:scala.collection.JavaConverters
类名称:JavaConverters
方法名:mapAsJavaMapConverter
暂无
代码示例来源:origin: twosigma/beakerx
private static Object asJava(Object scalaObject) {
if (scalaObject instanceof scala.collection.Seq) {
List objects = new ArrayList(Arrays.asList(
JavaConverters.asJavaCollectionConverter((Seq<?>) scalaObject).asJavaCollection()));
return objects.stream().map(Scala::asJava).collect(Collectors.toList());
} else if (scalaObject instanceof scala.collection.immutable.Map) {
@SuppressWarnings("unchecked")
scala.collection.immutable.Map<Object, Object> map = (scala.collection.immutable.Map<Object, Object>) scalaObject;
Map<Object, Object> objects = new HashMap<>(JavaConverters.mapAsJavaMapConverter(map).asJava());
return objects.entrySet().stream()
.collect(Collectors.toMap(incomingMap -> asJava(incomingMap.getKey()), incomingMap -> asJava(incomingMap.getValue())));
}
return scalaObject;
}
代码示例来源:origin: com.typesafe.play/play_2.10
/**
* Converts a Scala Map to Java.
*/
public static <K,V> java.util.Map<K,V> asJava(scala.collection.Map<K,V> scalaMap) {
return scala.collection.JavaConverters.mapAsJavaMapConverter(scalaMap).asJava();
}
代码示例来源:origin: com.typesafe.play/play
/**
* Converts a Scala Map to Java.
*
* @param scalaMap the scala map.
* @param <K> key type
* @param <V> value type
* @return the java map.
*/
public static <K, V> java.util.Map<K, V> asJava(scala.collection.Map<K, V> scalaMap) {
return scala.collection.JavaConverters.mapAsJavaMapConverter(scalaMap).asJava();
}
代码示例来源:origin: com.typesafe.play/play_2.11
/**
* Converts a Scala Map to Java.
*
* @param scalaMap the scala map.
* @param <K> key type
* @param <V> value type
* @return the java map.
*/
public static <K, V> java.util.Map<K, V> asJava(scala.collection.Map<K, V> scalaMap) {
return scala.collection.JavaConverters.mapAsJavaMapConverter(scalaMap).asJava();
}
代码示例来源:origin: com.typesafe.play/play_2.12
/**
* Converts a Scala Map to Java.
*
* @param scalaMap the scala map.
* @param <K> key type
* @param <V> value type
* @return the java map.
*/
public static <K, V> java.util.Map<K, V> asJava(scala.collection.Map<K, V> scalaMap) {
return scala.collection.JavaConverters.mapAsJavaMapConverter(scalaMap).asJava();
}
代码示例来源:origin: com.sandinh/play-alone
/**
* Converts a Scala Map to Java.
*/
public static <K,V> java.util.Map<K,V> asJava(scala.collection.Map<K,V> scalaMap) {
return scala.collection.JavaConverters.mapAsJavaMapConverter(scalaMap).asJava();
}
代码示例来源:origin: uber/hudi
public static <K, V> java.util.Map<K, V> toJavaMap(Map<K, V> m) {
return JavaConverters.mapAsJavaMapConverter(m).asJava();
}
}
代码示例来源:origin: com.uber.hoodie/hoodie-utilities
public static <K, V> java.util.Map<K, V> toJavaMap(Map<K, V> m) {
return JavaConverters.mapAsJavaMapConverter(m).asJava();
}
}
代码示例来源:origin: uber/marmaray
public static <K, V> Map<K, V> toJavaMap(@NonNull final scala.collection.Map<K, V> scalaMap) {
return JavaConverters.mapAsJavaMapConverter(scalaMap).asJava();
}
代码示例来源:origin: apache/samza
/**
* For each input stream specified in config, exactly determine its
* partitions, returning a set of SystemStreamPartitions containing them all.
*/
private Set<SystemStreamPartition> getInputStreamPartitions() {
TaskConfig taskConfig = new TaskConfig(config);
scala.collection.immutable.Set<SystemStream> inputSystemStreams = taskConfig.getInputStreams();
// Get the set of partitions for each SystemStream from the stream metadata
Set<SystemStreamPartition>
sspSet = JavaConverters.mapAsJavaMapConverter(streamMetadataCache.getStreamMetadata(inputSystemStreams, true)).asJava()
.entrySet()
.stream()
.flatMap(this::mapSSMToSSP)
.collect(Collectors.toSet());
return sspSet;
}
代码示例来源:origin: jgperrin/net.jgp.labs.spark
@Override
public BaseRelation createRelation(SQLContext arg0, Map<String,
String> arg1) {
log.debug("-> createRelation()");
java.util.Map<String, String> javaMap = scala.collection.JavaConverters
.mapAsJavaMapConverter(arg1).asJava();
SubStringCounterRelation br = new SubStringCounterRelation();
br.setSqlContext(arg0);
for (java.util.Map.Entry<String, String> entry : javaMap.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
log.debug("[{}] --> [{}]", key, value);
if (key.compareTo(K.PATH) == 0) {
br.setFilename(value);
} else if (key.startsWith(K.COUNT)) {
br.addCriteria(value);
}
}
return br;
}
代码示例来源:origin: gnuhpc/Kafka-zk-restapi
private List<TopicAndPartition> getTopicPartitions(String t) {
List<TopicAndPartition> tpList = new ArrayList<>();
List<String> l = Arrays.asList(t);
java.util.Map<String, Seq<Object>> tpMap =
JavaConverters.mapAsJavaMapConverter(
zkUtils.getPartitionsForTopics(
JavaConverters.asScalaIteratorConverter(l.iterator()).asScala().toSeq()))
.asJava();
if (tpMap != null) {
ArrayList<Object> partitionLists =
new ArrayList<>(JavaConverters.seqAsJavaListConverter(tpMap.get(t)).asJava());
tpList =
partitionLists.stream().map(p -> new TopicAndPartition(t, (Integer) p)).collect(toList());
}
return tpList;
}
代码示例来源:origin: apache/samza
/**
* Fetch SystemStreamMetadata for each topic with the consumer
* @param topics set of topics to get metadata info for
* @return map of topic to SystemStreamMetadata
*/
private Map<String, SystemStreamMetadata> fetchSystemStreamMetadata(Set<String> topics) {
Map<SystemStreamPartition, String> allOldestOffsets = new HashMap<>();
Map<SystemStreamPartition, String> allNewestOffsets = new HashMap<>();
Map<SystemStreamPartition, String> allUpcomingOffsets = new HashMap<>();
LOG.info("Fetching SystemStreamMetadata for topics {} on system {}", topics, systemName);
topics.forEach(topic -> {
List<PartitionInfo> partitionInfos = metadataConsumer.partitionsFor(topic);
if (partitionInfos == null) {
String msg = String.format("Partition info not(yet?) available for system %s topic %s", systemName, topic);
throw new SamzaException(msg);
}
List<TopicPartition> topicPartitions = partitionInfos.stream()
.map(partitionInfo -> new TopicPartition(partitionInfo.topic(), partitionInfo.partition()))
.collect(Collectors.toList());
OffsetsMaps offsetsForTopic = fetchTopicPartitionsMetadata(topicPartitions);
allOldestOffsets.putAll(offsetsForTopic.getOldestOffsets());
allNewestOffsets.putAll(offsetsForTopic.getNewestOffsets());
allUpcomingOffsets.putAll(offsetsForTopic.getUpcomingOffsets());
});
scala.collection.immutable.Map<String, SystemStreamMetadata> result =
KafkaSystemAdminUtilsScala.assembleMetadata(ScalaJavaUtil.toScalaMap(allOldestOffsets),
ScalaJavaUtil.toScalaMap(allNewestOffsets), ScalaJavaUtil.toScalaMap(allUpcomingOffsets));
LOG.debug("assembled SystemStreamMetadata is: {}", result);
return JavaConverters.mapAsJavaMapConverter(result).asJava();
}
代码示例来源:origin: Netflix/iceberg
private static <K, V> Map<K, V> toJavaMap(scala.collection.Map<K, V> map) {
return map == null ? null : mapAsJavaMapConverter(map).asJava();
}
代码示例来源:origin: apache/samza
/**
* Get the oldest offset for each changelog SSP based on the stream's metadata (obtained from streamMetadataCache).
*/
private void getOldestChangeLogOffsets() {
Map<SystemStream, SystemStreamMetadata> changeLogMetadata = JavaConverters.mapAsJavaMapConverter(
streamMetadataCache.getStreamMetadata(
JavaConverters.asScalaSetConverter(new HashSet<>(changelogSystemStreams.values())).asScala().toSet(),
false)).asJava();
LOG.info("Got change log stream metadata: {}", changeLogMetadata);
changeLogOldestOffsets =
getChangeLogOldestOffsetsForPartition(taskModel.getChangelogPartition(), changeLogMetadata);
LOG.info("Assigning oldest change log offsets for taskName {} : {}", taskModel.getTaskName(),
changeLogOldestOffsets);
}
代码示例来源:origin: apache/samza
/**
* Gets the metadata for all the specified system streams from the provided metadata cache.
* Handles scala-java conversions.
*
* @param streamsToMonitor the set of system streams for which the metadata is needed.
* @param metadataCache the metadata cache which will be used to fetch metadata.
* @return a map from each system stream to its metadata.
*/
private static Map<SystemStream, SystemStreamMetadata> getMetadata(Set<SystemStream> streamsToMonitor,
StreamMetadataCache metadataCache) {
return JavaConverters
.mapAsJavaMapConverter(
metadataCache.getStreamMetadata(
JavaConverters.asScalaSetConverter(streamsToMonitor).asScala().toSet(),
true
)
).asJava();
}
代码示例来源:origin: org.apache.samza/samza-core_2.11
/**
* Gets the metadata for all the specified system streams from the provided metadata cache.
* Handles scala-java conversions.
*
* @param streamsToMonitor the set of system streams for which the metadata is needed.
* @param metadataCache the metadata cache which will be used to fetch metadata.
* @return a map from each system stream to its metadata.
*/
private static Map<SystemStream, SystemStreamMetadata> getMetadata(Set<SystemStream> streamsToMonitor,
StreamMetadataCache metadataCache) {
return JavaConverters
.mapAsJavaMapConverter(
metadataCache.getStreamMetadata(
JavaConverters.asScalaSetConverter(streamsToMonitor).asScala().toSet(),
true
)
).asJava();
}
代码示例来源:origin: org.apache.samza/samza-core_2.12
/**
* Gets the metadata for all the specified system streams from the provided metadata cache.
* Handles scala-java conversions.
*
* @param streamsToMonitor the set of system streams for which the metadata is needed.
* @param metadataCache the metadata cache which will be used to fetch metadata.
* @return a map from each system stream to its metadata.
*/
private static Map<SystemStream, SystemStreamMetadata> getMetadata(Set<SystemStream> streamsToMonitor,
StreamMetadataCache metadataCache) {
return JavaConverters
.mapAsJavaMapConverter(
metadataCache.getStreamMetadata(
JavaConverters.asScalaSetConverter(streamsToMonitor).asScala().toSet(),
true
)
).asJava();
}
代码示例来源:origin: org.apache.samza/samza-core_2.10
/**
* Gets the metadata for all the specified system streams from the provided metadata cache.
* Handles scala-java conversions.
*
* @param streamsToMonitor the set of system streams for which the metadata is needed.
* @param metadataCache the metadata cache which will be used to fetch metadata.
* @return a map from each system stream to its metadata.
*/
private static Map<SystemStream, SystemStreamMetadata> getMetadata(Set<SystemStream> streamsToMonitor,
StreamMetadataCache metadataCache) {
return JavaConverters
.mapAsJavaMapConverter(
metadataCache.getStreamMetadata(
JavaConverters.asScalaSetConverter(streamsToMonitor).asScala().toSet(),
true
)
).asJava();
}
代码示例来源:origin: org.apache.samza/samza-core
/**
* Gets the metadata for all the specified system streams from the provided metadata cache.
* Handles scala-java conversions.
*
* @param streamsToMonitor the set of system streams for which the metadata is needed.
* @param metadataCache the metadata cache which will be used to fetch metadata.
* @return a map from each system stream to its metadata.
*/
private static Map<SystemStream, SystemStreamMetadata> getMetadata(Set<SystemStream> streamsToMonitor,
StreamMetadataCache metadataCache) {
return JavaConverters
.mapAsJavaMapConverter(
metadataCache.getStreamMetadata(
JavaConverters.asScalaSetConverter(streamsToMonitor).asScala().toSet(),
true
)
).asJava();
}
内容来源于网络,如有侵权,请联系作者删除!