本文整理汇总了Scala中scala.collection.SortedMap类的典型用法代码示例。如果您正苦于以下问题:Scala SortedMap类的具体用法?Scala SortedMap怎么用?Scala SortedMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SortedMap类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: Desenho
//设置package包名称以及导入依赖的类
package jerimum
import java.awt.{ Graphics2D, RenderingHints }
import scala.collection.SortedMap
import br.edu.ifrn.potigol.Potigolutil.Inteiro
object Desenho {
private[this] val vazia = SortedMap[Inteiro, List[Graphics2D => Unit]]()
private[this] var camadas = vazia
private[this] def todos = camadas.values.flatten
private[this] val rh = new RenderingHints(
RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB)
def desenhe(g: Graphics2D): Unit = {
g match {
case g: Graphics2D =>
g.setRenderingHints(rh)
}
todos.foreach(f => f(g))
camadas = vazia
}
def incluir(z: Inteiro, funcao: Graphics2D => Unit) = {
camadas += z -> (funcao :: camadas.getOrElse(z, Nil))
}
}
示例2: BlockDiffer
//设置package包名称以及导入依赖的类
package com.wavesplatform.state2.diffs
import cats.Monoid
import cats.implicits._
import com.wavesplatform.settings.FunctionalitySettings
import com.wavesplatform.state2._
import com.wavesplatform.state2.patch.LeasePatch
import com.wavesplatform.state2.reader.{CompositeStateReader, StateReader}
import scorex.block.Block
import scorex.transaction.{Signed, Transaction, ValidationError}
import scorex.utils.ScorexLogging
import scala.collection.SortedMap
object BlockDiffer extends ScorexLogging {
def right(diff: Diff): Either[ValidationError, Diff] = Right(diff)
def fromBlock(settings: FunctionalitySettings, s: StateReader, pervBlockTimestamp : Option[Long])(block: Block): Either[ValidationError, BlockDiff] =
Signed.validateSignatures(block).flatMap { _ => apply(settings, s, pervBlockTimestamp)(block.feesDistribution, block.timestamp, block.transactionData, 1) }
def unsafeDiffMany(settings: FunctionalitySettings, s: StateReader, prevBlockTimestamp: Option[Long])(blocks: Seq[Block]): BlockDiff =
blocks.foldLeft((Monoid[BlockDiff].empty, prevBlockTimestamp)) { case ((diff, prev), block) =>
val blockDiff = fromBlock(settings, new CompositeStateReader(s, diff), prev)(block).explicitGet()
(Monoid[BlockDiff].combine(diff, blockDiff), Some(block.timestamp))
}._1
private def apply(settings: FunctionalitySettings, s: StateReader, pervBlockTimestamp : Option[Long])(feesDistribution: Diff, timestamp: Long, txs: Seq[Transaction], heightDiff: Int) = {
val currentBlockHeight = s.height + 1
val txDiffer = TransactionDiffer(settings, pervBlockTimestamp, timestamp, currentBlockHeight) _
val txsDiffEi = txs.foldLeft(right(feesDistribution)) { case (ei, tx) => ei.flatMap(diff =>
txDiffer(new CompositeStateReader(s, diff.asBlockDiff), tx)
.map(newDiff => diff.combine(newDiff)))
}
txsDiffEi.map { d =>
val diff = if (currentBlockHeight == settings.resetEffectiveBalancesAtHeight)
Monoid.combine(d, LeasePatch(new CompositeStateReader(s, d.asBlockDiff)))
else d
val newSnapshots = diff.portfolios
.collect { case (acc, portfolioDiff) if portfolioDiff.balance != 0 || portfolioDiff.effectiveBalance != 0 =>
val oldPortfolio = s.accountPortfolio(acc)
acc -> SortedMap(currentBlockHeight -> Snapshot(
prevHeight = s.lastUpdateHeight(acc).getOrElse(0),
balance = oldPortfolio.balance + portfolioDiff.balance,
effectiveBalance = oldPortfolio.effectiveBalance + portfolioDiff.effectiveBalance))
}
BlockDiff(diff, heightDiff, newSnapshots)
}
}
}
示例3: BlockDiff
//设置package包名称以及导入依赖的类
package com.wavesplatform.state2
import cats.Monoid
import cats.implicits._
import scorex.account.Address
import scala.collection.SortedMap
case class BlockDiff(txsDiff: Diff,
heightDiff: Int,
snapshots: Map[Address, SortedMap[Int, Snapshot]])
object BlockDiff {
val empty: BlockDiff = BlockDiff(Monoid[Diff].empty, 0, Map.empty)
implicit def sortedMapForSnapshotsMonoid[A: Ordering, S]: Monoid[SortedMap[A, S]] = new Monoid[SortedMap[A, S]] {
def empty: SortedMap[A, S] = SortedMap.empty[A, S]
def combine(f1: SortedMap[A, S], f2: SortedMap[A, S]): SortedMap[A, S] = f1 ++ f2
}
implicit val blockDiffMonoid = new Monoid[BlockDiff] {
override def empty: BlockDiff = BlockDiff.empty
override def combine(older: BlockDiff, newer: BlockDiff): BlockDiff = BlockDiff(
txsDiff = older.txsDiff.combine(newer.txsDiff),
heightDiff = older.heightDiff + newer.heightDiff,
snapshots = older.snapshots.combine(newer.snapshots))
}
}
示例4: BagSortedMap
//设置package包名称以及导入依赖的类
package es.weso.collection
import scala.collection.SortedMap
case class BagSortedMap[A: Ordering](smap: SortedMap[A, Int])
extends Bag[A] {
def contains(elem: A): Boolean = smap.contains(elem)
def insert(elem: A): BagSortedMap[A] =
if (smap.contains(elem))
BagSortedMap(smap + (elem -> (smap(elem) + 1)))
else
BagSortedMap(smap + (elem -> 1))
def delete(elem: A): BagSortedMap[A] =
if (smap.contains(elem)) {
val n = smap(elem)
if (n == 1)
BagSortedMap(smap - elem)
else
BagSortedMap(smap + (elem -> (n - 1)))
} else // TODO: Consider returning some kind of error
this
def multiplicity(elem: A): Int = {
if (smap.contains(elem))
smap(elem)
else
0
}
override def add(elem: A, n: Int): BagSortedMap[A] =
if (smap.contains(elem))
BagSortedMap(smap + (elem -> (smap(elem) + n)))
else
BagSortedMap(smap + (elem -> n))
def elems: Iterator[(A, Int)] = smap.iterator
def asSortedMap: SortedMap[A, Int] = smap
override def toString: String = {
val b = new StringBuilder
smap.addString(b, "{| ", ", ", " |}")
b.toString
}
}
object BagSortedMap {
}
示例5: SyukujitsuBody
//设置package包名称以及导入依赖的类
package model
import java.time.LocalDate
import java.time.format.DateTimeFormatter
import org.json4s.CustomKeySerializer
import scala.collection.SortedMap
case class SyukujitsuBody(date_name: String, date: LocalDate)
case class JSONResponse(success: Boolean, msg: String, syukujitsu: Option[SortedMap[LocalDate, String]])
object LocalDateKeyJSonSerializer extends CustomKeySerializer[LocalDate](format => (
{
case s: String => {
LocalDate.parse(s, DateTimeFormatter.ofPattern("yyyy/M/d"))
}
},
{
case x: LocalDate => {
val obj = java.time.format.DateTimeFormatter.ofPattern("yyyy/MM/dd")
obj.format(x)
x.toString
}
}
))
示例6: Builder
//设置package包名称以及导入依赖的类
package org.hammerlab.genomics.loci.set
import org.hammerlab.genomics.reference.ContigName
import scala.collection.SortedMap
private[loci] class Builder {
private val map = SortedMap.newBuilder[ContigName, Contig]
def add(contig: Contig): this.type = {
if (!contig.isEmpty) {
map += ((contig.name, contig))
}
this
}
def result: LociSet = {
LociSet(map.result())
}
}
示例7: TSchemaUtil
//设置package包名称以及导入依赖的类
package com.gxq.learn.recontool.utils
import com.gxq.learn.recontool.entity.ReconToolTSchema
import org.apache.spark.SparkContext
import play.api.libs.json.Json
import play.api.libs.json.JsValue
import play.api.libs.json.JsResult
import play.api.libs.json.JsSuccess
import play.api.libs.json.JsPath
import play.api.libs.json.JsError
import scala.collection.SortedMap
object TSchemaUtil {
def getTSchema(sc: SparkContext, fileUrl: String): ReconToolTSchema = {
val jsonString = sc.textFile(fileUrl).collect().mkString
implicit val rtReads = Json.reads[ReconToolTSchema]
val jsonValue: JsValue = Json.parse(jsonString)
val rtFromJson: JsResult[ReconToolTSchema] = Json.fromJson[ReconToolTSchema](jsonValue)
val result = rtFromJson match {
case JsSuccess(rt: ReconToolTSchema, path: JsPath) => rt
case e: JsError => throw new IllegalArgumentException(JsError.toJson(e).toString())
}
result
}
def getHeaderIndexMap(header: String): SortedMap[Int, String] = {
var headMap = SortedMap[Int, String]()
val hArr = header.split(",", -1)
for (i <- 0 until hArr.length) {
headMap = headMap + (i -> hArr(i).trim())
}
headMap
}
}
示例8: index
//设置package包名称以及导入依赖的类
package controllers
import play.api.libs.json.{JsArray, JsObject, JsString}
import play.api.mvc._
import scala.collection.SortedMap
def index = Action(parse.raw) { request =>
val headerOrdering: Ordering[String] = Ordering.by(_.toLowerCase)
val headers = request.headers.toMap.foldLeft(SortedMap.empty[String, Seq[String]](headerOrdering))(_ + _)
val charset = request.charset.getOrElse("ISO-8859-1")
val method = request.method
val uri = request.uri
val queryString = request.rawQueryString
val bodyBytes: Seq[String] = for {
bytes <- request.body.asBytes().toSeq
by <- bytes
} yield {
val hex = Integer.toHexString(by)
val prefix = if (by < 16) "0" else ""
prefix + hex
}
val parsedBody = request.body.asBytes().map(_.decodeString(charset)).getOrElse("")
Ok(JsObject(
Seq(
"method" -> JsString(method),
"uri" -> JsString(uri),
"queryString" -> JsString(queryString),
"charset" -> JsString(charset),
"body" -> JsObject(
Seq(
"string" -> JsString(parsedBody),
"bytes" -> JsArray(bodyBytes.map(JsString))
)
),
"headers" -> JsObject(headers.mapValues(vs => JsArray(vs.map(JsString))))
)
))
}
}
示例9: TopNUsingMapPartition
//设置package包名称以及导入依赖的类
package com.cmb.Test
import org.apache.spark.SparkConf
import org.apache.spark.SparkContext
import scala.collection.SortedMap
object TopNUsingMapPartition {
def main(args: Array[String]): Unit = {
val sparkConf = new SparkConf().setAppName("TopNWithoutTake").setMaster("local")
val sc = new SparkContext(sparkConf)
val N = sc.broadcast(10) //??????
val input = sc.textFile("E:\\JavaWork\\topNwithSingleKey.txt", 3)
val pair = input.map(x => (x.toInt, x))
//import Ordering.Implicits._
val partitions = pair.mapPartitions(itr => {
var sortedMap = SortedMap.empty[Int, String]
itr.foreach { tuple => {
sortedMap += tuple
if (sortedMap.size > N.value) {
sortedMap = sortedMap.takeRight(N.value)
}
}
}
sortedMap.takeRight(N.value).toIterator
})
val alltop10 = partitions.collect()
//As with ++, returns a new collection containing the elements from the left operand followed by the elements from the right operand.
//It differs from ++ in that the right operand determines the type of the resulting collection rather than the left one.
//++ Returns a new traversable collection containing the elements from the left hand operand followed by the elements from the right hand operand.
// The element type of the traversable collection is the most specific superclass encompassing the element types of the two operands.
val finaltop10 = SortedMap.empty[Int, String].++:(alltop10)
val resultUsingMapPartition = finaltop10.takeRight(N.value)
resultUsingMapPartition.foreach {
case (k, v) => println(s"$k ")
}
sc.stop()
}
}
示例10: BlockDiffer
//设置package包名称以及导入依赖的类
package com.wavesplatform.state2.diffs
import cats.Monoid
import cats.implicits._
import com.wavesplatform.settings.FunctionalitySettings
import com.wavesplatform.state2._
import com.wavesplatform.state2.patch.LeasePatch
import com.wavesplatform.state2.reader.{CompositeStateReader, StateReader}
import scorex.block.Block
import scorex.transaction.{History, Signed, Transaction, ValidationError}
import scorex.utils.ScorexLogging
import scala.collection.SortedMap
object BlockDiffer extends ScorexLogging {
def right(diff: Diff): Either[ValidationError, Diff] = Right(diff)
def fromBlock(settings: FunctionalitySettings, s: StateReader, pervBlockTimestamp : Option[Long])(block: Block): Either[ValidationError, BlockDiff] =
Signed.validateSignatures(block).flatMap { _ => apply(settings, s, pervBlockTimestamp)(block.feesDistribution, block.timestamp, block.transactionData, 1) }
def unsafeDiffMany(settings: FunctionalitySettings, s: StateReader, prevBlockTimestamp: Option[Long])(blocks: Seq[Block]): BlockDiff =
blocks.foldLeft((Monoid[BlockDiff].empty, prevBlockTimestamp)) { case ((diff, prev), block) =>
val blockDiff = fromBlock(settings, new CompositeStateReader(s, diff), prev)(block).explicitGet()
(Monoid[BlockDiff].combine(diff, blockDiff), Some(block.timestamp))
}._1
private def apply(settings: FunctionalitySettings, s: StateReader, pervBlockTimestamp : Option[Long])(feesDistribution: Diff, timestamp: Long, txs: Seq[Transaction], heightDiff: Int) = {
val currentBlockHeight = s.height + 1
val txDiffer = TransactionDiffer(settings, pervBlockTimestamp, timestamp, currentBlockHeight) _
val txsDiffEi = txs.foldLeft(right(feesDistribution)) { case (ei, tx) => ei.flatMap(diff =>
txDiffer(new CompositeStateReader(s, diff.asBlockDiff), tx)
.map(newDiff => diff.combine(newDiff)))
}
txsDiffEi.map { d =>
val diff = if (currentBlockHeight == settings.resetEffectiveBalancesAtHeight)
Monoid.combine(d, LeasePatch(new CompositeStateReader(s, d.asBlockDiff)))
else d
val newSnapshots = diff.portfolios
.collect { case (acc, portfolioDiff) if (portfolioDiff.balance != 0 || portfolioDiff.effectiveBalance != 0) =>
val oldPortfolio = s.accountPortfolio(acc)
acc -> SortedMap(currentBlockHeight -> Snapshot(
prevHeight = s.lastUpdateHeight(acc).getOrElse(0),
balance = oldPortfolio.balance + portfolioDiff.balance,
effectiveBalance = oldPortfolio.effectiveBalance + portfolioDiff.effectiveBalance))
}
BlockDiff(diff, heightDiff, newSnapshots)
}
}
}
示例11: BlockDiff
//设置package包名称以及导入依赖的类
package com.wavesplatform.state2
import cats.Monoid
import cats.implicits._
import scorex.account.Address
import scala.collection.SortedMap
case class BlockDiff(txsDiff: Diff,
heightDiff: Int,
snapshots: Map[Address, SortedMap[Int, Snapshot]])
object BlockDiff {
val empty: BlockDiff = BlockDiff(Monoid[Diff].empty, 0, Map.empty)
implicit def sortedMapForSnapshotsMonoid[A: Ordering, Snapshot]: Monoid[SortedMap[A, Snapshot]] = new Monoid[SortedMap[A, Snapshot]] {
def empty: SortedMap[A, Snapshot] = SortedMap.empty[A, Snapshot]
def combine(f1: SortedMap[A, Snapshot], f2: SortedMap[A, Snapshot]): SortedMap[A, Snapshot] = f1 ++ f2
}
implicit val blockDiffMonoid = new Monoid[BlockDiff] {
override def empty: BlockDiff = BlockDiff.empty
override def combine(older: BlockDiff, newer: BlockDiff): BlockDiff = BlockDiff(
txsDiff = older.txsDiff.combine(newer.txsDiff),
heightDiff = older.heightDiff + newer.heightDiff,
snapshots = older.snapshots.combine(newer.snapshots))
}
}
示例12: Model
//设置package包名称以及导入依赖的类
package de.sergio.stormeye.model
import scala.collection.SortedMap
object Model {
case class Hero(id: String, name: String, title: String, description: String, role: String, `type`: String, gender: String, franchise: String, difficulty: String, abilities: Map[String, List[Ability]], talents: Map[String, List[Talent]], builds: Option[List[Build]]) {
override def toString(): String = {
"\nID: \t\t" + id +
"\nName: \t\t" + name +
"\nTitle: \t\t" + title +
"\nDescription: \t" + description +
"\nRole: \t\t" + role +
"\nType: \t\t" + `type` +
"\nGender: \t" + gender +
"\nFranchise: \t" + franchise +
"\nDifficulty: \t" + difficulty
}
}
case class Ability(id: String, manaCost: Option[Int], name: String, description: String, cooldown: Option[Int], shortcut: Option[String]) {
override def toString(): String = {
"\nID: \t\t" + id +
"\nName: \t\t" + name +
"\nDescription: \t" + description +
"\nMana cost: \t" + manaCost.getOrElse(0) +
"\nCooldown: \t" + cooldown.getOrElse(0) +
"\nShortcut: \t" + shortcut.getOrElse("None")
}
}
case class Talent(id: String, name: String, description: String, cooldown: Option[Int]) {
override def toString(): String = {
"\nID: \t\t" + id +
"\nName: \t\t" + name +
"\nDescription: \t" + description +
"\nCooldown: \t" + cooldown.getOrElse("NA")
}
}
case class Build(hero: String, order: Int, description: String, talentsPerTier: List[Map[String, String]]) {
val s = SortedMap(talentsPerTier.reduce(_ ++ _).map { case(k,v) => (k.toInt, v) }.toSeq:_*).map {
case (key, value) => s"\t\t[$key] \t-> [$value]"
} mkString ("", "\n", "\n")
override def toString(): String = s"\nHero: \t\t$hero\nOrder: \t\t$order\nDescription: \t$description\nBuild:\n" + s
}
}