本文整理汇总了Java中scala.collection.JavaConversions.seqAsJavaList方法的典型用法代码示例。如果您正苦于以下问题:Java JavaConversions.seqAsJavaList方法的具体用法?Java JavaConversions.seqAsJavaList怎么用?Java JavaConversions.seqAsJavaList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scala.collection.JavaConversions
的用法示例。
在下文中一共展示了JavaConversions.seqAsJavaList方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processTopic
import scala.collection.JavaConversions; //导入方法依赖的package包/类
public List<OffsetInfo> processTopic(String group, String topic) throws Exception {
List<String> partitionIds = null;
try {
partitionIds = JavaConversions.seqAsJavaList(ZKUtils.getZKUtilsFromKafka()
.getChildren(ZkUtils.BrokerTopicsPath() + "/" + topic + "/partitions"));
} catch (Exception e) {
if (e instanceof NoNodeException) {
LOG.warn("Is topic >" + topic + "< exists!", e);
return null;
}
}
List<OffsetInfo> offsetInfos = new ArrayList<OffsetInfo>();
OffsetInfo offsetInfo = null;
if (partitionIds == null) {
// TODO that topic exists in consumer node but not in topics node?!
return null;
}
for (String partitionId : partitionIds) {
offsetInfo = processPartition(group, topic, partitionId);
if (offsetInfo != null) {
offsetInfos.add(offsetInfo);
}
}
return offsetInfos;
}
示例2: getOffsets
import scala.collection.JavaConversions; //导入方法依赖的package包/类
/**
* @param zkServers Zookeeper server string: host1:port1[,host2:port2,...]
* @param groupID consumer group to get offsets for
* @param topic topic to get offsets for
* @return mapping of (topic and) partition to offset
*/
public static Map<Pair<String,Integer>,Long> getOffsets(String zkServers,
String groupID,
String topic) {
ZKGroupTopicDirs topicDirs = new ZKGroupTopicDirs(groupID, topic);
Map<Pair<String,Integer>,Long> offsets = new HashMap<>();
ZkUtils zkUtils = ZkUtils.apply(zkServers, ZK_TIMEOUT_MSEC, ZK_TIMEOUT_MSEC, false);
try {
List<?> partitions = JavaConversions.seqAsJavaList(
zkUtils.getPartitionsForTopics(
JavaConversions.asScalaBuffer(Collections.singletonList(topic))).head()._2());
partitions.forEach(partition -> {
String partitionOffsetPath = topicDirs.consumerOffsetDir() + "/" + partition;
Option<String> maybeOffset = zkUtils.readDataMaybeNull(partitionOffsetPath)._1();
Long offset = maybeOffset.isDefined() ? Long.valueOf(maybeOffset.get()) : null;
offsets.put(new Pair<>(topic, Integer.valueOf(partition.toString())), offset);
});
} finally {
zkUtils.close();
}
return offsets;
}
示例3: in
import scala.collection.JavaConversions; //导入方法依赖的package包/类
/**
* Pass a Scala Seq of inputs to the script. The inputs are either two-value
* or three-value tuples, where the first value is the variable name, the
* second value is the variable value, and the third optional value is the
* metadata.
*
* @param inputs
* Scala Seq of inputs (parameters ($) and variables).
* @return {@code this} Script object to allow chaining of methods
*/
public Script in(scala.collection.Seq<Object> inputs) {
List<Object> list = JavaConversions.seqAsJavaList(inputs);
for (Object obj : list) {
if (obj instanceof Tuple3) {
@SuppressWarnings("unchecked")
Tuple3<String, Object, MatrixMetadata> t3 = (Tuple3<String, Object, MatrixMetadata>) obj;
in(t3._1(), t3._2(), t3._3());
} else if (obj instanceof Tuple2) {
@SuppressWarnings("unchecked")
Tuple2<String, Object> t2 = (Tuple2<String, Object>) obj;
in(t2._1(), t2._2());
} else {
throw new MLContextException("Only Tuples of 2 or 3 values are permitted");
}
}
return this;
}
示例4: getTopics
import scala.collection.JavaConversions; //导入方法依赖的package包/类
public List<String> getTopics() {
List<String> topics = null;
try {
topics = JavaConversions
.seqAsJavaList(ZKUtils.getZKUtilsFromKafka().getChildren(ZkUtils.BrokerTopicsPath()));
} catch (Exception e) {
LOG.error("could not get topics because of " + e.getMessage(), e);
}
return topics;
}
示例5: getClusterViz
import scala.collection.JavaConversions; //导入方法依赖的package包/类
public Node getClusterViz() {
Node rootNode = new Node("KafkaCluster");
List<Node> childNodes = new ArrayList<Node>();
List<Broker> brokers = JavaConversions.seqAsJavaList(ZKUtils.getZKUtilsFromKafka().getAllBrokersInCluster());
brokers.forEach(broker -> {
List<EndPoint> endPoints = JavaConversions.seqAsJavaList(broker.endPoints().seq());
childNodes.add(new Node(broker.id() + ":" + endPoints.get(0).host() + ":" + endPoints.get(0).port(), null));
});
rootNode.setChildren(childNodes);
return rootNode;
}
示例6: buildPredicate
import scala.collection.JavaConversions; //导入方法依赖的package包/类
private Predicate buildPredicate(Split split,
CategoricalValueEncodings categoricalValueEncodings) {
if (split == null) {
// Left child always applies, but is evaluated second
return new True();
}
int featureIndex = inputSchema.predictorToFeatureIndex(split.feature());
FieldName fieldName = FieldName.create(inputSchema.getFeatureNames().get(featureIndex));
if (split.featureType().equals(FeatureType.Categorical())) {
// Note that categories in MLlib model select the *left* child but the
// convention here will be that the predicate selects the *right* child
// So the predicate will evaluate "not in" this set
// More ugly casting
@SuppressWarnings("unchecked")
List<Double> javaCategories = (List<Double>) (List<?>)
JavaConversions.seqAsJavaList(split.categories());
Set<Integer> negativeEncodings = javaCategories.stream().map(Double::intValue).collect(Collectors.toSet());
Map<Integer,String> encodingToValue =
categoricalValueEncodings.getEncodingValueMap(featureIndex);
List<String> negativeValues = negativeEncodings.stream().map(encodingToValue::get).collect(Collectors.toList());
String joinedValues = TextUtils.joinPMMLDelimited(negativeValues);
return new SimpleSetPredicate(fieldName,
SimpleSetPredicate.BooleanOperator.IS_NOT_IN,
new Array(Array.Type.STRING, joinedValues));
} else {
// For MLlib, left means <= threshold, so right means >
return new SimplePredicate(fieldName, SimplePredicate.Operator.GREATER_THAN)
.setValue(Double.toString(split.threshold()));
}
}
示例7: getOffsets
import scala.collection.JavaConversions; //导入方法依赖的package包/类
public static Map<TopicAndPartition, Long> getOffsets(String zkKafkaServers,
String zkOffSetManager,
String groupID,
String topic,
Map<String, String> kafkaParams) {
ZKGroupTopicDirs topicDirs = new ZKGroupTopicDirs(groupID, topic);
Map<TopicAndPartition, Long> offsets = new HashMap<>();
AutoZkClient zkKafkaClient = new AutoZkClient(zkKafkaServers);
AutoZkClient zkOffsetManagerClient = new AutoZkClient(zkOffSetManager);
List<?> partitions = JavaConversions.seqAsJavaList(
ZkUtils.getPartitionsForTopics(
zkKafkaClient,
JavaConversions.asScalaBuffer(Collections.singletonList(topic))).head()._2());
partitions.forEach(partition -> {
String partitionOffsetPath = topicDirs.consumerOffsetDir() + "/" + partition;
log.info("Offset location, zookeeper path=" + partitionOffsetPath);
Option<String> maybeOffset = ZkUtils.readDataMaybeNull(zkOffsetManagerClient, partitionOffsetPath)._1();
Long offset = maybeOffset.isDefined() ? Long.parseLong(maybeOffset.get()) : null;
TopicAndPartition topicAndPartition = new TopicAndPartition(topic, Integer.parseInt(partition.toString()));
offsets.put(topicAndPartition, offset);
});
fillInLatestOffsets(offsets, kafkaParams); // in case offsets are blank for any partition
return offsets;
}
示例8: getBootstrapServers
import scala.collection.JavaConversions; //导入方法依赖的package包/类
/**
* Gets a list of servers that are up in the cluster
*
* @param maxNumServers Maximum number of bootstrap servers that should be returned. Note that
* less servers may be returned than the maximum.
* @return A list of bootstrap servers, or an empty list if there are none or if there were
* errors. Note that only servers with PLAINTEXT ports will be returned.
*/
public List<String> getBootstrapServers(KafkaZkClient zkClient, int maxNumServers) {
Objects.requireNonNull(zkClient, "zkClient must not be null");
if (maxNumServers < 1) {
throw new IllegalArgumentException("maximum number of requested servers must be >= 1");
}
// Note that we only support PLAINTEXT ports for this version
List<Broker> brokers = JavaConversions.seqAsJavaList(zkClient.getAllBrokersInCluster());
if (brokers == null) {
return Collections.emptyList();
} else {
List<String> bootstrapServers = new ArrayList<>();
for (Broker broker : brokers) {
for (EndPoint endPoint : JavaConversions.seqAsJavaList(broker.endPoints())) {
if (endPoint.listenerName().value().equals("PLAINTEXT")) {
bootstrapServers.add(endPoint.connectionString());
if (bootstrapServers.size() == maxNumServers) {
break;
}
}
}
}
return bootstrapServers;
}
}
示例9: getProgressFromStage_1_0x
import scala.collection.JavaConversions; //导入方法依赖的package包/类
private int[] getProgressFromStage_1_0x(JobProgressListener sparkListener, Object stage)
throws IllegalAccessException, IllegalArgumentException,
InvocationTargetException, NoSuchMethodException, SecurityException {
int numTasks = (int) stage.getClass().getMethod("numTasks").invoke(stage);
int completedTasks = 0;
int id = (int) stage.getClass().getMethod("id").invoke(stage);
Object completedTaskInfo = null;
completedTaskInfo = JavaConversions.mapAsJavaMap(
(HashMap<Object, Object>) sparkListener.getClass()
.getMethod("stageIdToTasksComplete").invoke(sparkListener)).get(id);
if (completedTaskInfo != null) {
completedTasks += (int) completedTaskInfo;
}
List<Object> parents = JavaConversions.seqAsJavaList((Seq<Object>) stage.getClass()
.getMethod("parents").invoke(stage));
if (parents != null) {
for (Object s : parents) {
int[] p = getProgressFromStage_1_0x(sparkListener, s);
numTasks += p[0];
completedTasks += p[1];
}
}
return new int[] {numTasks, completedTasks};
}
示例10: getProgressFromStage_1_1x
import scala.collection.JavaConversions; //导入方法依赖的package包/类
private int[] getProgressFromStage_1_1x(JobProgressListener sparkListener, Object stage)
throws IllegalAccessException, IllegalArgumentException,
InvocationTargetException, NoSuchMethodException, SecurityException {
int numTasks = (int) stage.getClass().getMethod("numTasks").invoke(stage);
int completedTasks = 0;
int id = (int) stage.getClass().getMethod("id").invoke(stage);
try {
Method stageIdToData = sparkListener.getClass().getMethod("stageIdToData");
HashMap<Tuple2<Object, Object>, Object> stageIdData =
(HashMap<Tuple2<Object, Object>, Object>) stageIdToData.invoke(sparkListener);
Class<?> stageUIDataClass =
this.getClass().forName("org.apache.spark.ui.jobs.UIData$StageUIData");
Method numCompletedTasks = stageUIDataClass.getMethod("numCompleteTasks");
Set<Tuple2<Object, Object>> keys =
JavaConverters.setAsJavaSetConverter(stageIdData.keySet()).asJava();
for (Tuple2<Object, Object> k : keys) {
if (id == (int) k._1()) {
Object uiData = stageIdData.get(k).get();
completedTasks += (int) numCompletedTasks.invoke(uiData);
}
}
} catch (Exception e) {
logger.error("Error on getting progress information", e);
}
List<Object> parents = JavaConversions.seqAsJavaList((Seq<Object>) stage.getClass()
.getMethod("parents").invoke(stage));
if (parents != null) {
for (Object s : parents) {
int[] p = getProgressFromStage_1_1x(sparkListener, s);
numTasks += p[0];
completedTasks += p[1];
}
}
return new int[] {numTasks, completedTasks};
}
示例11: calculate
import scala.collection.JavaConversions; //导入方法依赖的package包/类
@Override
public Double calculate(SparkContext sc, Seq<Tuple2<EmptyParams, RDD<Tuple3<Query, PredictedResult, Set<String>>>>> qpas) {
List<Tuple2<EmptyParams, RDD<Tuple3<Query, PredictedResult, Set<String>>>>> sets = JavaConversions.seqAsJavaList(qpas);
List<Double> allSetResults = new ArrayList<>();
for (Tuple2<EmptyParams, RDD<Tuple3<Query, PredictedResult, Set<String>>>> set : sets) {
List<Double> setResults = set._2().toJavaRDD().map(new Function<Tuple3<Query, PredictedResult, Set<String>>, Double>() {
@Override
public Double call(Tuple3<Query, PredictedResult, Set<String>> qpa) throws Exception {
Set<String> predicted = new HashSet<>();
for (ItemScore itemScore : qpa._2().getItemScores()) {
predicted.add(itemScore.getItemEntityId());
}
Set<String> intersection = new HashSet<>(predicted);
intersection.retainAll(qpa._3());
return 1.0 * intersection.size() / qpa._2().getItemScores().size();
}
}).collect();
allSetResults.addAll(setResults);
}
double sum = 0.0;
for (Double value : allSetResults) sum += value;
return sum / allSetResults.size();
}
示例12: process
import scala.collection.JavaConversions; //导入方法依赖的package包/类
@Override
public void process(
VariantContextWritable input, Emitter<Pair<Variant, Collection<Genotype>>> emitter) {
VariantContext bvc = input.get();
List<org.bdgenomics.adam.models.VariantContext> avcList =
JavaConversions.seqAsJavaList(vcc.convert(bvc));
for (org.bdgenomics.adam.models.VariantContext avc : avcList) {
Variant variant = avc.variant().variant();
Collection<Genotype> genotypes = JavaConversions.asJavaCollection(avc.genotypes());
emitter.emit(Pair.of(variant, genotypes));
}
}
示例13: convertClassToThriftType
import scala.collection.JavaConversions; //导入方法依赖的package包/类
/**
* In composite types, such as the type of the key in a map, since we use reflection to get the type class, this method
* does conversion based on the class provided.
*
* @return converted ThriftType
*/
private ThriftType convertClassToThriftType(String name, Requirement requirement, Manifest<?> typeManifest) {
Class typeClass = typeManifest.runtimeClass();
if (typeManifest.runtimeClass() == boolean.class) {
return new ThriftType.BoolType();
} else if (typeClass == byte.class) {
return new ThriftType.ByteType();
} else if (typeClass == double.class) {
return new ThriftType.DoubleType();
} else if (typeClass == short.class) {
return new ThriftType.I16Type();
} else if (typeClass == int.class) {
return new ThriftType.I32Type();
} else if (typeClass == long.class) {
return new ThriftType.I64Type();
} else if (typeClass == String.class) {
return new ThriftType.StringType();
} else if (typeClass == ByteBuffer.class) {
return new ThriftType.StringType();
} else if (typeClass == scala.collection.Seq.class) {
Manifest<?> a = typeManifest.typeArguments().apply(0);
return convertListTypeField(name, a, requirement);
} else if (typeClass == scala.collection.Set.class) {
Manifest<?> setElementManifest = typeManifest.typeArguments().apply(0);
return convertSetTypeField(name, setElementManifest, requirement);
} else if (typeClass == scala.collection.Map.class) {
List<Manifest<?>> ms = JavaConversions.seqAsJavaList(typeManifest.typeArguments());
Manifest keyManifest = ms.get(0);
Manifest valueManifest = ms.get(1);
return convertMapTypeField(name, keyManifest, valueManifest, requirement);
} else if (com.twitter.scrooge.ThriftEnum.class.isAssignableFrom(typeClass)) {
return convertEnumTypeField(typeClass, name);
} else {
return convertStructFromClass(typeClass);
}
}
示例14: getEnumList
import scala.collection.JavaConversions; //导入方法依赖的package包/类
/**
* When define an enum in scrooge, each enum value is a subclass of the enum class, the enum class could be Operation$
*/
private List getEnumList(String enumName) throws ClassNotFoundException, IllegalAccessException, NoSuchFieldException, NoSuchMethodException, InvocationTargetException {
enumName += "$";//In scala generated code, the actual class is ended with $
Class companionObjectClass = Class.forName(enumName);
Object cObject = companionObjectClass.getField("MODULE$").get(null);
Method listMethod = companionObjectClass.getMethod("list", new Class[]{});
Object result = listMethod.invoke(cObject, null);
return JavaConversions.seqAsJavaList((Seq) result);
}
示例15: authors
import scala.collection.JavaConversions; //导入方法依赖的package包/类
public static List<String> authors(Map<String, Object> auth, boolean ex) {
String key = ex ? "ex_authors" : "authors";
if (auth.contains(key)) {
Option val = ScalaUtils.unwrap(auth.get(key));
if (val.isDefined()) {
return JavaConversions.seqAsJavaList((scala.collection.immutable.List) val.get());
}
}
return Lists.newArrayList();
}