本文整理汇总了Scala中scala.collection.immutable.VectorBuilder类的典型用法代码示例。如果您正苦于以下问题:Scala VectorBuilder类的具体用法?Scala VectorBuilder怎么用?Scala VectorBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了VectorBuilder类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: maintainSum
//设置package包名称以及导入依赖的类
package hu.bme.mit.ire.nodes.unary
import hu.bme.mit.ire.datatypes._
import hu.bme.mit.ire.messages.ChangeSet
import hu.bme.mit.ire.util.GenericMath
import scala.collection.immutable.VectorBuilder
import scala.collection.mutable
trait SumLike {
val sums = new mutable.HashMap[Tuple, Any].withDefault(d => 0)
def maintainSum(changeSet: ChangeSet, aggregationKeys: Vector[Int], sumKey: Int): ChangeSet = {
val oldValues = new mutable.HashMap[Tuple, Any]
for (tuple <- changeSet.positive;
key = aggregationKeys.map(tuple(_))) {
if (!oldValues.contains(key)) {
oldValues(key) = sums(key)
}
sums(key) = GenericMath.plus(sums(key), tuple(sumKey))
}
for (tuple <- changeSet.negative;
key = aggregationKeys.map(tuple(_))) {
if (!oldValues.contains(key)) {
oldValues(key) = sums(key)
}
sums(key) = GenericMath.minus(sums(key), tuple(sumKey))
}
val positive = new VectorBuilder[Tuple]
val negative = new VectorBuilder[Tuple]
for ((key, oldValue) <- oldValues) {
if (oldValue != 0) {
negative += key :+ oldValues(key)
}
if (sums(key) != 0) {
positive += key :+ sums(key)
}
}
return ChangeSet(positive = positive.result(), negative = negative.result())
}
}
示例2: Level
//设置package包名称以及导入依赖的类
package com.oradian.dictionarycheck
import java.io._
import scala.collection.immutable.VectorBuilder
sealed trait Level
object Level {
case object Info extends Level
case object Warning extends Level
case object Error extends Level
def fromString(level: String): Level = level.toLowerCase match {
case "info" => Info
case "warning" => Warning
case "error" => Error
case _ => sys.error("Unknown level: " + level)
}
}
case class DictionaryEntry(pattern: String, level: Level, message: String)
case class Dictionary(entries: Seq[DictionaryEntry]) {
private[this] val lookup = entries flatMap { entry =>
val pattern = entry.pattern
val upperPattern = pattern.toUpperCase
val lowerPattern = pattern.toLowerCase
val sentencePattern = pattern.head.toUpper + pattern.tail
val targets = Seq(pattern, upperPattern, lowerPattern, sentencePattern)
targets.distinct map { target => target -> entry }
} toMap
def get(pattern: String): Option[DictionaryEntry] =
lookup.get(pattern)
}
object Dictionary {
private[this] val LineEntry = """([^;]+?);([^;]+?);(.*)""".r
def parse(path: String): Dictionary = {
val reader = new BufferedReader(new InputStreamReader(new FileInputStream(path)))
try {
val entries = new VectorBuilder[DictionaryEntry]
var line: String = null
while ({ line = reader.readLine(); line != null }) {
val LineEntry(patternStr, levelStr, messageStr) = line
entries += DictionaryEntry(
pattern = patternStr.trim,
level = Level.fromString(levelStr),
message = messageStr.trim
)
}
new Dictionary(entries.result)
} finally {
reader.close()
}
}
}
示例3: LineRendering
//设置package包名称以及导入依赖的类
package swave.core.graph.impl
import java.lang.StringBuilder
import swave.core.graph.{Digraph, GlyphSet}
import scala.collection.immutable.VectorBuilder
import Infrastructure._
private[graph] object LineRendering {
def renderLines[V](nodes: Vector[Node], glyphSet: GlyphSet): Digraph.Rendering[V] = {
var charBuf: Array[Char] = Array.emptyCharArray
val lines = new VectorBuilder[String]
val sb = new StringBuilder
var maxLineLength = 0
val vertexRenderings =
for (node ? nodes) yield {
val maxChars = node.glyphs.size * glyphSet.columns * 2
if (charBuf.length < maxChars) charBuf = new Array[Char](maxChars)
lines.clear()
for (glyphRow ? 0 until glyphSet.rows) {
val endIx = node.glyphs.foldLeft(0)((ix, glyph) ? glyphSet.place(glyph, glyphRow, charBuf, ix))
sb.append(charBuf, 0, endIx)
// trim whitespace at line end
while (sb.length > 0 && Character.isWhitespace(sb.charAt(sb.length - 1))) sb.setLength(sb.length - 1)
// if (glyphRow == glyphSet.rows / 2) sb.append(' ').append(node.xRank.level)
val line = sb.toString
maxLineLength = math.max(maxLineLength, line.length)
lines += line
sb.setLength(0)
}
Digraph.VertexRendering(node.vertex.asInstanceOf[V], lines.result())
}
Digraph.Rendering(glyphSet, maxLineLength, vertexRenderings)
}
}
示例4: fixtureState
//设置package包名称以及导入依赖的类
package swave.core.internal.testkit
import scala.collection.immutable.VectorBuilder
import scala.concurrent.{Future, Promise}
import swave.core.impl.stages.StageImpl
private[testkit] trait TestStage extends StageImpl {
private[this] val resultBuilder = new VectorBuilder[AnyRef]
private[this] var _resultSize = 0
private[this] var _fixtureState: TestFixture.State = TestFixture.State.Starting
private[this] val _finishedState = Promise[TestFixture.State.Finished]()
private[this] var onElem: AnyRef ? Unit = x ? ()
def fixtureState: TestFixture.State = _fixtureState
def fixtureState_=(value: TestFixture.State): Unit = {
value match {
case TestFixture.State.Cancelled ? _finishedState.success(TestFixture.State.Cancelled)
case TestFixture.State.Completed ? _finishedState.success(TestFixture.State.Completed)
case TestFixture.State.Error(e) ? _finishedState.failure(e)
case _ ?
}
_fixtureState = value
}
def finishedState: Future[TestFixture.State.Finished] = _finishedState.future
private[testkit] final def result[T]: Vector[T] = resultBuilder.result().asInstanceOf[Vector[T]]
private[testkit] final def resultSize: Int = _resultSize
protected final def recordElem(elem: AnyRef): Unit = {
resultBuilder += elem
_resultSize += 1
onElem(elem)
}
def appendElemHandler(f: AnyRef ? Unit): Unit = {
val prev = onElem
onElem = { elem ?
prev(elem)
f(elem)
}
}
def id: Int
def formatLong: String
def scriptedSize: Int
}
示例5: maintainCount
//设置package包名称以及导入依赖的类
package hu.bme.mit.ire.nodes.unary
import hu.bme.mit.ire.datatypes._
import hu.bme.mit.ire.messages.ChangeSet
import scala.collection.immutable.VectorBuilder
import scala.collection.mutable
trait CountLike {
val counts = new mutable.HashMap[Tuple, Int].withDefault(d => 0)
def maintainCount(changeSet: ChangeSet, aggregationKeys: Vector[Int]): ChangeSet = {
val oldValues = new mutable.HashMap[Tuple, Int]
for (tuple <- changeSet.positive;
key = aggregationKeys.map(tuple(_))) {
if (!oldValues.contains(key)) {
oldValues(key) = counts(key)
}
counts(key) += 1
}
for (tuple <- changeSet.negative;
key = aggregationKeys.map(tuple(_))) {
if (!oldValues.contains(key)) {
oldValues(key) = counts(key)
}
counts(key) -= 1
}
val positive = new VectorBuilder[Tuple]
val negative = new VectorBuilder[Tuple]
for ((key, oldValue) <- oldValues) {
if (oldValue != 0) {
negative += key :+ oldValues(key)
}
if (counts(key) != 0) {
positive += key :+ counts(key)
}
}
return ChangeSet(positive = positive.result(), negative = negative.result())
}
}
示例6: ExtremeNode
//设置package包名称以及导入依赖的类
package hu.bme.mit.ire.nodes.unary
import hu.bme.mit.ire.SingleForwarder
import hu.bme.mit.ire.datatypes._
import hu.bme.mit.ire.messages.{ChangeSet, ReteMessage}
import hu.bme.mit.ire.util.SizeCounter
import scala.collection.immutable.VectorBuilder
import scala.collection.mutable
abstract class ExtremeNode(override val next: (ReteMessage) => Unit,
val aggregationKeys: Vector[Int],
val extremeKey: Int,
override val expectedTerminatorCount: Int = 1
) extends UnaryNode with SingleForwarder {
val data = new mutable.HashMap[Vector[Any], mutable.SortedSet[Tuple]]()
implicit val order : Ordering[Tuple]
override def onSizeRequest(): Long = SizeCounter.count(data.values)
override def onChangeSet(changeSet: ChangeSet): Unit = {
val oldValues = new mutable.HashMap[Vector[Any], Option[Any]]
for (tuple <- changeSet.positive;
key = aggregationKeys.map(tuple(_))) {
if (!oldValues.contains(key)) {
oldValues(key) = data.get(key).map(_.last(extremeKey))
}
data.getOrElseUpdate(key, mutable.SortedSet[Tuple]()) += tuple
}
for (tuple <- changeSet.negative;
key = aggregationKeys.map(tuple(_))) {
if (!oldValues.contains(key)) {
oldValues(key) = data.get(key).map(_.last(extremeKey))
}
data(key) -= tuple
}
val positive = new VectorBuilder[Tuple]
val negative = new VectorBuilder[Tuple]
for ((key, oldValue) <- oldValues) {
if (oldValue.isEmpty || data(key) != oldValue.get)
if (oldValue.isDefined) {
negative += key :+ oldValues(key).get
}
positive += key :+ data(key).last(extremeKey)
}
forward(ChangeSet(positive = positive.result(), negative = negative.result()))
}
}
示例7: CollectNode
//设置package包名称以及导入依赖的类
package hu.bme.mit.ire.nodes.unary
import hu.bme.mit.ire.SingleForwarder
import hu.bme.mit.ire.datatypes._
import hu.bme.mit.ire.messages.{ChangeSet, ReteMessage}
import hu.bme.mit.ire.util.SizeCounter
import scala.collection.immutable.VectorBuilder
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
class CollectNode(override val next: (ReteMessage) => Unit,
val aggregationKeys: Vector[Int],
val collectKey: Int) extends UnaryNode with SingleForwarder {
val collections = new mutable.HashMap[Tuple, ListBuffer[Any]].withDefault(d => new ListBuffer())
override def onSizeRequest(): Long = SizeCounter.count(collections.values)
def maintainCollections(changeSet: ChangeSet, aggregationKeys: Vector[Int], collectKey: Int): ChangeSet = {
val oldValues = new mutable.HashMap[Tuple, ListBuffer[Any]]
for (tuple <- changeSet.positive;
key = aggregationKeys.map(tuple(_))) {
if (!oldValues.contains(key)) {
oldValues(key) = collections(key)
}
collections(key) = collections(key) :+ tuple(collectKey)
}
for (tuple <- changeSet.negative;
key = aggregationKeys.map(tuple(_))) {
if (!oldValues.contains(key)) {
oldValues(key) = collections(key)
}
collections(key) = collections(key) - tuple(collectKey)
}
val positive = new VectorBuilder[Tuple]
val negative = new VectorBuilder[Tuple]
for ((key, oldValue) <- oldValues) {
if (!oldValue.isEmpty) {
negative += key :+ oldValues(key).toVector
}
if (!collections(key).isEmpty) {
positive += key :+ collections(key).toVector
}
}
return ChangeSet(positive = positive.result(), negative = negative.result())
}
override def onChangeSet(changeSet: ChangeSet): Unit = {
val newChangeSet = maintainCollections(changeSet, aggregationKeys, collectKey)
forward(newChangeSet)
}
}
示例8: getPostSummaries
//设置package包名称以及导入依赖的类
package docs.home.scaladsl.persistence
//#imports
import scala.collection.immutable
import scala.collection.immutable.VectorBuilder
import akka.NotUsed
import com.lightbend.lagom.scaladsl.api.Service
import com.lightbend.lagom.scaladsl.api.ServiceCall
import com.lightbend.lagom.scaladsl.persistence.jdbc.JdbcSession
//#imports
trait JdbcReadSideQuery {
trait BlogService extends Service {
def getPostSummaries(): ServiceCall[NotUsed, immutable.IndexedSeq[PostSummary]]
override def descriptor = ???
}
//#service-impl
class BlogServiceImpl(jdbcSession: JdbcSession) extends BlogService {
import JdbcSession.tryWith
override def getPostSummaries() = ServiceCall { request =>
jdbcSession.withConnection { connection =>
tryWith(connection.prepareStatement("SELECT id, title FROM blogsummary")) { ps =>
tryWith(ps.executeQuery()) { rs =>
val summaries = new VectorBuilder[PostSummary]
while (rs.next()) {
summaries += PostSummary(rs.getString("id"), rs.getString("title"))
}
summaries.result()
}
}
}
}
//#service-impl
}
}
示例9: FileUtil
//设置package包名称以及导入依赖的类
package sangria.util
import java.io.File
import io.github.lukehutch.fastclasspathscanner.FastClasspathScanner
import io.github.lukehutch.fastclasspathscanner.matchprocessor.FileMatchContentsProcessorWithContext
import sangria.parser.QueryParser
import sangria.parser.DeliveryScheme.Throw
import spray.json._
import scala.collection.immutable.VectorBuilder
import scala.io.Source
import net.jcazevedo.moultingyaml._
object FileUtil {
def loadQuery(name: String) =
loadResource("queries/" + name)
def loadYaml(name: String, root: String = "scenarios") =
loadResource(root + "/" + name).parseYaml
def loadScenarios(path: String, root: String = "scenarios") = this.synchronized {
val builder = new VectorBuilder[ScenarioFile]
new FastClasspathScanner(root + "." + path).matchFilenameExtension("yaml", new FileMatchContentsProcessorWithContext {
override def processMatch(file: File, relativePath: String, fileContents: Array[Byte]) = {
builder += ScenarioFile(file.getName, relativePath, new String(fileContents, "UTF-8").parseYaml)
}
}).scan()
builder.result()
}
def loadSchema(path: String) =
QueryParser.parse(loadResource(path))
def loadTestData(path: String): Either[YamlValue, JsValue] = {
val text = loadResource(path)
if (path endsWith ".yaml") Left(text.parseYaml)
else if (path endsWith ".json") Right(text.parseJson)
else throw new IllegalArgumentException(s"Unsupported file format for test data '$path'. Only `*.json` and `*.yaml` files are supported.")
}
def loadResource(path: String) =
Option(this.getClass.getResourceAsStream("/" + path)) match {
case Some(res) ? Source.fromInputStream(res, "UTF-8").mkString
case None ? throw new IllegalArgumentException("Resource not found: /" + path)
}
case class ScenarioFile(fileName: String, path: String, scenario: YamlValue) {
def folder = path.substring(0, path.lastIndexOf("/"))
}
}