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


Scala typeOf类代码示例

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


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

示例1: ShapelessTest

//设置package包名称以及导入依赖的类
package com.nekopiano.scala.scalasandbox.types


object ShapelessTest {

  def main(args: Array[String]): Unit = {
    var hm = new HMap
    hm.set("hoge", 1)
    hm.set("fuga", "moge")
    hm.get[Int]("hoge")
    hm.get[String]("fuga")
    hm.get[String]("hoge")

    println(hm)
  }
  class HMap {
    import scala.reflect.runtime.universe.{ typeOf, TypeTag, Type }
    private var m = Map[String, (Type, _)]()
    def set[T: TypeTag](k: String, v: T): Unit = { m += k -> (typeOf[T] -> v) }
    def get[T: TypeTag](k: String): Option[T] = m.get(k) flatMap {
      case (t, v) if t <:< typeOf[T] => Some(v.asInstanceOf[T])
      case _ => None
    }
  }
} 
开发者ID:lamusique,项目名称:ScalaSandbox,代码行数:26,代码来源:ShapelessTest.scala

示例2: InjectRuntimeGeneratorsTest

//设置package包名称以及导入依赖的类
package org.dama.datasynth.runtime.spark.passes

import org.dama.datasynth.executionplan.ExecutionPlan
import org.dama.datasynth.executionplan.ExecutionPlan.PropertyTable
import org.scalatest.{FlatSpec, Matchers}
import scala.reflect.runtime.universe.{TypeTag, typeOf}


class InjectRuntimeGeneratorsTest extends FlatSpec with Matchers {

  "The source code for a boolean runtime property generator with a dependency " should " be correctly generated " in {

    val size = ExecutionPlan.StaticValue[Long](1000)
    val valueFloat = ExecutionPlan.StaticValue[Float](1.0f)
    val generatorFloat = ExecutionPlan.PropertyGenerator[Float]("org.dama.datasynth.common.generators.property.dummy.DummyFloatPropertyGenerator",Seq(valueFloat),Seq())
    val tableFloat = PropertyTable[Float]("float","property",generatorFloat,size)

    val valueBoolean = ExecutionPlan.StaticValue[Boolean](true)
    val generatorBoolean = ExecutionPlan.PropertyGenerator[Boolean]("org.dama.datasynth.common.generators.property.dummy.DummyBooleanPropertyGenerator",Seq(valueBoolean),Seq(tableFloat))
    val tableBoolean = PropertyTable[Boolean]("boolean","property",generatorBoolean,size)

    val generatorMap : Map[String,String] = Map( "boolean.property" -> "BOOLEANPROPERTY", "float.property" -> "FLOATPROPERTY")
    val injectRuntimeGenerators = new InjectRuntimeGenerators(generatorMap)
    val executionPlan = injectRuntimeGenerators.run(Seq(tableBoolean,tableFloat))
    executionPlan(0) match {
      case table : PropertyTable[[email protected]] if table.tag.tpe =:= typeOf[Boolean] => table.generator.className should be ("BOOLEANPROPERTY")
      case _ => throw new RuntimeException("Table is not of type PropertyTable[Boolean]")
    }

    executionPlan(1) match {
      case table : PropertyTable[[email protected]] if table.tag.tpe =:= typeOf[Float] => table.generator.className should be ("FLOATPROPERTY")
      case _ => throw new RuntimeException("Table is not of type PropertyTable[Float]")
    }
  }
} 
开发者ID:DAMA-UPC,项目名称:DataSynth,代码行数:36,代码来源:InjectRuntimeGeneratorsTest.scala

示例3: UnitConverterPresenter

//设置package包名称以及导入依赖的类
package com.stulsoft.pscalafx.demo1

import scala.reflect.runtime.universe.typeOf
import scalafx.application.{Platform, JFXApp}
import scalafx.Includes._
import scalafx.scene.Scene
import scalafx.scene.control.{ComboBox, TextField}
import scalafx.event.ActionEvent
import scalafxml.core.{DependenciesByType, FXMLView}
import scalafxml.core.macros.sfxml
import javafx.beans.binding.StringBinding


@sfxml
class UnitConverterPresenter(from: TextField,
                             to: TextField,
                             types: ComboBox[UnitConverter],
                             converters: UnitConverters) {

  // Filling the combo box
  for (converter <- converters.available) {
    types += converter
  }
  types.getSelectionModel.selectFirst()

  // Data binding
  to.text <== new StringBinding {
    bind(from.text.delegate, types.getSelectionModel.selectedItemProperty)

    def computeValue(): String = types.getSelectionModel.getSelectedItem.run(from.text.value)
  }

  // Close button event handler
  def onClose(event: ActionEvent) {
    Platform.exit()
  }
}

object ScalaFXML extends JFXApp {

  val root = FXMLView(getClass.getResource("/fxml/unitconverter.fxml"),
    new DependenciesByType(Map(
      typeOf[UnitConverters] -> new UnitConverters(InchesToMM, MMtoInches))))

  stage = new JFXApp.PrimaryStage() {
    title = "Unit conversion"
    scene = new Scene(root)

  }
} 
开发者ID:ysden123,项目名称:poc,代码行数:51,代码来源:ScalaFXML.scala

示例4: MainViewController

//设置package包名称以及导入依赖的类
package de.m7w3.signal.controller

import de.m7w3.signal.ApplicationContext
import scala.reflect.runtime.universe.{Type, typeOf}

import scalafx.Includes._
import scalafx.scene.Parent
import scalafxml.core.{DependenciesByType, FXMLView}
import scalafxml.core.macros.{nested, sfxml}

@sfxml
class MainViewController(@nested[EditMenuController] editMenuController: MenuController,
                          @nested[FileMenuController] fileMenuController: MenuController,
                          @nested[HelpMenuController] helpMenuController: MenuController,
                          applicationContext: ApplicationContext) {

}

object MainView {
  def load(context: ApplicationContext): Parent = {
    val dependencies = Map[Type, Any](
      typeOf[ApplicationContext] -> context
    )
    val resourceUri = "/de/m7w3/signal/main_view.fxml"
    val fxmlUri = getClass.getResource(resourceUri)
    require(fxmlUri != null, s"$resourceUri not found")
    FXMLView(fxmlUri, new DependenciesByType(dependencies))
  }
} 
开发者ID:ayoub-benali,项目名称:signal-desktop-client,代码行数:30,代码来源:MainViewController.scala


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