• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala SortedMap类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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))
  }
} 
开发者ID:potigol,项目名称:Jerimum,代码行数:31,代码来源:Desenho.scala


示例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)
    }
  }
} 
开发者ID:wavesplatform,项目名称:Waves,代码行数:54,代码来源:BlockDiffer.scala


示例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))
  }
} 
开发者ID:wavesplatform,项目名称:Waves,代码行数:32,代码来源:BlockDiff.scala


示例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 {
} 
开发者ID:labra,项目名称:rbe,代码行数:54,代码来源:BagSortedMap.scala


示例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
    }
  }
)) 
开发者ID:matsutomu,项目名称:parse-syukujitsu-scala,代码行数:28,代码来源:SyukujitsuData.scala


示例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())
  }
} 
开发者ID:hammerlab,项目名称:genomic-loci,代码行数:22,代码来源:Builder.scala


示例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
  }
} 
开发者ID:gong1989313,项目名称:spark-bigdata,代码行数:35,代码来源:TSchemaUtil.scala


示例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))))
      )
    ))
  }

} 
开发者ID:unclealex72,项目名称:whatamisending,代码行数:43,代码来源:GlobalController.scala


示例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()
  }
} 
开发者ID:doublefox,项目名称:SparkTest,代码行数:46,代码来源:TopNUsingMapPartition.scala


示例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)
    }
  }
} 
开发者ID:mikepijn,项目名称:wavesnode,代码行数:54,代码来源:BlockDiffer.scala


示例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))
  }
} 
开发者ID:mikepijn,项目名称:wavesnode,代码行数:32,代码来源:BlockDiff.scala


示例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
  }
} 
开发者ID:asgoncalves,项目名称:storm-eye,代码行数:48,代码来源:Model.scala



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala FeatureSpec类代码示例发布时间:2022-05-23
下一篇:
Scala TrustManagerFactory类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap