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


Scala SortedSet类代码示例

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


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

示例1: ScannerSpec

//设置package包名称以及导入依赖的类
package scan

import java.io.PrintWriter
import java.nio.file._

import org.specs2._

import scala.collection.immutable.SortedSet

class ScannerSpec extends mutable.Specification {

  "Report Format" ! {
    val base = deletedOnExit(Files.createTempDirectory("exercise1"))
    val base1 = deletedOnExit(fillFile(base, 1))
    val base2 = deletedOnExit(fillFile(base, 2))
    val subdir = deletedOnExit(Files.createTempDirectory(base, "subdir"))
    val sub1 = deletedOnExit(fillFile(subdir, 1))
    val sub3 = deletedOnExit(fillFile(subdir, 3))

    val actual = Scanner.pathScan(base, 2)
    val expected = new PathScan(SortedSet(FileSize(sub3, 3), FileSize(base2, 2)), 7, 4)

    actual.mustEqual(expected)
  }

  def fillFile(dir: Path, size: Int) = {
    val path = dir.resolve(s"$size.txt")
    val w = new PrintWriter(path.toFile)
    try w.write("a" * size)
    finally w.close
    path
  }

  def deletedOnExit(p: Path) = {
    p.toFile.deleteOnExit()
    p
  }

} 
开发者ID:benhutchison,项目名称:GettingWorkDoneWithExtensibleEffects,代码行数:40,代码来源:ScannerSpec.scala

示例2: ScannerSpec

//设置package包名称以及导入依赖的类
package scan

import java.io.IOException

import org.specs2._

import scala.collection.immutable.SortedSet

import monix.execution.Scheduler.Implicits.global

import scala.concurrent.Await
import scala.concurrent.duration._

class ScannerSpec extends mutable.Specification {

  case class MockFilesystem(directories: Map[Directory, List[FilePath]], fileSizes: Map[File, Long]) extends Filesystem {

    def length(file: File) = fileSizes.getOrElse(file, throw new IOException())

    def listFiles(directory: Directory) = directories.getOrElse(directory, throw new IOException())
  }

  {
    val base = Directory("base")
    val base1 = File(s"${base.path}/1.txt")
    val base2 = File(s"${base.path}/2.txt")
    val subdir = Directory(s"${base.path}/subdir")
    val sub1 = File(s"${subdir.path}/1.txt")
    val sub3 = File(s"${subdir.path}/3.txt")
    val fs = MockFilesystem(
      Map(
        base -> List(base1, base2, subdir),
        subdir -> List(sub1, sub3)
      ),
      Map(base1 -> 1, base2 -> 2, sub1 -> 1, sub3 -> 3)
    )

    val expected = Right(new PathScan(SortedSet(FileSize(sub3, 3), FileSize(base2, 2)), 7, 4))
    val expectedLogs = List(
      Log.info("Scan started on Directory(base)"),
      Log.debug("Scanning directory 'Directory(base)': 1 subdirectories and 2 files"),
      Log.debug("File base/1.txt Size 1 B"),
      Log.debug("File base/2.txt Size 2 B"),
      Log.debug("Scanning directory 'Directory(base/subdir)': 0 subdirectories and 2 files"),
      Log.debug("File base/subdir/1.txt Size 1 B"),
      Log.debug("File base/subdir/3.txt Size 3 B")
    )
    val (actual, logs) = Await.result(Scanner.pathScan(base, 2, fs).runAsync, 1.seconds)

    "Report Format" ! {actual.mustEqual(expected)}
    "Logs" ! {logs.mustEqual(expectedLogs)}
  }

} 
开发者ID:benhutchison,项目名称:GettingWorkDoneWithExtensibleEffects,代码行数:55,代码来源:ScannerSpec.scala

示例3: ScannerSpec

//设置package包名称以及导入依赖的类
package scan

import java.io.{FileNotFoundException, IOException}

import org.specs2._

import scala.collection.immutable.SortedSet

class ScannerSpec extends mutable.Specification {

  case class MockFilesystem(directories: Map[Directory, List[FilePath]], fileSizes: Map[File, Long]) extends Filesystem {

    def length(file: File) = fileSizes.getOrElse(file, throw new IOException())

    def listFiles(directory: Directory) =
      directories.getOrElse(directory, throw new FileNotFoundException(directory.path))
  }

  "Report Format" ! {
    val base = Directory("base")
    val base1 = File(s"${base.path}/1.txt")
    val base2 = File(s"${base.path}/2.txt")
    val subdir = Directory(s"${base.path}/subdir")
    val sub1 = File(s"${subdir.path}/1.txt")
    val sub3 = File(s"${subdir.path}/3.txt")
    val fs = MockFilesystem(
      Map(
        base -> List(subdir, base1, base2),
        subdir -> List(sub1, sub3)
      ),
      Map(base1 -> 1, base2 -> 2, sub1 -> 1, sub3 -> 3)
    )

    val actual = Scanner.pathScan(base, 2, fs)
    val expected = Right(new PathScan(SortedSet(FileSize(sub3, 3), FileSize(base2, 2)), 7, 4))

    actual.mustEqual(expected)
  }

  "Error handling" ! {
    val base = Directory("base")
    val fs = MockFilesystem(Map.empty, Map.empty)

    val actual = Scanner.pathScan(base, 2, fs)
    val expected = ???

    //Cant directly compare 2 different FileNotFoundException instances for equality, so convert to Strings first
    actual.toString.mustEqual(expected.toString)
  }

} 
开发者ID:benhutchison,项目名称:GettingWorkDoneWithExtensibleEffects,代码行数:52,代码来源:ScannerSpec.scala

示例4: ScannerSpec

//设置package包名称以及导入依赖的类
package scan

import java.io.IOException

import org.specs2._

import scala.collection.immutable.SortedSet

import monix.execution.Scheduler.Implicits.global

import scala.concurrent.Await
import scala.concurrent.duration._

class ScannerSpec extends mutable.Specification {

  case class MockFilesystem(directories: Map[Directory, List[FilePath]], fileSizes: Map[File, Long]) extends Filesystem {

    def length(file: File) = fileSizes.getOrElse(file, throw new IOException())

    def listFiles(directory: Directory) = directories.getOrElse(directory, throw new IOException())
  }

  {
    val base = Directory("base")
    val base1 = File(s"${base.path}/1.txt")
    val base2 = File(s"${base.path}/2.txt")
    val subdir = Directory(s"${base.path}/subdir")
    val sub1 = File(s"${subdir.path}/1.txt")
    val sub3 = File(s"${subdir.path}/3.txt")
    val fs = MockFilesystem(
      Map(
        base -> List(subdir, base1, base2),
        subdir -> List(sub1, sub3)
      ),
      Map(base1 -> 1, base2 -> 2, sub1 -> 1, sub3 -> 3)
    )

    val expected = Right(new PathScan(SortedSet(FileSize(sub3, 3), FileSize(base2, 2)), 7, 4))
    val expectedLogs = Set(
      Log.info("Scan started on Directory(base)"),
      Log.debug("Scanning directory 'Directory(base)': 1 subdirectories and 2 files"),
      Log.debug("File base/1.txt Size 1 B"),
      Log.debug("File base/2.txt Size 2 B"),
      Log.debug("Scanning directory 'Directory(base/subdir)': 0 subdirectories and 2 files"),
      Log.debug("File base/subdir/1.txt Size 1 B"),
      Log.debug("File base/subdir/3.txt Size 3 B")
    )
    val (actual, logs) = Await.result(Scanner.pathScan(base, 2, fs).runAsync, 1.seconds)

    "Report Format" ! {actual.mustEqual(expected)}
    "Logs messages are emitted (ignores order due to non-determinstic concurrent execution)" ! {logs.forall(expectedLogs.contains)}
  }

} 
开发者ID:benhutchison,项目名称:GettingWorkDoneWithExtensibleEffects,代码行数:55,代码来源:ScannerSpec.scala

示例5: ScannerSpec

//设置package包名称以及导入依赖的类
package scan

import java.io.{FileNotFoundException, IOException}

import org.specs2._

import scala.collection.immutable.SortedSet

class ScannerSpec extends mutable.Specification {

  case class MockFilesystem(directories: Map[Directory, List[FilePath]], fileSizes: Map[File, Long]) extends Filesystem {

    def length(file: File) = fileSizes.getOrElse(file, throw new IOException())

    def listFiles(directory: Directory) =
      directories.getOrElse(directory, throw new FileNotFoundException(directory.path))
  }

  "Report Format" ! {
    val base = Directory("base")
    val base1 = File(s"${base.path}/1.txt")
    val base2 = File(s"${base.path}/2.txt")
    val subdir = Directory(s"${base.path}/subdir")
    val sub1 = File(s"${subdir.path}/1.txt")
    val sub3 = File(s"${subdir.path}/3.txt")
    val fs = MockFilesystem(
      Map(
        base -> List(subdir, base1, base2),
        subdir -> List(sub1, sub3)
      ),
      Map(base1 -> 1, base2 -> 2, sub1 -> 1, sub3 -> 3)
    )

    val actual = Scanner.pathScan(base, 2, fs)
    val expected = Right(new PathScan(SortedSet(FileSize(sub3, 3), FileSize(base2, 2)), 7, 4))

    actual.mustEqual(expected)
  }

  "Error handling" ! {
    val base = Directory("base")
    val fs = MockFilesystem(Map.empty, Map.empty)

    val actual = Scanner.pathScan(base, 2, fs)
    val expected = Left(new FileNotFoundException("base"))

    //Cant directly compare 2 different FileNotFoundException instances for equality, so convert to Strings first
    actual.toString.mustEqual(expected.toString)
  }

} 
开发者ID:benhutchison,项目名称:GettingWorkDoneWithExtensibleEffects,代码行数:52,代码来源:ScannerSpec.scala

示例6: NotFoundTest

//设置package包名称以及导入依赖的类
package com.twitter.finagle.memcached.unit.util

import com.twitter.finagle.memcached.util.NotFound
import org.junit.runner.RunWith
import org.scalatest.FunSuite
import org.scalatest.junit.JUnitRunner
import scala.collection.immutable.SortedSet

@RunWith(classOf[JUnitRunner])
class NotFoundTest extends FunSuite {

  val set = SortedSet(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
  val seq = set.toSeq
  val map = set.map(x => x -> x).toMap
  val removeAll = NotFound

  test("remove none") {
    assert(removeAll(set, Set.empty[Int]) == set)
    assert(removeAll(Set.empty[Int], Set.empty[Int]) == Set.empty[Int])

    assert(removeAll(seq, Set.empty[Int]) == seq.toSet)
    assert(removeAll(Seq.empty[Int], Set.empty[Int]) == Set.empty[Int])

    assert(removeAll(map, Set.empty[Int]) == map)
    assert(removeAll(Map.empty[Int, Int], Set.empty[Int]) == Map.empty[Int, Int])
  }

  test("remove all") {
    assert(removeAll(set, set) == Set.empty)
    assert(removeAll(seq, set) == Set.empty)
    assert(removeAll(map, set) == Map.empty)
  }

  test("remove more than threshold") {
    val n = NotFound.cutoff * set.size + 1
    val elems = set.take(n.toInt)


    assert(removeAll(set, elems) == Set(8, 9, 10))
    assert(removeAll(seq, elems) == Set(8, 9, 10))
    assert(removeAll(map, elems) == Map(8 -> 8, 9 -> 9, 10 -> 10))
  }

  test("remove less than threshold") {
    val n = NotFound.cutoff * set.size - 1
    val elems = set.take(n.toInt)

    assert(removeAll(set, elems) == Set(6, 7, 8, 9, 10))
    assert(removeAll(seq, elems) == Set(6, 7, 8, 9, 10))
    assert(removeAll(map, elems) == Map(6 -> 6, 7 -> 7, 8 -> 8, 9 -> 9, 10 -> 10))
  }

} 
开发者ID:wenkeyang,项目名称:finagle,代码行数:54,代码来源:NotFoundTest.scala

示例7: ControlGraph

//设置package包名称以及导入依赖的类
package io.github.jamespic.ethereum_tools.decompiler.control_flow

import scala.collection.immutable.SortedSet

case class ControlGraph(blocks: SortedSet[Block]) {
  lazy val parents: Map[Int, Set[Block]] = {
    val exitBlockMapping = for (
      block <- blocks; exitBlock <- exitBlocks(block.exitPoint)
    ) yield (exitBlock, block)
    val foundParents = exitBlockMapping.groupBy(_._1.address).mapValues(kvPairs => kvPairs.map(_._2))
    val defaults = blocks.map(b => b.address -> SortedSet.empty[Block]).toMap
    defaults ++ foundParents
  }

  lazy val blockByAddress: Map[Int, Block] = {
    blocks.map(block => (block.address, block)).toMap
  }

  def exitBlocks(exitPoint: ExitPoint): Set[Block] = exitPoint match {
    case ConstJump(n) => blockByAddress.get(n).toSet
    case StackJump(_)|Halt|Throw|FunctionReturn(_) => Set.empty
    case ConditionalExit(trueExit, falseExit) => exitBlocks(trueExit) ++ exitBlocks(falseExit)
    case CalculatedJump => Set.empty
  }

  override def toString = blocks.mkString("\n")

  object ExitBlock {
    def unapplySeq(exitPoint: ExitPoint): Option[Seq[Block]] = Some(exitBlocks(exitPoint).toSeq)
    def unapplySeq(stateChange: StateChange): Option[Seq[Block]] = unapplySeq(stateChange.exitPoint)
  }
}

object ControlGraph {
  def apply(blocks: Block*): ControlGraph = ControlGraph(blocks.to[SortedSet])
} 
开发者ID:jamespic,项目名称:ethereum-tools,代码行数:37,代码来源:ControlGraph.scala

示例8: ControlGraphSpec

//设置package包名称以及导入依赖的类
package io.github.jamespic.ethereum_tools.decompiler.control_flow

import scala.collection.immutable.SortedSet

import org.scalatest.{FreeSpec, Matchers}

import io.github.jamespic.ethereum_tools._
import Bytecode._


class ControlGraphSpec extends FreeSpec with Matchers {
  def fakeBlock(address: Int, exitPoint: ExitPoint) = new BasicBlock(address, Nil, StateChange(exitPoint, StackState()))
  val instance = ControlGraph(SortedSet[Block](
    fakeBlock(0, ConstJump(4)),
    fakeBlock(4, ConditionalExit(ConstJump(4), StackJump(2))),
    fakeBlock(6, CalculatedJump),
    fakeBlock(10, ConditionalExit(Halt, ConstJump(4))),
    fakeBlock(15, ConditionalExit(FunctionReturn(2), ConstJump(10))),
    fakeBlock(17, ConditionalExit(Throw, ConstJump(4)))
  ))

  "ControlSpecGraph" - {
    "should find parent blocks" in {
      instance.parents should equal(Map(
        0 -> SortedSet.empty[Block],
        4 -> SortedSet(
          fakeBlock(0, ConstJump(4)),
          fakeBlock(4, ConditionalExit(ConstJump(4), StackJump(2))),
          fakeBlock(10, ConditionalExit(Halt, ConstJump(4))),
          fakeBlock(17, ConditionalExit(Throw, ConstJump(4)))
        ),
        6 -> SortedSet.empty[Block],
        10 -> SortedSet(fakeBlock(15, ConditionalExit(FunctionReturn(2), ConstJump(10)))),
        15 -> SortedSet.empty[Block],
        17 -> SortedSet.empty[Block]
      ))
    }
  }
} 
开发者ID:jamespic,项目名称:ethereum-tools,代码行数:40,代码来源:ControlGraphSpec.scala

示例9: ScannerSpec

//设置package包名称以及导入依赖的类
package scan

import java.io.IOException

import org.specs2._

import scala.collection.immutable.SortedSet

import monix.execution.Scheduler.Implicits.global

import scala.concurrent.Await
import scala.concurrent.duration._

class ScannerSpec extends mutable.Specification {

  case class MockFilesystem(directories: Map[Directory, List[FilePath]], fileSizes: Map[File, Long]) extends Filesystem {

    def length(file: File) = fileSizes.getOrElse(file, throw new IOException())

    def listFiles(directory: Directory) = directories.getOrElse(directory, throw new IOException())
  }

  {
    val base = Directory("base")
    val base1 = File(s"${base.path}/1.txt")
    val base2 = File(s"${base.path}/2.txt")
    val subdir = Directory(s"${base.path}/subdir")
    val sub1 = File(s"${subdir.path}/1.txt")
    val sub3 = File(s"${subdir.path}/3.txt")
    val fs = MockFilesystem(
      Map(
        base -> List(subdir, base1, base2),
        subdir -> List(sub1, sub3)
      ),
      Map(base1 -> 1, base2 -> 2, sub1 -> 1, sub3 -> 3)
    )

    val expected = Right(new PathScan(SortedSet(FileSize(sub3, 3), FileSize(base2, 2)), 7, 4))
    val expectedLogs = List(
      Log.info("Scan started on Directory(base)"),
      Log.debug("Scanning directory 'Directory(base)': 1 subdirectories and 2 files"),
      Log.debug("File base/1.txt Size 1 B"),
      Log.debug("File base/2.txt Size 2 B"),
      Log.debug("Scanning directory 'Directory(base/subdir)': 0 subdirectories and 2 files"),
      Log.debug("File base/subdir/1.txt Size 1 B"),
      Log.debug("File base/subdir/3.txt Size 3 B")
    )
    val (actual, logs) = Await.result(Scanner.pathScan(base, 2, fs).runAsync, 1.seconds)

    "Report Format" ! {actual.mustEqual(expected)}
    "Logs" ! {logs.mustEqual(expectedLogs)}
  }

} 
开发者ID:Kimply,项目名称:scala-eff,代码行数:55,代码来源:ScannerSpec.scala

示例10: ClusterMembership

//设置package包名称以及导入依赖的类
package demo

import akka.actor.{Actor, ActorLogging, Props}
import akka.cluster.ClusterEvent._
import akka.cluster.{Member, Cluster, MemberStatus}

import scala.collection.immutable.SortedSet

object ClusterMembership {
  def props(cluster: Cluster) = Props(new ClusterMembership(cluster))
}

class ClusterMembership(cluster: Cluster) extends Actor with ActorLogging {

  override def preStart = {
    cluster.subscribe(self, classOf[ClusterDomainEvent])
  }

  private def evolve(clusterMembers: SortedSet[Member]): Receive = {
    case MemberUp(member) =>
      log.info("MemberUp = {}", member.address)
      context become (evolve(clusterMembers + member))

    case MemberExited(member) =>
      log.info("MemberExited = {}", member.address)

    case ReachableMember(member) =>
      log.info("ReachableMember = {}", member.address)

    case UnreachableMember(member) =>
      log.info("UnreachableMember = {}", member.address)

    case MemberRemoved(member, prev) =>
      if (prev == MemberStatus.Exiting) log.info("{} gracefully exited", member.address)
      else log.info("{} downed after being Unreachable", member.address)
      context become evolve(clusterMembers - member)

    case state: CurrentClusterState =>
      log.info("Cluster state = {}", state.members)
      context become evolve(state.members)

    case 'Members =>
      sender() ! clusterMembers.mkString(",")
  }

  override def receive = evolve(SortedSet[Member]())
} 
开发者ID:haghard,项目名称:docker-compose-akka-cluster,代码行数:48,代码来源:ClusterMembership.scala


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