scala.collection.Iterator类的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(9.9k)|赞(0)|评价(0)|浏览(213)

本文整理了Java中scala.collection.Iterator类的一些代码示例,展示了Iterator类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Iterator类的具体详情如下:
包路径:scala.collection.Iterator
类名称:Iterator

Iterator介绍

暂无

代码示例

代码示例来源:origin: twosigma/beakerx

public static SparkConf getSparkConfBasedOn(SparkSession.Builder sparkSessionBuilder) {
 try {
  SparkConf sparkConf = new SparkConf();
  Field options = sparkSessionBuilder.getClass().getDeclaredField("org$apache$spark$sql$SparkSession$Builder$$options");
  options.setAccessible(true);
  Iterator iterator = ((scala.collection.mutable.HashMap) options.get(sparkSessionBuilder)).iterator();
  while (iterator.hasNext()) {
   Tuple2 x = (Tuple2) iterator.next();
   sparkConf.set((String) (x)._1, (String) (x)._2);
  }
  return sparkConf;
 } catch (Exception e) {
  throw new RuntimeException(e);
 }
}

代码示例来源:origin: linkedin/cruise-control

JavaConverters.asScalaIteratorConverter(newAssignedReplica.iterator()).asScala().toSeq());

代码示例来源:origin: linkedin/kafka-monitor

private static List<PartitionInfo> getPartitionInfo(KafkaZkClient zkClient, String topic) {
 scala.collection.immutable.Set<String> topicList = new scala.collection.immutable.Set.Set1<>(topic);
 scala.collection.Map<Object, scala.collection.Seq<Object>> partitionAssignments =
   zkClient.getPartitionAssignmentForTopics(topicList).apply(topic);
 List<PartitionInfo> partitionInfoList = new ArrayList<>();
 scala.collection.Iterator<scala.Tuple2<Object, scala.collection.Seq<Object>>> it = partitionAssignments.iterator();
 while (it.hasNext()) {
  scala.Tuple2<Object, scala.collection.Seq<Object>> scalaTuple = it.next();
  Integer partition = (Integer) scalaTuple._1();
  scala.Option<Object> leaderOption = zkClient.getLeaderForPartition(new TopicPartition(topic, partition));
  Node leader = leaderOption.isEmpty() ?  null : new Node((Integer) leaderOption.get(), "", -1);
  Node[] replicas = new Node[scalaTuple._2().size()];
  for (int i = 0; i < replicas.length; i++) {
   Integer brokerId = (Integer) scalaTuple._2().apply(i);
   replicas[i] = new Node(brokerId, "", -1);
  }
  partitionInfoList.add(new PartitionInfo(topic, partition, leader, replicas, null));
 }
 return partitionInfoList;
}

代码示例来源:origin: edu.cmu.ml.rtw/matt-util

public static <V> List<V> scalaToJavaList(scala.collection.Seq<V> scalaList) {
  List<V> javaList = Lists.newArrayList();
  scala.collection.Iterator<V> iterator = scalaList.iterator();
  while (iterator.hasNext()) {
   javaList.add(iterator.next());
  }
  return javaList;
 }
}

代码示例来源:origin: openzipkin/zipkin-finagle

@Override public void incrementMessagesDropped(Throwable cause) {
 if (cause instanceof FinagleSender.WrappedException) cause = cause.getCause();
 Seq<Traversable<String>> paths = Throwables.mkString(cause).inits().toSeq();
 for (Iterator<Traversable<String>> i = paths.iterator(); i.hasNext();) {
  messagesDropped.counter(i.next().toSeq()).incr();
 }
}

代码示例来源:origin: open-korean-text/elasticsearch-analysis-openkoreantext

@Override
protected Seq<KoreanToken> perform(Seq<KoreanToken> tokens) {
  KoreanToken[] performed = new KoreanToken[tokens.length()];
  int i = 0;
  Iterator<KoreanToken> tokenIterator =  tokens.iterator();
  while (tokenIterator.hasNext()) {
    KoreanToken token = tokenIterator.next();
    performed[i++] = token.stem().nonEmpty() ? stem(token) : token;
  }
  return JavaConverters.asScalaBuffer(Arrays.asList(performed)).toSeq();
}

代码示例来源:origin: dcaoyuan/nbscala

@Override
  public void run(ResultIterator resultIterator) throws Exception {
    ScalaRootScope rootScope = ((ScalaParserResult) resultIterator.getParserResult()).rootScope();
    if (rootScope == null) {
      return;
    }
    rootScope.visibleDfns(ElementKind.CLASS);
    scala.collection.Seq<AstDfn> tmpls = rootScope.visibleDfns(ElementKind.CLASS);
    if (!tmpls.isEmpty()) {
      scala.collection.Iterator itr = tmpls.iterator();
      while (itr.hasNext()) {
        AstDfn tmpl = (AstDfn) itr.next();
        if (classes[0].length() > 0) {
          classes[0] = classes[0] + " ";            // NOI18N
        }
        classes[0] = classes[0] + tmpl.getName().toString().replace('.', '/') + "*.class";  // NOI18N
      }
    }
  }
});

代码示例来源:origin: vakinge/jeesuite-libs

public List<BrokerInfo> fetchAllBrokers(){
  List<BrokerInfo> result = new ArrayList<>();
  Seq<Broker> brokers = zkUtils.getAllBrokersInCluster();
  Iterator<Broker> iterator = brokers.toList().iterator();
  while(iterator.hasNext()){
    Broker broker = iterator.next();
    Node node = broker.getNode(ListenerName.forSecurityProtocol(SecurityProtocol.PLAINTEXT)).get();
    result.add(new BrokerInfo(node.idString(), node.host(), node.port()));
  }
  return result;
}

代码示例来源:origin: org.opendaylight.controller/sal-distributed-datastore

@VisibleForTesting
static MemberName memberToName(final Member member) {
  return MemberName.forName(member.roles().iterator().next());
}

代码示例来源:origin: org.mule.modules/edi-module-common

/**
 * Build metadata for structures list.
 *
 * @param root
 * @param structKey key for map of structure lists in root
 * @param read input version of structure data
 */
public void buildStructures(DynamicObjectBuilder<?> root, String structKey, boolean read) {
  DynamicObjectBuilder<?> structuresMap = root.addDynamicObjectField(structKey);
  Iterator<String> keys = schema.structures().keysIterator();
  while (!keys.isEmpty()) {
    Structure structure = (Structure)schema.structures().apply(keys.next());
    DynamicObjectBuilder<?> tranMap = structuresMap.addList(structure.ident()).
      ofDynamicObject(structure.ident());
    buildStructure(structure, read, tranMap);
  }
}

代码示例来源:origin: org.openkoreantext/open-korean-text

/**
 * Tokenize with the builder options into a String Iterable.
 *
 * @param tokens Korean tokens (output of tokenize(CharSequence text)).
 * @return List of token strings.
 */
public static List<String> tokensToJavaStringList(Seq<KoreanToken> tokens, boolean keepSpace) {
 Iterator<KoreanToken> tokenized = tokens.iterator();
 List<String> output = new LinkedList<>();
 while (tokenized.hasNext()) {
  final KoreanToken token = tokenized.next();
  if (keepSpace || token.pos() != KoreanPos.Space()) {
   output.add(token.text());
  }
 }
 return output;
}

代码示例来源:origin: io.zipkin.finagle2/zipkin-finagle

@Override public void incrementMessagesDropped(Throwable cause) {
 if (cause instanceof FinagleSender.WrappedException) cause = cause.getCause();
 Seq<Traversable<String>> paths = Throwables.mkString(cause).inits().toSeq();
 for (Iterator<Traversable<String>> i = paths.iterator(); i.hasNext();) {
  messagesDropped.counter(i.next().toSeq()).incr();
 }
}

代码示例来源:origin: open-korean-text/elasticsearch-analysis-openkoreantext

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();
  }
}

代码示例来源:origin: jpmml/jpmml-sparkml

List<Double> coefficients = new ArrayList<>(VectorUtil.toList(thetaRows.next()));

代码示例来源:origin: twitter/distributedlog

scala.collection.Iterator<Address> endpointAddressesIterator = endpointAddresses.toIterator();
HashSet<ServiceInstance> serviceInstances = new HashSet<ServiceInstance>();
while (endpointAddressesIterator.hasNext()) {
  serviceInstances.add(endpointAddressToServiceInstance(endpointAddressesIterator.next()));

代码示例来源:origin: dcaoyuan/nbscala

scala.collection.Iterator<AstDfn> itr = rootScope.visibleDfns(ElementKind.PACKAGE).iterator();
while (itr.hasNext()) {
  AstDfn packaging = itr.next();
  objs = packaging.bindingScope().visibleDfns(ElementKind.CLASS);
  break;
itr = objs.iterator();
while (itr.hasNext()) {
  AstDfn obj = itr.next();
  if (obj.qualifiedName().equals(mainClassName)) {
    mainClass = obj;

代码示例来源:origin: io.zipkin.finagle/zipkin-finagle

@Override public void incrementMessagesDropped(Throwable cause) {
 Seq<Traversable<String>> paths = Throwables.mkString(cause).inits().toSeq();
 for (Iterator<Traversable<String>> i = paths.iterator(); i.hasNext();) {
  messagesDropped.counter(i.next().toSeq()).incr();
 }
}

代码示例来源:origin: apache/phoenix

/**
 * Sets the schema using all the table columns before any column pruning has been done
 */
private void setSchema() {
  try (Connection conn = DriverManager.getConnection("jdbc:phoenix:" + zkUrl)) {
    List<ColumnInfo> columnInfos = PhoenixRuntime.generateColumnInfo(conn, tableName, null);
    Seq<ColumnInfo> columnInfoSeq = JavaConverters.asScalaIteratorConverter(columnInfos.iterator()).asScala().toSeq();
    schema = SparkSchemaUtil.phoenixSchemaToCatalystSchema(columnInfoSeq, dateAsTimestamp);
  }
  catch (SQLException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: org.apache.spark/spark-core_2.10

@Override
public void write(scala.collection.Iterator<Product2<K, V>> records) throws IOException {
 // Keep track of success so we know if we encountered an exception
 // We do this rather than a standard try/catch/re-throw to handle
 // generic throwables.
 boolean success = false;
 try {
  while (records.hasNext()) {
   insertRecordIntoSorter(records.next());
  }
  closeAndWriteOutput();
  success = true;
 } finally {
  if (sorter != null) {
   try {
    sorter.cleanupResources();
   } catch (Exception e) {
    // Only throw this error if we won't be masking another
    // error.
    if (success) {
     throw e;
    } else {
     logger.error("In addition to a failure during writing, we failed during " +
            "cleanup.", e);
    }
   }
  }
 }
}

代码示例来源:origin: org.openkoreantext/open-korean-text

/**
 * Transforms the tokenization output to List<KoreanTokenJava>
 *
 * @param tokens Korean tokens (output of tokenize(CharSequence text)).
 * @return List of KoreanTokenJava.
 */
public static List<KoreanTokenJava> tokensToJavaKoreanTokenList(Seq<KoreanToken> tokens, boolean keepSpace) {
 Iterator<KoreanToken> tokenized = tokens.iterator();
 List<KoreanTokenJava> output = new LinkedList<>();
 while (tokenized.hasNext()) {
  KoreanToken token = tokenized.next();
  String stem = "";
  if (token.stem().nonEmpty()) {
   stem += token.stem().get();
  }
  if (keepSpace || token.pos() != KoreanPos.Space()) {
   output.add(new KoreanTokenJava(
     token.text(),
     KoreanPosJava.valueOf(token.pos().toString()),
     token.offset(),
     token.length(),
     token.unknown(),
     stem
   ));
  }
 }
 return output;
}

相关文章