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


Scala Collectors类代码示例

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


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

示例1: Dynamite

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

import java.util.stream.Collectors

object Dynamite {

  def main(args: Array[String]): Unit = {
    Opts.parse(args) match {
      case Some(config) =>
        config.script match {
          case Some(script) => Script(config, script)
          case None =>
            if (System.console() == null) {
              val input = Console.in.lines().collect(Collectors.joining("\n"))
              Script(config, input)
            } else {
              Repl(config)
            }
        }
      case None => sys.exit(1)
    }
  }

} 
开发者ID:joprice,项目名称:dynamite,代码行数:25,代码来源:Dynamite.scala

示例2: TemplateUploadActor

//设置package包名称以及导入依赖的类
package firecrest.actors

import java.io.{BufferedReader, InputStreamReader}
import java.util.stream.Collectors
import javax.inject.Inject

import akka.actor.{Actor, ActorLogging}
import org.elasticsearch.client.support.AbstractClient

import scala.concurrent.duration._

object TemplateUploadActor {
  case object Upload
}

class TemplateUploadActor @Inject() (elasticSearchClient: AbstractClient)
  extends Actor with ActorLogging {

  import TemplateUploadActor._
  import context._

  override def preStart(): Unit = {
    super.preStart()
    system.scheduler.scheduleOnce(1 second, self, Upload)
  }

  override def postRestart(reason: Throwable) = {}

  override def receive = {
    case Upload =>
      log.info("Uploading index template")
      system.scheduler.scheduleOnce(10 minutes, self, Upload)

      val istream = ClassLoader.getSystemResourceAsStream("index-template.json")
      val buffer = new BufferedReader(new InputStreamReader(istream))
      val content = buffer.lines().collect(Collectors.joining())

      val indicesAdminClient = elasticSearchClient.admin().indices()
      val result = indicesAdminClient.preparePutTemplate("firecrest")
        .setSource(content)
        .get()
      if (!result.isAcknowledged) {
        log.warning("Index upload is not acknowledged")
      }
  }
} 
开发者ID:redvasily,项目名称:firecrest,代码行数:47,代码来源:TemplateUploadActor.scala

示例3: JsoupHelper

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

import java.util.stream.Collectors

import org.jsoup.nodes.Element
import org.jsoup.select.Elements


object JsoupHelper {
  implicit def elementsToElements4Scala(elements: Elements): Elements4Scala = {
    new Elements4Scala(elements)
  }
}

class Elements4Scala(that: Elements) {
  def toElementArray: Array[Element] = {
    val list: java.util.List[Element] = that.stream.collect(Collectors.toList[Element])
    list.toArray(new Array[Element](list.size()))
  }
} 
开发者ID:ktr-skmt,项目名称:FelisCatusZero,代码行数:21,代码来源:JsoupHelper.scala

示例4: findAll

//设置package包名称以及导入依赖的类
package org.littlewings.tweetbot.application.carat.information.repository

import java.util.UUID
import java.util.stream.Collectors
import javax.enterprise.context.ApplicationScoped
import javax.enterprise.inject.Typed
import javax.inject.Inject

import org.infinispan.Cache
import org.littlewings.tweetbot.application.carat.information.Information
import org.littlewings.tweetbot.application.carat.information.qualifier.CaratInformationTweetBot
import org.littlewings.tweetbot.resource.Managed

import scala.collection.JavaConverters._

trait InformationRepository {
  def findAll: Seq[Information]

  def saveAll(informations: Seq[Information]): Unit

  def clear(): Unit
}

@Typed(Array(classOf[InformationRepository]))
@ApplicationScoped
class DefaultInformationRepository @Inject()(@CaratInformationTweetBot protected[repository] val cache: Cache[String, Information])
  extends InformationRepository {
  override def findAll: Seq[Information] = {
    val stream =
      for (s <- Managed(cache.values.stream))
        yield s.collect(Collectors.toList[Information]).asScala.toVector
    stream.acquireAndGet(identity)
  }

  override def saveAll(informations: Seq[Information]): Unit = {
    cache.clear()
    informations.foreach {
      information =>
        cache.put(UUID.randomUUID.toString, information)
    }
  }

  override def clear(): Unit = cache.clear()
} 
开发者ID:kazuhira-r,项目名称:tweet-bot,代码行数:45,代码来源:InformationRepository.scala

示例5: size

//设置package包名称以及导入依赖的类
package org.littlewings.tweetbot.standard.lyrics.repository

import java.util.stream.Collectors

import org.infinispan.Cache
import org.littlewings.tweetbot.resource.Managed
import org.littlewings.tweetbot.standard.lyrics.Lyrics

trait LyricsRepository {
  protected val cache: Cache[String, Lyrics]

  def size: Int

  def select(n: Int): (String, Lyrics)

  def delete(key: String): Unit
}

trait LyricsRepositorySupport extends LyricsRepository {
  protected val cache: Cache[String, Lyrics]

  override def size: Int = cache.size

  override def select(n: Int): (String, Lyrics) = {
    if (n <= cache.size) {
      val stream =
        for (s <- Managed(cache.entrySet.stream))
          yield s
            .map[(String, Lyrics)](e => e.getKey -> e.getValue)
            .collect(Collectors.toList[(String, Lyrics)])

      val entries = stream.acquireAndGet(identity)
      entries.get(n)
    } else {
      null
    }
  }

  override def delete(key: String): Unit = cache.remove(key)
} 
开发者ID:kazuhira-r,项目名称:tweet-bot,代码行数:41,代码来源:LyricsRepository.scala


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