本文整理汇总了Java中scala.collection.JavaConverters类的典型用法代码示例。如果您正苦于以下问题:Java JavaConverters类的具体用法?Java JavaConverters怎么用?Java JavaConverters使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JavaConverters类属于scala.collection包,在下文中一共展示了JavaConverters类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertPhrasesToTokens
import scala.collection.JavaConverters; //导入依赖的package包/类
private Seq<KoreanToken> convertPhrasesToTokens(Seq<KoreanPhrase> phrases) {
KoreanToken[] tokens = new KoreanToken[phrases.length()];
Iterator<KoreanPhrase> iterator = phrases.iterator();
int i = 0;
while (iterator.hasNext()) {
KoreanPhrase phrase = iterator.next();
tokens[i++] = new KoreanToken(phrase.text(), phrase.pos(), phrase.offset(), phrase.length(), scala.Option.apply(null), false);
}
Arrays.sort(tokens, (o1, o2) -> {
if(o1.offset()== o2.offset())
return 0;
return o1.offset()< o2.offset()? -1 : 1;
});
return JavaConverters.asScalaBuffer(Arrays.asList(tokens)).toSeq();
}
开发者ID:open-korean-text,项目名称:elasticsearch-analysis-openkoreantext,代码行数:19,代码来源:OpenKoreanTextPhraseExtractor.java
示例2: incrementToken
import scala.collection.JavaConverters; //导入依赖的package包/类
@Override
public final boolean incrementToken() throws IOException {
clearAttributes();
if(input instanceof KoreanTokenPrepareable) {
if(preparedTokens == null) {
this.preparedTokens = JavaConverters.seqAsJavaList(prepareKoreanTokens());
}
if (this.preparedTokens == null || this.preparedTokens.isEmpty() || tokenIndex >= this.preparedTokens.size()) {
return false;
}
setAttributes(this.preparedTokens.get(tokenIndex++));
return true;
} else {
return input.incrementToken();
}
}
开发者ID:open-korean-text,项目名称:elasticsearch-analysis-openkoreantext,代码行数:20,代码来源:OpenKoreanTextTokenFilter.java
示例3: deserialize
import scala.collection.JavaConverters; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Object deserialize(JsonNode n, ObjectMapper mapper) {
org.apache.commons.lang3.tuple.Pair<String, Object> deserializeObject = TableDisplayDeSerializer.getDeserializeObject(parent, n, mapper);
String subtype = deserializeObject.getLeft();
if (subtype != null && subtype.equals(TableDisplay.DICTIONARY_SUBTYPE)) {
return JavaConverters.mapAsScalaMapConverter((Map<String, Object>) deserializeObject.getRight()).asScala().toMap(Predef.<Tuple2<String, Object>>conforms());
} else if (subtype != null && subtype.equals(TableDisplay.LIST_OF_MAPS_SUBTYPE)) {
List<Map<String, Object>> rows = (List<Map<String, Object>>) deserializeObject.getRight();
List<Object> oo = new ArrayList<Object>();
for (Map<String, Object> row : rows) {
oo.add(JavaConverters.mapAsScalaMapConverter(row).asScala().toMap(Predef.<Tuple2<String, Object>>conforms()));
}
return scala.collection.JavaConversions.collectionAsScalaIterable(oo);
} else if (subtype != null && subtype.equals(TableDisplay.MATRIX_SUBTYPE)) {
List<List<?>> matrix = (List<List<?>>) deserializeObject.getRight();
ArrayList<Object> ll = new ArrayList<Object>();
for (List<?> ob : matrix) {
ll.add(scala.collection.JavaConversions.asScalaBuffer(ob).toList());
}
return scala.collection.JavaConversions.asScalaBuffer(ll).toList();
}
return deserializeObject.getRight();
}
示例4: writeBatch
import scala.collection.JavaConverters; //导入依赖的package包/类
private Future<Optional<Exception>> writeBatch(AtomicWrite atomicWrite) {
return storage.execute(atomicWrite.persistenceId(), cache, (entityIdParam, cacheParam) -> {
try {
Map<Long, JournalItem> batch = JavaConverters
.seqAsJavaListConverter(atomicWrite.payload())
.asJava().stream()
.map(this::convert)
.collect(Collectors.toMap(JournalItem::getSequenceNr, item -> item));
cache.putAll(batch);
if (log.isDebugEnabled()) {
log.debug("doAsyncWriteMessages persistenceId'{}': batch {}", atomicWrite.persistenceId(), batch);
}
return Optional.empty();
} catch (Exception e) {
log.error(e.getMessage(), e);
return Optional.of(e);
}
});
}
示例5: generateData
import scala.collection.JavaConverters; //导入依赖的package包/类
private String generateData(boolean printHeader, boolean longTimestamp, String Timezone, String dataFormat)
{
LocalDateTime queryTime = LocalDateTime.now();
if(isTest)
queryTime = LocalDateTime.parse("2016-01-01T00:00:00.000");
// Get the time Values for the current time
scala.collection.Iterable<Tuple3<String, LocalDateTime, Object>> data = SimController.getTimeValue(simConfig.timeSeries(), queryTime);
// Convert the Scala Iterable to a Java one
Iterable<Tuple3<String, LocalDateTime, Object>> generatedValues = JavaConverters.asJavaIterableConverter(data).asJava();
String resultString = "";
if (dataFormat.equals("CSV")){
resultString = createCsv(printHeader, longTimestamp, Timezone, generatedValues);
}
else if (dataFormat.equals("JSON")){
resultString = generateJson(longTimestamp, Timezone, generatedValues);
}
return resultString;
}
示例6: getReplicaAssignmentForTopic
import scala.collection.JavaConverters; //导入依赖的package包/类
private scala.collection.Map<Object, Seq<Object>> getReplicaAssignmentForTopic(
ZkUtils zkUtils, String topic) {
if (topicPartitionAssignments.containsKey(topic)) {
return topicPartitionAssignments.get(topic);
}
List<String> topics = new ArrayList<>();
topics.add(topic);
Seq<String> topicsSeq = scala.collection.JavaConverters.asScalaBuffer(topics).toSeq();
scala.collection.mutable.Map<String, scala.collection.Map<Object, Seq<Object>>> assignments;
assignments = zkUtils.getPartitionAssignmentForTopics(topicsSeq);
scala.collection.Map<Object, Seq<Object>> partitionAssignment = assignments.get(topic).get();
topicPartitionAssignments.put(topic, partitionAssignment);
return partitionAssignment;
}
示例7: collectNodes
import scala.collection.JavaConverters; //导入依赖的package包/类
private static void collectNodes(GraphNode node, Map<GraphNode, Integer> processed,
Map<GraphNode, Integer> counts, AtomicInteger counter) {
if (node.relatedNodes().size() > 0) {
if (!processed.containsKey(node)) {
int id = counter.incrementAndGet();
processed.put(node, id);
counts.put(node, 1);
JavaConverters.asJavaCollectionConverter(node.relatedNodes()).asJavaCollection()
.forEach(c -> collectNodes(c, processed, counts, counter));
}
else {
counts.put(node, counts.get(node) + 1);
}
}
else {
if (!processed.containsKey(node)) {
processed.put(node, 0);
counts.put(node, 1);
}
else {
counts.put(node, counts.get(node) + 1);
}
}
}
示例8: filterMetaInf
import scala.collection.JavaConverters; //导入依赖的package包/类
public static ArtifactSource filterMetaInf(ArtifactSource source) {
return source.filter(new AbstractFunction1<DirectoryArtifact, Object>() {
@Override
public Object apply(DirectoryArtifact dir) {
// This is required to remove our maven packaging information
if (dir.name().equals("META-INF")) {
Optional<Artifact> nonMavenArtifact = JavaConverters
.asJavaCollectionConverter(dir.artifacts()).asJavaCollection().stream()
.filter(a -> !a.path().startsWith("META-INF/maven")).findAny();
return nonMavenArtifact.isPresent();
}
return (!dir.path().equals("META-INF/maven"));
}
}, new AbstractFunction1<FileArtifact, Object>() {
@Override
public Object apply(FileArtifact arg0) {
return true;
}
});
}
示例9: getGearpumpState
import scala.collection.JavaConverters; //导入依赖的package包/类
private State getGearpumpState() {
ApplicationStatus status = null;
List<AppMasterData> apps =
JavaConverters.<AppMasterData>seqAsJavaListConverter(
(Seq<AppMasterData>) client.listApps().appMasters()).asJava();
for (AppMasterData appData: apps) {
if (appData.appId() == app.appId()) {
status = appData.status();
}
}
if (null == status || status instanceof ApplicationStatus.NONEXIST$) {
return State.UNKNOWN;
} else if (status instanceof ApplicationStatus.ACTIVE$) {
return State.RUNNING;
} else if (status instanceof ApplicationStatus.SUCCEEDED$) {
return State.DONE;
} else {
return State.FAILED;
}
}
示例10: testCassandraScalaTupleAtLeastOnceSinkBuilderDetection
import scala.collection.JavaConverters; //导入依赖的package包/类
@Test
public void testCassandraScalaTupleAtLeastOnceSinkBuilderDetection() throws Exception {
Class<scala.Tuple1<String>> c = (Class<scala.Tuple1<String>>) new scala.Tuple1<>("hello").getClass();
Seq<TypeInformation<?>> typeInfos = JavaConverters.asScalaBufferConverter(
Collections.<TypeInformation<?>>singletonList(BasicTypeInfo.STRING_TYPE_INFO)).asScala();
Seq<String> fieldNames = JavaConverters.asScalaBufferConverter(
Collections.singletonList("_1")).asScala();
CaseClassTypeInfo<scala.Tuple1<String>> typeInfo = new CaseClassTypeInfo<scala.Tuple1<String>>(c, null, typeInfos, fieldNames) {
@Override
public TypeSerializer<scala.Tuple1<String>> createSerializer(ExecutionConfig config) {
return null;
}
};
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
DataStream<scala.Tuple1<String>> input = env.fromElements(new scala.Tuple1<>("hello")).returns(typeInfo);
CassandraSink.CassandraSinkBuilder<scala.Tuple1<String>> sinkBuilder = CassandraSink.addSink(input);
assertTrue(sinkBuilder instanceof CassandraSink.CassandraScalaProductSinkBuilder);
}
示例11: getMetricsReporters
import scala.collection.JavaConverters; //导入依赖的package包/类
public static Map<String, MetricsReporter> getMetricsReporters(MetricsConfig config, String containerName) {
Map<String, MetricsReporter> metricsReporters = new HashMap<>();
for (String metricsReporterName : JavaConverters.seqAsJavaListConverter(config.getMetricReporterNames()).asJava()) {
String metricsFactoryClass = config.getMetricsFactoryClass(metricsReporterName).get();
if (metricsFactoryClass == null) {
throw new SamzaException(String.format("Metrics reporter %s missing .class config", metricsReporterName));
}
MetricsReporterFactory metricsReporterFactory = Util.getObj(metricsFactoryClass);
metricsReporters.put(metricsReporterName,
metricsReporterFactory.getMetricsReporter(metricsReporterName,
containerName,
config));
}
return metricsReporters;
}
示例12: caseCall
import scala.collection.JavaConverters; //导入依赖的package包/类
private void caseCall(InvokeExpr m, Option<Value> baseValue) {
Option<Var<?>> base =
baseValue.isDefined() ? Vars.getAll(baseValue.get()).find(FunctionsForJava.<Var<?>>constantTrue()) : Option.<Var<?>>empty();
// baseValue.flatMap(v -> Interop.asJavaStream().findFirst());
List<Option<Var<?>>> args = new ArrayList<>();
for (soot.Value v : m.getArgs()) {
List<Var<?>> vars = (List<Var<?>>)JavaConverters.seqAsJavaListConverter(Vars.getAll(v).toSeq()).asJava();
if (vars.isEmpty()) {
args.add(Option.<Var<?>>empty());
} else if (vars.size() == 1) {
args.add(Option.<Var<?>>apply(vars.get(0)));
} else {
throw new RuntimeException("Unexpected: multiple variables contained in a call argumnent");
}
}
caseCall(m.getMethod(), base, args);
}
示例13: deserialize
import scala.collection.JavaConverters; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Object deserialize(JsonNode n, ObjectMapper mapper) {
org.apache.commons.lang3.tuple.Pair<String, Object> deserializeObject = TableDisplayDeSerializer.getDeserializeObject(parent, n, mapper);
String subtype = deserializeObject.getLeft();
if (subtype != null && subtype.equals(TableDisplay.DICTIONARY_SUBTYPE)) {
return JavaConverters.mapAsScalaMapConverter((Map<String, Object>) deserializeObject.getRight()).asScala().toMap(Predef.<Tuple2<String, Object>>conforms());
} else if (subtype != null && subtype.equals(TableDisplay.LIST_OF_MAPS_SUBTYPE)) {
List<Map<String, Object>> rows = (List<Map<String, Object>>) deserializeObject.getRight();
List<Object> oo = new ArrayList<Object>();
for (Map<String, Object> row : rows) {
oo.add(JavaConverters.mapAsScalaMapConverter(row).asScala().toMap(Predef.<Tuple2<String, Object>>conforms()));
}
return scala.collection.JavaConversions.collectionAsScalaIterable(oo);
} else if (subtype != null && subtype.equals(TableDisplay.MATRIX_SUBTYPE)) {
List<List<?>> matrix = (List<List<?>>) deserializeObject.getRight();
ArrayList<Object> ll = new ArrayList<Object>();
for (List<?> ob : matrix) {
ll.add(scala.collection.JavaConversions.asScalaBuffer(ob).toList());
}
return scala.collection.JavaConversions.asScalaBuffer(ll).toList();
}
return deserializeObject.getRight();
}
示例14: RaygunPlayScalaRequestHeaderMessage
import scala.collection.JavaConverters; //导入依赖的package包/类
public RaygunPlayScalaRequestHeaderMessage(RequestHeader scalaRequestHeader)
{
try
{
hostName = scalaRequestHeader.host();
url = scalaRequestHeader.uri();
httpMethod = scalaRequestHeader.method();
ipAddress = scalaRequestHeader.remoteAddress();
String rawQuery = scalaRequestHeader.rawQueryString();
if (!rawQuery.isEmpty())
{
queryString = queryStringToMap(rawQuery);
}
headers = JavaConverters.mapAsJavaMapConverter(scalaRequestHeader.headers().toSimpleMap()).asJava();
}
catch (Throwable t)
{
Logger.getLogger("Raygun4Java-Play2").info("Couldn't get all request params: " + t.getMessage());
}
}
示例15: RaygunPlayScalaRequestMessage
import scala.collection.JavaConverters; //导入依赖的package包/类
public RaygunPlayScalaRequestMessage(Request request)
{
try
{
httpMethod = request.method();
ipAddress = request.remoteAddress();
hostName = request.host();
url = request.uri();
headers = JavaConverters.mapAsJavaMapConverter(request.headers().toSimpleMap()).asJava();
String rawQuery = request.rawQueryString();
if (!rawQuery.isEmpty())
{
queryString = queryStringToMap(rawQuery);
}
}
catch (NullPointerException e)
{
Logger.getLogger("Raygun4Java-Play2").info("Couldn't get all request params: " + e.getMessage());
}
}