本文整理汇总了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)
}
}
}
示例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)
})
}
}
示例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
}