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

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

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

Iterable介绍

暂无

代码示例

代码示例来源:origin: com.typesafe.play/play

/**
 * Converts a Java Collection to a Scala Seq.
 *
 * @param javaCollection the java collection
 * @param <A>            the type of Seq element
 * @return the scala Seq.
 */
public static <A> scala.collection.immutable.Seq<A> asScala(Collection<A> javaCollection) {
  return scala.collection.JavaConverters.collectionAsScalaIterableConverter(javaCollection).asScala().toList();
}

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

@Test
public void combineByKey() {
 JavaRDD<Integer> originalRDD = sc.parallelize(Arrays.asList(1, 2, 3, 4, 5, 6));
 Function<Integer, Integer> keyFunction = v1 -> v1 % 3;
 Function<Integer, Integer> createCombinerFunction = v1 -> v1;
 Function2<Integer, Integer, Integer> mergeValueFunction = (v1, v2) -> v1 + v2;
 JavaPairRDD<Integer, Integer> combinedRDD = originalRDD.keyBy(keyFunction)
  .combineByKey(createCombinerFunction, mergeValueFunction, mergeValueFunction);
 Map<Integer, Integer> results = combinedRDD.collectAsMap();
 ImmutableMap<Integer, Integer> expected = ImmutableMap.of(0, 9, 1, 5, 2, 7);
 assertEquals(expected, results);
 Partitioner defaultPartitioner = Partitioner.defaultPartitioner(
  combinedRDD.rdd(),
  JavaConverters.collectionAsScalaIterableConverter(
   Collections.<RDD<?>>emptyList()).asScala().toSeq());
 combinedRDD = originalRDD.keyBy(keyFunction)
  .combineByKey(
   createCombinerFunction,
   mergeValueFunction,
   mergeValueFunction,
   defaultPartitioner,
   false,
   new KryoSerializer(new SparkConf()));
 results = combinedRDD.collectAsMap();
 assertEquals(expected, results);
}

代码示例来源:origin: com.mangofactory.swagger/swagger-models

@Override
public com.google.common.base.Optional<Model> modelFor(ModelContext modelContext) {
  ResolvedType propertiesHost = alternateTypeProvider.alternateFor(modelContext.resolvedType(resolver));
  if (isContainerType(propertiesHost)
      || propertiesHost.getErasedType().isEnum()
      || Types.isBaseType(Types.typeNameFor(propertiesHost.getErasedType()))) {
    return Optional.absent();
  }
  Map<String, ModelProperty> properties = newLinkedHashMap();
  int index = 0;
  for (com.mangofactory.swagger.models.property.ModelProperty each : properties(modelContext, propertiesHost)) {
    properties.put(each.getName(), new ModelProperty(each.typeName(modelContext),
        each.qualifiedTypeName(),
        index,
        each.isRequired(),
        each.propertyDescription(),
        each.allowableValues(),
        itemModelRef(each.getType())
    ));
  }
  return Optional.of(new Model(typeName(propertiesHost),
      typeName(propertiesHost),
      simpleQualifiedTypeName(propertiesHost),
      toScalaLinkedHashMap(properties),
      modelDescription(propertiesHost), Option.apply(""),
      Option.<String>empty(),
      collectionAsScalaIterable(new ArrayList<String>()).toList()));
}

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

public static Object scalaIterableCheck(Object array, Schema schema) {
 Class collectionClass = ScalaSafeReflectData.getClassProp(schema,
   ScalaSafeReflectData.CLASS_PROP);
 if (collectionClass != null) {
  if (scala.collection.Iterable.class.isAssignableFrom(collectionClass)) {
   scala.collection.Iterable it = toIter(array);
   if (scala.collection.immutable.List.class.isAssignableFrom(collectionClass)) {
    return it.toList();
   }
   if (scala.collection.mutable.Buffer.class.isAssignableFrom(collectionClass)) {
    return it.toBuffer();
   }
   if (scala.collection.immutable.Set.class.isAssignableFrom(collectionClass)) {
    return it.toSet();
   }
   return it;
  }
 }
 return array;
}

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

int asyncTaskCount = taskInstances.values().count(new AbstractFunction1<TaskInstance, Object>() {
 @Override
 public Boolean apply(TaskInstance t) {

代码示例来源:origin: org.scala-lang.modules/scala-java8-compat_2.11

/** 
 * Generates a Stream that traverses a scala.collection.Iterable.
 * <p>
 * Only sequential operations will be efficient.
 * For efficient parallel operation, use the streamAccumulated method instead,
 * but note that this creates a copy of the contents of the Iterable
 *
 * @param coll The scala.collection.Iterable to traverse
 * @return     A Stream view of the collection which, by default, executes sequentially.
 */
public static <T> Stream<T> stream(scala.collection.Iterable<T> coll) {
  return StreamSupport.stream(new StepsAnyIterator<T>(coll.iterator()), false);
}

代码示例来源:origin: com.typesafe.akka/akka-http-core_2.11

@SuppressWarnings("unchecked")
public static <T, U extends T> Seq<U> convertIterable(Iterable<T> els) {
  return scala.collection.JavaConverters.iterableAsScalaIterableConverter((Iterable<U>)els).asScala().toVector();
}
public static <T, U extends T> Seq<U> convertArray(T[] els) {

代码示例来源:origin: org.apache.samza/samza-core_2.12

int asyncTaskCount = taskInstances.values().count(new AbstractFunction1<TaskInstance, Object>() {
 @Override
 public Boolean apply(TaskInstance t) {

代码示例来源:origin: org.scala-lang.modules/scala-java8-compat_2.12

/** 
 * Generates a Stream that traverses a scala.collection.Iterable.
 * <p>
 * Only sequential operations will be efficient.
 * For efficient parallel operation, use the streamAccumulated method instead,
 * but note that this creates a copy of the contents of the Iterable
 *
 * @param coll The scala.collection.Iterable to traverse
 * @return     A Stream view of the collection which, by default, executes sequentially.
 */
public static <T> Stream<T> stream(scala.collection.Iterable<T> coll) {
  return StreamSupport.stream(new StepsAnyIterator<T>(coll.iterator()), false);
}

代码示例来源:origin: com.typesafe.akka/akka-http-core_2.12

@SuppressWarnings("unchecked")
public static <T, U extends T> Seq<U> convertIterable(Iterable<T> els) {
  return scala.collection.JavaConverters.iterableAsScalaIterableConverter((Iterable<U>)els).asScala().toVector();
}
public static <T, U extends T> Seq<U> convertArray(T[] els) {

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

@Test
public void combineByKey() {
 JavaRDD<Integer> originalRDD = sc.parallelize(Arrays.asList(1, 2, 3, 4, 5, 6));
 Function<Integer, Integer> keyFunction = v1 -> v1 % 3;
 Function<Integer, Integer> createCombinerFunction = v1 -> v1;
 Function2<Integer, Integer, Integer> mergeValueFunction = (v1, v2) -> v1 + v2;
 JavaPairRDD<Integer, Integer> combinedRDD = originalRDD.keyBy(keyFunction)
  .combineByKey(createCombinerFunction, mergeValueFunction, mergeValueFunction);
 Map<Integer, Integer> results = combinedRDD.collectAsMap();
 ImmutableMap<Integer, Integer> expected = ImmutableMap.of(0, 9, 1, 5, 2, 7);
 assertEquals(expected, results);
 Partitioner defaultPartitioner = Partitioner.defaultPartitioner(
  combinedRDD.rdd(),
  JavaConverters.collectionAsScalaIterableConverter(
   Collections.<RDD<?>>emptyList()).asScala().toSeq());
 combinedRDD = originalRDD.keyBy(keyFunction)
  .combineByKey(
   createCombinerFunction,
   mergeValueFunction,
   mergeValueFunction,
   defaultPartitioner,
   false,
   new KryoSerializer(new SparkConf()));
 results = combinedRDD.collectAsMap();
 assertEquals(expected, results);
}

代码示例来源:origin: com.typesafe.play/play_2.11

/**
 * Converts a Java Collection to a Scala Seq.
 *
 * @param javaCollection the java collection
 * @param <A>            the type of Seq element
 * @return the scala Seq.
 */
public static <A> scala.collection.immutable.Seq<A> asScala(Collection<A> javaCollection) {
  return scala.collection.JavaConverters.collectionAsScalaIterableConverter(javaCollection).asScala().toList();
}

代码示例来源:origin: org.apache.samza/samza-core

int asyncTaskCount = taskInstances.values().count(new AbstractFunction1<TaskInstance, Object>() {
 @Override
 public Boolean apply(TaskInstance t) {

代码示例来源:origin: org.scala-lang.modules/scala-java8-compat

/** 
 * Generates a Stream that traverses a scala.collection.Iterable.
 * <p>
 * Only sequential operations will be efficient.
 * For efficient parallel operation, use the streamAccumulated method instead,
 * but note that this creates a copy of the contents of the Iterable
 *
 * @param coll The scala.collection.Iterable to traverse
 * @return     A Stream view of the collection which, by default, executes sequentially.
 */
public static <T> Stream<T> stream(scala.collection.Iterable<T> coll) {
  return StreamSupport.stream(new StepsAnyIterator<T>(coll.iterator()), false);
}

代码示例来源:origin: com.typesafe.akka/akka-http-core

@SuppressWarnings("unchecked")
public static <T, U extends T> Seq<U> convertIterable(Iterable<T> els) {
  return scala.collection.JavaConverters.iterableAsScalaIterableConverter((Iterable<U>)els).asScala().toVector();
}
public static <T, U extends T> Seq<U> convertArray(T[] els) {

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

@Test
public void combineByKey() {
 JavaRDD<Integer> originalRDD = sc.parallelize(Arrays.asList(1, 2, 3, 4, 5, 6));
 Function<Integer, Integer> keyFunction = v1 -> v1 % 3;
 Function<Integer, Integer> createCombinerFunction = v1 -> v1;
 Function2<Integer, Integer, Integer> mergeValueFunction = (v1, v2) -> v1 + v2;
 JavaPairRDD<Integer, Integer> combinedRDD = originalRDD.keyBy(keyFunction)
  .combineByKey(createCombinerFunction, mergeValueFunction, mergeValueFunction);
 Map<Integer, Integer> results = combinedRDD.collectAsMap();
 ImmutableMap<Integer, Integer> expected = ImmutableMap.of(0, 9, 1, 5, 2, 7);
 assertEquals(expected, results);
 Partitioner defaultPartitioner = Partitioner.defaultPartitioner(
  combinedRDD.rdd(),
  JavaConverters.collectionAsScalaIterableConverter(
   Collections.<RDD<?>>emptyList()).asScala().toSeq());
 combinedRDD = originalRDD.keyBy(keyFunction)
  .combineByKey(
   createCombinerFunction,
   mergeValueFunction,
   mergeValueFunction,
   defaultPartitioner,
   false,
   new KryoSerializer(new SparkConf()));
 results = combinedRDD.collectAsMap();
 assertEquals(expected, results);
}

代码示例来源:origin: com.typesafe.play/play_2.12

/**
 * Converts a Java Collection to a Scala Seq.
 *
 * @param javaCollection the java collection
 * @param <A>            the type of Seq element
 * @return the scala Seq.
 */
public static <A> scala.collection.immutable.Seq<A> asScala(Collection<A> javaCollection) {
  return scala.collection.JavaConverters.collectionAsScalaIterableConverter(javaCollection).asScala().toList();
}

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

int asyncTaskCount = taskInstances.values().count(new AbstractFunction1<TaskInstance, Object>() {
 @Override
 public Boolean apply(TaskInstance t) {

代码示例来源:origin: org.scala-lang.modules/scala-java8-compat_2.12

/** 
 * Generates a LongStream that traverses a long-valued scala.collection.Iterable.
 * <p>
 * Only sequential operations will be efficient.
 * For efficient parallel operation, use the longStreamAccumulated method instead,
 * but note that this creates a copy of the contents of the Iterable.
 *
 * @param coll The scala.collection.Iterable to traverse
 * @return     A LongStream view of the collection which, by default, executes sequentially.
 */
public static LongStream longStream(scala.collection.Iterable<Long> coll) {
  scala.collection.Iterator iter = (scala.collection.Iterator)coll.iterator();        
  return StreamSupport.longStream(new StepsLongIterator(iter), false);
}

代码示例来源:origin: com.typesafe.akka/akka-http-core-experimental

@SuppressWarnings("unchecked")
public static <T, U extends T> Seq<U> convertIterable(Iterable<T> els) {
  return scala.collection.JavaConverters.iterableAsScalaIterableConverter((Iterable<U>)els).asScala().toVector();
}
@SuppressWarnings("unchecked")

相关文章