本文整理汇总了Scala中scala.annotation.switch类的典型用法代码示例。如果您正苦于以下问题:Scala switch类的具体用法?Scala switch怎么用?Scala switch使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了switch类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: isVarPart
//设置package包名称以及导入依赖的类
package org.argus.jawa.core
import scala.annotation.switch
import java.lang.{Character => JCharacter}
import scala.language.postfixOps
def isVarPart(c: Char): Boolean =
'0' <= c && c <= '9' || 'A' <= c && c <= 'Z' || 'a' <= c && c <= 'z'
def isIdentifierStart(c: Char): Boolean =
(c == '`') || Character.isJavaIdentifierPart(c)
def isIdentifierPart(c: Char, isGraveAccent: Boolean): Boolean = {
(c != '`' || c != ' ') &&
{if(isGraveAccent) {c == '.' || c == '/' || c == ';' || c == ':' || c == '_' || c == '(' || c == ')' || c == '<' || c == '>' || Character.isJavaIdentifierPart(c)}
else {c != '.' && Character.isJavaIdentifierPart(c)}}
}
def isSpecial(c: Char): Boolean = {
val chtp = Character.getType(c)
chtp == Character.MATH_SYMBOL.toInt || chtp == Character.OTHER_SYMBOL.toInt
}
private final val otherLetters = Set[Char]('\u0024', '\u005F') // '$' and '_'
private final val letterGroups = {
import JCharacter._
Set[Byte](LOWERCASE_LETTER, UPPERCASE_LETTER, OTHER_LETTER, TITLECASE_LETTER, LETTER_NUMBER)
}
def isJawaLetter(ch: Char): Boolean = letterGroups(JCharacter.getType(ch).toByte) || otherLetters(ch)
def isOperatorPart(c: Char): Boolean = (c: @switch) match {
case '+' | '-' | '/' | '\\' | '*' | '%' | '&' | '|' | '?' | '>' | '<' | '=' | '~' | ':' => true
case a => isSpecial(a)
}
}
object Chars extends Chars { }
示例2: Employee
//设置package包名称以及导入依赖的类
package com.alvin.niagara
import scala.annotation.switch
case class Employee(var firstName: String, var lastName: String, var age: Int, var phoneNumber: String) extends org.apache.avro.specific.SpecificRecordBase {
def this() = this("", "", 0, "")
def get(field$: Int): AnyRef = {
(field$: @switch) match {
case 0 => {
firstName
}.asInstanceOf[AnyRef]
case 1 => {
lastName
}.asInstanceOf[AnyRef]
case 2 => {
age
}.asInstanceOf[AnyRef]
case 3 => {
phoneNumber
}.asInstanceOf[AnyRef]
case _ => new org.apache.avro.AvroRuntimeException("Bad index")
}
}
def put(field$: Int, value: Any): Unit = {
(field$: @switch) match {
case 0 => this.firstName = {
value.toString
}.asInstanceOf[String]
case 1 => this.lastName = {
value.toString
}.asInstanceOf[String]
case 2 => this.age = {
value
}.asInstanceOf[Int]
case 3 => this.phoneNumber = {
value.toString
}.asInstanceOf[String]
case _ => new org.apache.avro.AvroRuntimeException("Bad index")
}
()
}
def getSchema: org.apache.avro.Schema = Employee.SCHEMA$
}
object Employee {
val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Employee\",\"namespace\":\"com.alvin.niagara\",\"fields\":[{\"name\":\"firstName\",\"type\":\"string\"},{\"name\":\"lastName\",\"type\":\"string\"},{\"name\":\"age\",\"type\":\"int\"},{\"name\":\"phoneNumber\",\"type\":\"string\"}]}")
}
示例3: Ui
//设置package包名称以及导入依赖的类
import java.net.HttpURLConnection
import sbt.Keys._
import sbt._
import scala.annotation.switch
object Ui {
lazy val uiVersion: SettingKey[String] = settingKey[String]("Ui version")
lazy val uiUrl: SettingKey[String => String] = settingKey[String => String]("Construct url for ui downloading")
lazy val uiCheckoutDir: SettingKey[String] = settingKey[String]("Directory for downloading ui")
lazy val ui: TaskKey[File] = taskKey[File]("Download ui or return cached")
lazy val settings = Seq(
uiUrl := { (s: String) => s"https://github.com/Hydrospheredata/mist-ui/releases/download/v$s/mist-ui-$s.tar.gz" },
uiVersion := "1.1.3",
uiCheckoutDir := "ui_local",
ui := {
val local = baseDirectory.value / uiCheckoutDir.value
if (!local.exists()) IO.createDirectory(local)
val v = uiVersion.value
val target = local / s"ui-$v"
if (!target.exists()) {
val link = url(uiUrl.value(v))
val targetF = local/ s"ui-$v.tar.gz"
download(link, targetF)
Tar.extractTarGz(targetF, target)
}
target / "dist"
}
)
def download(url: URL, to: File): Unit = {
val conn = url.openConnection().asInstanceOf[HttpURLConnection]
conn.connect()
(conn.getResponseCode: @switch) match {
case 301 | 302 =>
val redirect = conn.getHeaderField("Location")
download(sbt.url(redirect), to)
case 200 =>
IO.download(url, to)
case x => throw new RuntimeException(s"Resource at $url response code is $x")
}
}
}
示例4: form
//设置package包名称以及导入依赖的类
package webby.commons.text
import scala.annotation.switch
trait Plural {
def form(num: Int): String
def form(num: Long): String = form((num % 100L).toInt)
class Builder(num: Int) {
private var numStr: String = null
private var delimiter: String = " "
def nbsp: Builder = {
delimiter = " "
this
}
def bigNumber(thousandSeparator: String): Builder = {
numStr = StdStr.bigNumber(num, thousandSeparator)
this
}
def bigNumberS: Builder = {
numStr = StdStr.bigNumberS(num)
this
}
override def toString: String = (if (numStr == null) String.valueOf(num) else numStr) + delimiter + form(num)
def str: String = toString
}
def apply(num: Int): Builder = new Builder(num)
}
case class EnPlural(single: String, multiple: String) extends Plural {
override def form(num: Int): String = if (num == 1) single else multiple
}
override def form(num: Int): String = {
val hund = num % 100
if (hund > 9 && hund < 21) form3
else
(hund % 10: @switch) match {
case 1 => form1
case 2 | 3 | 4 => form2
case _ => form3
}
}
}
示例5: Util
//设置package包名称以及导入依赖的类
package de.sciss.negatum
import de.sciss.kollflitz.Vec
import de.sciss.negatum.Delaunay.Vector2
import scala.annotation.switch
import scala.util.Random
object Util {
object DefaultRandom {
implicit val random: Random = new Random
}
def exprand(lo: Double, hi: Double)(implicit random: Random): Double =
lo * math.exp(math.log(hi / lo) * random.nextDouble)
def rrand(lo: Double, hi: Double)(implicit random: Random): Double =
random.nextDouble() * (hi - lo) + lo
def rand(d: Double)(implicit random: Random): Double = random.nextDouble() * d
def coin(w: Double = 0.5)(implicit random: Random): Boolean = random.nextDouble() < w
def choose[A](seq: Seq[A])(implicit random: Random): A =
seq(random.nextInt(seq.size))
def randomRectSides(n: Int)(implicit random: Random): Vec[Vector2] = {
val sides = random.shuffle(0 until 4: Vec[Int]).take(n)
sides.map { si =>
val r = random.nextFloat()
(si: @switch) match {
case 0 => Vector2(0f, r) // left
case 1 => Vector2(r, 0f) // top
case 2 => Vector2(r, 1f) // bottom
case 3 => Vector2(1f, r) // right
}
}
}
}