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

Scala Collectors类代码示例

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

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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