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

Scala JavaConversions类代码示例

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

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



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

示例1: givenCleanMetricRegistry

//设置package包名称以及导入依赖的类
package uk.gov.hmrc.agentmapping.support

import com.codahale.metrics.MetricRegistry
import com.kenshoo.play.metrics.Metrics
import org.scalatest.Matchers
import org.scalatestplus.play.OneAppPerSuite

import scala.collection.JavaConversions

trait MetricTestSupport {
  self: OneAppPerSuite with Matchers =>

  private var metricsRegistry: MetricRegistry = _

  def givenCleanMetricRegistry(): Unit = {
    val registry = app.injector.instanceOf[Metrics].defaultRegistry
    for (metric <- JavaConversions.asScalaIterator[String](registry.getMetrics.keySet().iterator())) {
      registry.remove(metric)
    }
    metricsRegistry = registry
  }

  def timerShouldExistsAndBeenUpdated(metric: String): Unit = {
    metricsRegistry.getTimers.get(s"Timer-$metric").getCount should be >= 1L
  }

} 
开发者ID:hmrc,项目名称:agent-mapping,代码行数:28,代码来源:MetricTestSupport.scala


示例2: givenCleanMetricRegistry

//设置package包名称以及导入依赖的类
package uk.gov.hmrc.agentaccesscontrol.support

import com.codahale.metrics.MetricRegistry
import com.kenshoo.play.metrics.Metrics
import org.scalatest.Matchers
import org.scalatestplus.play.OneAppPerSuite

import scala.collection.JavaConversions

trait MetricTestSupport {
  self: OneAppPerSuite with Matchers =>

  private var metricsRegistry: MetricRegistry = _

  def givenCleanMetricRegistry(): Unit = {
    val registry = app.injector.instanceOf[Metrics].defaultRegistry
    for (metric <- JavaConversions.asScalaIterator[String](registry.getMetrics.keySet().iterator())) {
      registry.remove(metric)
    }
    metricsRegistry = registry
  }

  def timerShouldExistsAndBeenUpdated(metric: String): Unit = {
    metricsRegistry.getTimers.get(s"Timer-$metric").getCount should be >= 1L
  }

} 
开发者ID:hmrc,项目名称:agent-access-control,代码行数:28,代码来源:MetricTestSupport.scala


示例3: app

//设置package包名称以及导入依赖的类
package uk.gov.hmrc.agentrelationships.support

import com.codahale.metrics.MetricRegistry
import com.kenshoo.play.metrics.Metrics
import org.scalatest.{Matchers, Suite}
import play.api.Application

import scala.collection.JavaConversions

trait MetricTestSupport {
  self: Suite with Matchers =>

  def app: Application

  private var metricsRegistry: MetricRegistry = _

  def givenCleanMetricRegistry(): Unit = {
    val registry = app.injector.instanceOf[Metrics].defaultRegistry
    for (metric <- JavaConversions.asScalaIterator[String](registry.getMetrics.keySet().iterator())) {
      registry.remove(metric)
    }
    metricsRegistry = registry
  }

  def timerShouldExistsAndBeenUpdated(metric: String): Unit = {
    metricsRegistry.getTimers.get(s"Timer-$metric").getCount should be >= 1L
  }

} 
开发者ID:hmrc,项目名称:agent-client-relationships,代码行数:30,代码来源:MetricTestSupport.scala


示例4: TestFileSystemSupport

//设置package包名称以及导入依赖的类
package com.github.madoc.create_sbt_project.io

import java.nio.charset.Charset
import java.nio.file.Files

import com.google.common.jimfs.{Configuration, Jimfs}

import scala.collection.JavaConversions

class TestFileSystemSupport(workingDirectory:String="/home/user/projectdir", userHome:String="/home/user")
extends FileSystemSupport.Default(Jimfs.newFileSystem(Configuration.unix().toBuilder.setWorkingDirectory(workingDirectory).build())) {
  private var errorOutput = ""
  private var standardOutput = ""
  private val lock = new Object

  locally {mkdirs(workingDirectory)}

  def getErrorOutput:String = lock synchronized errorOutput
  def getStandardOutput:String = lock synchronized standardOutput
  def setUserPreferencesFileContents(contents:String) =
    outputToFile(contents, userPreferencesFilePath, Charset forName "utf-8")(new Output[String] {
      def apply(the:String)(write:Write) = write(the)
    })
  def getFileContents(path:String, charset:Charset=Charset forName "utf-8"):String =
    JavaConversions.asScalaBuffer(Files.readAllLines(fs getPath path, charset)).mkString("\n")

  override protected def userHomeDirectory = userHome
  override protected def systemErr = new Appendable {
    def append(csq:CharSequence) = {lock synchronized {errorOutput += csq.toString}; this}
    def append(csq:CharSequence, start:Int, end:Int) = append(csq subSequence (start, end))
    def append(c:Char) = append(c toString)
  }
  override protected def systemOut = new Appendable {
    def append(csq:CharSequence) = {lock synchronized {standardOutput += csq.toString}; this}
    def append(csq:CharSequence, start:Int, end:Int) = append(csq subSequence (start, end))
    def append(c:Char) = append(c toString)
  }
} 
开发者ID:Madoc,项目名称:create-sbt-project,代码行数:39,代码来源:TestFileSystemSupport.scala


示例5: ProcessRunner

//设置package包名称以及导入依赖的类
package yuck.util.testing

import scala.collection.JavaConversions

import java.util.concurrent.Callable
import yuck.util.logging.LazyLogger


class ProcessRunner(logger: LazyLogger, commandLine: Seq[String]) extends Callable[(List[String], List[String])] {

    override def call = {
        val processBuilder = new java.lang.ProcessBuilder(JavaConversions.seqAsJavaList(commandLine))
        logger.log(JavaConversions.asScalaBuffer(processBuilder.command).toIterator.mkString(" "))
        val process = processBuilder.start
        val stdout = scala.io.Source.fromInputStream(process.getInputStream)
        val stderr = scala.io.Source.fromInputStream(process.getErrorStream)
        val outputLines = stdout.mkString.lines.toList
        val (errorLines, warningLines) = stderr.mkString.lines.toList.partition(_.toLowerCase.contains("error"))
        outputLines.foreach(logger.log(_))
        warningLines.foreach(logger.log(_))
        errorLines.foreach(logger.log(_))
        (outputLines, errorLines)
    }

} 
开发者ID:informarte,项目名称:yuck,代码行数:26,代码来源:ProcessRunner.scala


示例6: JfxUtils

//设置package包名称以及导入依赖的类
package fhj.swengb.project.courseware.components

import javafx.beans.value.ObservableValue
import javafx.collections.{FXCollections, ObservableList}
import javafx.scene.control.TableColumn
import javafx.util.Callback
import scala.collection.JavaConversions

object JfxUtils {

  type TCDF[S, T] = TableColumn.CellDataFeatures[S, T]

  import JavaConversions._

  def mkObservableList[T](collection: Iterable[T]): ObservableList[T] = {
    FXCollections.observableList(new java.util.ArrayList[T](collection))
  }

  private def mkCellValueFactory[S, T](fn: TCDF[S, T] => ObservableValue[T]): Callback[TCDF[S, T], ObservableValue[T]] = {
    new Callback[TCDF[S, T], ObservableValue[T]] {
      def call(cdf: TCDF[S, T]): ObservableValue[T] = fn(cdf)
    }
  }

  def initTableViewColumnCellValueFactory[S, T](tc: TableColumn[S, T], f: S => Any): Unit = {
    tc.setCellValueFactory(mkCellValueFactory(cdf => f(cdf.getValue).asInstanceOf[ObservableValue[T]]))
  }

} 
开发者ID:McKorleone,项目名称:fhj.swengb.project.courseware,代码行数:30,代码来源:JfxUtils.scala


示例7: AnnotationLoader

//设置package包名称以及导入依赖的类
package temportalist.origin.api.common.lib.loader

import net.minecraftforge.fml.common.discovery.ASMDataTable
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent

import scala.collection.mutable.ListBuffer
import scala.collection.{JavaConversions, mutable}


class AnnotationLoader[C, T](private val annotation: Class[C], private val instance: Class[T]) {

	private val classInstances = mutable.Map[Class[_ <: T], mutable.Map[String, AnyRef]]()
	private var mapKeys = ListBuffer[Class[_ <: T]]()

	final def loadAnnotations(event: FMLPreInitializationEvent): Unit = {
		this.findInstanceClasses(event.getAsmData)
	}

	final def findInstanceClasses(asmData: ASMDataTable): Unit = {
		val annotationName = this.annotation.getName
		val dataAnnotatedClasses = JavaConversions.asScalaSet(asmData.getAll(annotationName))
		for (dataAnnotatedClass <- dataAnnotatedClasses) {
			try {
				val annotatedClass = Class.forName(dataAnnotatedClass.getClassName)
				val annotatedClassAsSub = annotatedClass.asSubclass(this.instance)
				val annotationInfo = JavaConversions.mapAsScalaMap(dataAnnotatedClass.getAnnotationInfo)
				this.classInstances.put(annotatedClassAsSub, annotationInfo)
				this.onAnnotationClassFound(annotatedClassAsSub, annotationInfo)
			}
			catch {
				case e: Exception =>
					e.printStackTrace()
			}
		}
		this.mapKeys ++= this.classInstances.keySet.toSeq.sortWith(this.keySorter)
	}

	def keySorter(a: Class[_ <: T], b: Class[_ <: T]): Boolean = a.getSimpleName < b.getSimpleName

	def onAnnotationClassFound[I <: T](implementer: Class[I], info: mutable.Map[String, AnyRef]): Unit = {}

	final def getClassInstances: Iterable[Class[_ <: T]] = this.mapKeys

	final def getAnnotationInfo(clazz: Class[_ <: T]) =
		this.classInstances.getOrElse(clazz, Map[String, AnyRef]())

} 
开发者ID:TheTemportalist,项目名称:Origin,代码行数:48,代码来源:AnnotationLoader.scala


示例8: AccessTokenRetriever

//设置package包名称以及导入依赖的类
package com.wix.pay.mercadopago

import com.google.api.client.http.{GenericUrl, HttpRequestFactory, HttpResponse, UrlEncodedContent}
import com.wix.pay.PaymentErrorException

import scala.collection.JavaConversions
import scala.concurrent.duration.Duration
import scala.util.Try

class AccessTokenRetriever(requestFactory: HttpRequestFactory,
                           connectTimeout: Option[Duration] = None,
                           readTimeout: Option[Duration] = None,
                           numberOfRetries: Int = 0,
                           endpointUrl: String) {
  
  def retrieveAccessToken(clientId: String, clientSecret: String): Try[String] = {
    Try {
      val params = MercadopagoHelper.createOauthRequest(clientId, clientSecret)

      val httpRequest = requestFactory.buildPostRequest(
        new GenericUrl(endpointUrl),
        new UrlEncodedContent(JavaConversions.mapAsJavaMap(params))
      )

      connectTimeout foreach (to => httpRequest.setConnectTimeout(to.toMillis.toInt))
      readTimeout foreach (to => httpRequest.setReadTimeout(to.toMillis.toInt))
      httpRequest.setNumberOfRetries(numberOfRetries)

      httpRequest.setThrowExceptionOnExecuteError(false)

      val httpResponse = httpRequest.execute()
      val responseJson = extractResponseAndClose(httpResponse)
      if (httpResponse.isSuccessStatusCode) {
        val oauthResponse = OauthResponseParser.parse(responseJson)
        oauthResponse.access_token
      } else {
        val oauthErrorResponse = OauthErrorResponseParser.parse(responseJson)
        throw PaymentErrorException(oauthErrorResponse.message)
      }
    }
  }

  private def extractResponseAndClose(httpResponse: HttpResponse): String = {
    try {
      httpResponse.parseAsString()
    } finally {
      httpResponse.ignore()
    }
  }
} 
开发者ID:wix,项目名称:libpay-mercadopago,代码行数:51,代码来源:AccessTokenRetriever.scala



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Scala OffsetDateTime类代码示例发布时间:2022-05-23
下一篇:
Scala TimestampType类代码示例发布时间: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