当前位置: 首页>>代码示例>>Scala>>正文


Scala Iterable类代码示例

本文整理汇总了Scala中scala.collection.Iterable的典型用法代码示例。如果您正苦于以下问题:Scala Iterable类的具体用法?Scala Iterable怎么用?Scala Iterable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Iterable类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: encode

//设置package包名称以及导入依赖的类
package com.ox.bigdata.util.kafka

import kafka.common.KafkaException
import kafka.utils.Logging

import scala.collection.{Iterable, Map}
import scala.util.parsing.json.JSON


  def encode(obj: Any): String = {
    obj match {
      case null => "null"
      case b: Boolean => b.toString
      case s: String => "\"" + s + "\""
      case n: Number => n.toString
      case m: Map[_, _] =>
        "{" +
          m.map(elem =>
            elem match {
              case t: Tuple2[_, _] => encode(t._1) + ":" + encode(t._2)
              case _ => throw new IllegalArgumentException("Invalid map element (" + elem + ") in " + obj)
            }).mkString(",") +
          "}"
      case a: Array[_] => encode(a.toSeq)
      case i: Iterable[_] => "[" + i.map(encode).mkString(",") + "]"
      case other: AnyRef => throw new IllegalArgumentException("Unknown arguement of type " + other.getClass + ": " + other)
    }
  }
} 
开发者ID:black-ox,项目名称:simple,代码行数:30,代码来源:Json.scala

示例2: PersonService

//设置package包名称以及导入依赖的类
package com.ntsdev.service

import com.ntsdev.domain.Person
import com.ntsdev.repository.PersonRepository
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service

import scala.collection.Iterable
import scala.collection.JavaConversions._

@Service
class PersonService {

  @Autowired
  val personRepository: PersonRepository = null

  
  def peopleWithContactsDepthOne: Iterable[Person] = {
    val people: Iterable[Person] = personRepository.findConnections

    def clearConnections(contact: Person) = {
      contact.copy(contacts = Set.empty[Person])
    }

    people.map(rootPerson => {
      val personContacts: Set[Person] = rootPerson.contacts.toSet
      val subContacts: Set[Person] = personContacts.map(clearConnections)
      rootPerson.copy(contacts = subContacts)
    })
  }
} 
开发者ID:neilshannon,项目名称:atlanta-scala-microservice,代码行数:32,代码来源:PersonService.scala

示例3: IncrementalSeq

//设置package包名称以及导入依赖的类
package inox.utils

import scala.collection.mutable.Builder
import scala.collection.mutable.ArrayBuffer
import scala.collection.{Iterable, IterableLike}

class IncrementalSeq[A] extends IncrementalState
                        with Iterable[A]
                        with IterableLike[A, Seq[A]]
                        with Builder[A, IncrementalSeq[A]] {

  private[this] var stack: List[ArrayBuffer[A]] = List(new ArrayBuffer())

  def clear() : Unit = {
    stack = List(new ArrayBuffer())
  }

  def reset(): Unit = {
    clear()
  }

  def push(): Unit = {
    stack ::= stack.head.clone
  }

  def pop(): Unit = {
    stack = stack.tail
  }

  def iterator = stack.head.toList.iterator
  def +=(e: A) = { stack.head += e; this }
  def -=(e: A) = { stack.head -= e; this }

  override def newBuilder = new scala.collection.mutable.ArrayBuffer()
  def result = this
} 
开发者ID:epfl-lara,项目名称:inox,代码行数:37,代码来源:IncrementalSeq.scala


注:本文中的scala.collection.Iterable类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。