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

Scala Seq类代码示例

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

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



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

示例1: initialize

//设置package包名称以及导入依赖的类
package org.danielnixon.progressive

import org.scalajs.dom.window

import org.danielnixon.progressive.shared.Wart

import scala.collection.immutable.Seq
import scala.scalajs.js


  def initialize(components: Components): Unit = {
    if (components.userAgentService.meetsRequirements && dependenciesExist) {
      components.historyService.initializeHistory()
      window.onpopstate = components.historyService.onPopState _
      components.eventHandlerSetupService.setupInitial(components.elements.body)
    }
  }

  @SuppressWarnings(Array(Wart.Any))
  private val dependenciesExist: Boolean = !Seq(Global.virtualDom, Global.vdomParser).exists(js.isUndefined)
} 
开发者ID:danielnixon,项目名称:progressive,代码行数:22,代码来源:Progressive.scala


示例2: FormSerializer

//设置package包名称以及导入依赖的类
package org.danielnixon.progressive.services

import org.danielnixon.progressive.extensions.dom.NodeListSeq
import org.scalajs.dom.html.{ Button, Element, Form, Input, Select, TextArea }

import scalaz._
import Scalaz._
import scala.collection.immutable.Seq
import scala.scalajs.js.URIUtils

class FormSerializer {
  // scalastyle:off cyclomatic.complexity
  def serializeSeq(form: Form): Seq[(Element, String, String)] = {
    form.elements.to[Seq] flatMap {
      case x: Select if x.name.nonEmpty && !x.disabled =>
        if (x.multiple) {
          x.options.filter(_.selected).map(opt => (x, x.name, opt.value))
        } else {
          Seq((x, x.name, x.value))
        }
      case x: Input if x.name.nonEmpty && !x.disabled =>
        if (x.`type` === "checkbox" || x.`type` === "radiobutton") {
          if (x.checked) Seq((x, x.name, x.value)) else Nil
        } else {
          Seq((x, x.name, x.value))
        }
      case x: Input if x.name.nonEmpty && !x.disabled =>
        if (x.`type` =/= "file") Seq((x, x.name, x.value)) else Nil
      case x: TextArea if x.name.nonEmpty && !x.disabled =>
        Seq((x, x.name, x.value))
      case x: Button if x.name.nonEmpty && !x.disabled =>
        Seq((x, x.name, x.value))
      case _ => Nil
    }
  }
  // scalastyle:on cyclomatic.complexity

  def serialize(form: Form): String = {
    serializeSeq(form).map({ case (_, name, value) => name + "=" + URIUtils.encodeURIComponent(value) }).mkString("&")
  }
} 
开发者ID:danielnixon,项目名称:progressive,代码行数:42,代码来源:FormSerializer.scala


示例3: Command

//设置package包名称以及导入依赖的类
package co.technius.brainfp

import scala.collection.immutable.Seq

sealed trait Command
object Command {
  case object RightShiftPointer            extends Command
  case object LeftShiftPointer             extends Command
  case object IncrementCell                extends Command
  case object DecrementCell                extends Command
  case object OutputCharacter              extends Command
  case object InputCharacter               extends Command
  case class  Loop(commands: Seq[Command]) extends Command

  def prettyPrint(cmd: Seq[Command]): Seq[String] = {
    cmd flatMap {
      case Loop(cmds) =>
        Seq("Loop") ++ prettyPrint(cmds).map("  " + _)
      case c => Seq(c.toString)
    }
  }
} 
开发者ID:Technius,项目名称:brainfp,代码行数:23,代码来源:Command.scala


示例4: SaveNewMessage

//设置package包名称以及导入依赖的类
package sample.helloworldconsumer.impl

import com.lightbend.lagom.scaladsl.persistence.PersistentEntity.ReplyType
import play.api.libs.json.Json
import akka.Done
import com.lightbend.lagom.scaladsl.playjson.{JsonSerializer, JsonSerializerRegistry}

import scala.collection.immutable.Seq


sealed trait MessageCommand [T] extends ReplyType[T]

case class SaveNewMessage(message: String) extends MessageCommand[Done]

object SaveNewMessage {
  implicit val formatter = Json.format[SaveNewMessage]
}

object HelloConsumerSerializerRegistry extends JsonSerializerRegistry {
  override def serializers: Seq[JsonSerializer[_]] = Seq(
    JsonSerializer[SaveNewMessage],
    JsonSerializer[MessageSaved],
    JsonSerializer[MessageState]
  )
} 
开发者ID:knoldus,项目名称:lagom-scala-wordcount.g8,代码行数:26,代码来源:MessageCommand.scala


示例5: TreeMatcherSpec

//设置package包名称以及导入依赖的类
package com.quoininc.treediffing

import org.scalatest.FunSpec

import scala.collection.immutable.Seq

import TreeMatcher.NodeWithMatching

class TreeMatcherSpec extends FunSpec {

  describe("TreeMatcher") {
    describe("match") {
      it("should fully match identical tree") {
        val t1 = Node(1, "ROOT", "", Seq(
          Node(2, "A", "a", Seq(
            Node(3, "A1", "a1"),
            Node(4, "A2", "a2"))),
          Node(5, "B", "b")))

        val matches = t1 matchWith t1.copy()
        matches foreach { t => assert(t._1 == t._2)}
      }

      it("should fully match very similar tree") {
        val t1 = Node(1, "ROOT", "", Seq(
          Node(2, "A", "a", Seq(
            Node(3, "A1", "a1"),
            Node(4, "A2", "a2"))),
          Node(5, "B", "var")))

        val t2 = Node(1, "ROOT", "", Seq(
          Node(2, "A", "a", Seq(
            Node(3, "A1", "a1"),
            Node(4, "A2", "a2"))),
          Node(5, "B", "val")))

        val matches = t1 matchWith t2
        assert(matches.size == 5)
      }

      it("should match inner node with two out of three matching leaves") {
        val root = Node(1, "ROOT", "", Seq(
          Node(2, "A", "a", Seq(
            Node(4, "A2", "a2"),
            Node(3, "A1", "a1"),
            Node(5, "A3", "a3"))),
          Node(6, "B", "b")))

        val matches = root matchWith root.replaceNode(3, null)
        assert(matches contains ((2, 2)))
      }
    }
  }
} 
开发者ID:Quoin,项目名称:tree-diffing,代码行数:55,代码来源:TreeMatcherTest.scala


示例6: Main

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

import scala.collection.immutable.Seq
import com.quantifind.charts.Highcharts._
import com.quantifind.charts.repl._

object Main {
  def main(args: Array[String]): Unit = {
    val data = RealEstateData.dataFrame
//    val time = data.select("year", "quarter").map(r => r.getInt(0)+r.getInt(1)*0.25).collect()
    
    for (i <- 1 to 20) {
      Thread sleep 100
      println(75000+i)
      val value = data.select((75000+i).toString).map(r => r.getDouble(0)).collect().toSeq
      line(value map {x => x/value(57)})
      hold()
    }
  }
} 
开发者ID:ngrislain,项目名称:french_real_estate,代码行数:21,代码来源:Main.scala


示例7: RegionsTest

//设置package包名称以及导入依赖的类
package com.wegtam.amws.common

import java.net.URI

import com.wegtam.amws.common.MarketPlaces._
import com.wegtam.amws.common.Regions._
import org.scalatest.prop.PropertyChecks
import org.scalatest.{ MustMatchers, WordSpec }

import scala.collection.immutable.Seq

class RegionsTest extends WordSpec with MustMatchers with PropertyChecks {
  private final val expectedEndpoints = Table(
    ("Region", "Endpoint"),
    (NorthAmerica, new URI("https://mws.amazonservices.com")),
    (Brazil, new URI("https://mws.amazonservices.com")),
    (Europe, new URI("https://mws-eu.amazonservices.com")),
    (India, new URI("https://mws.amazonservices.in")),
    (China, new URI("https://mws.amazonservices.com.cn")),
    (Japan, new URI("https://mws.amazonservices.jp"))
  )
  private final val expectedMarketplaces = Table(
    ("Region", "Marketplaces"),
    (NorthAmerica, Seq(CA, MX, US)),
    (Brazil, Seq(BR)),
    (Europe, Seq(DE, ES, FR, IT, UK)),
    (India, Seq(IN)),
    (China, Seq(CN)),
    (Japan, Seq(JP))
  )

  "endpoint" must {
    "return the correct region endpoint" in {
      forAll(expectedEndpoints) { (r: Region, u: URI) =>
        r.endPoint mustEqual u
      }
    }
  }

  "marketPlaces" must {
    "return the correct marketplaces for the region" in {
      forAll(expectedMarketplaces) { (r: Region, mps: Seq[MarketPlace]) =>
        r.marketPlaces mustEqual mps
      }
    }
  }

} 
开发者ID:wegtam,项目名称:amws-scala,代码行数:49,代码来源:RegionsTest.scala


示例8: InMemoryProductService

//设置package包名称以及导入依赖的类
package com.github.simonthecat.eventdrivenorders.productservice

import domain._

import scala.collection.immutable.Seq


class InMemoryProductService extends ProductsService {

  private var store = Map[Product, Long](
    Product("apple") -> 3,
    Product("orange") -> 10
  )

  override def quantity(productId: String): Long = synchronized {
    store.getOrElse(Product(productId), 0)
  }

  override def removeProducts(productsAndCounts: Seq[ProductAndCount]): Boolean = synchronized {
    val allProductsAvailable = productsAndCounts.forall {
      case ProductAndCount(Product(id), count) => quantity(id) >= count
    }

    if (allProductsAvailable) {
      store = store.map {
        case (product, count) =>
          val newCount = store(product) - productsAndCounts.find(_.product == product).map(_.count).getOrElse(0L)
          (product, newCount)
      }
      true
    } else {
      false
    }
  }

} 
开发者ID:simonko91,项目名称:event-driven-orders,代码行数:37,代码来源:InMemoryProductService.scala


示例9: BasketApplication

//设置package包名称以及导入依赖的类
package demo.impl.basket

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.broker.kafka.LagomKafkaComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.playjson.{JsonSerializer, JsonSerializerRegistry}
import com.lightbend.lagom.scaladsl.server._
import com.softwaremill.macwire._
import demo.api.basket.{Basket, BasketService}
import play.api.libs.ws.ahc.AhcWSComponents

import scala.collection.immutable.Seq

abstract class BasketApplication(ctx: LagomApplicationContext) extends LagomApplication(ctx)
  with AhcWSComponents
  with LagomKafkaComponents
  with CassandraPersistenceComponents {
  override def lagomServer: LagomServer = LagomServer.forServices {
    bindService[BasketService].to(wire[BasketServiceImpl])
  }

  persistentEntityRegistry.register(wire[BasketEntity])
}

class BasketApplicationLoader extends LagomApplicationLoader {
  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new BasketApplication(context) with LagomDevModeComponents {
      override def jsonSerializerRegistry: JsonSerializerRegistry = BasketSerializerRegistry
    }

  override def load(context: LagomApplicationContext): LagomApplication = new BasketApplication(context) {
    override def serviceLocator: ServiceLocator = NoServiceLocator
    override def jsonSerializerRegistry: JsonSerializerRegistry = BasketSerializerRegistry
  }
}

object BasketSerializerRegistry extends JsonSerializerRegistry {
  import BasketEntityFormats._
  override def serializers: Seq[JsonSerializer[_]] = Seq (
    JsonSerializer[AddItem],
    JsonSerializer[GetBasket.type],
    JsonSerializer[GetTotal.type],
    JsonSerializer[ClearAll.type],
    JsonSerializer[BasketCleared.type],
    JsonSerializer[ItemAdded],
    JsonSerializer[BasketEntityState],
    JsonSerializer[Basket],
    JsonSerializer[OrderPlaced],
    JsonSerializer[PlaceOrder.type],
    JsonSerializer[Basket]
  )
} 
开发者ID:tommpy,项目名称:demo-lagom-checkout,代码行数:55,代码来源:BasketApplication.scala


示例10: OrderApplication

//设置package包名称以及导入依赖的类
package demo.impl.order

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.broker.kafka.LagomKafkaComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.playjson.{JsonSerializer, JsonSerializerRegistry}
import com.lightbend.lagom.scaladsl.server._
import com.softwaremill.macwire.wire
import demo.api.basket.BasketService
import demo.api.order.OrderService
import play.api.libs.ws.ahc.AhcWSComponents

import scala.collection.immutable.Seq

abstract class OrderApplication(ctx: LagomApplicationContext) extends LagomApplication(ctx)
  with AhcWSComponents
  with CassandraPersistenceComponents
  with LagomKafkaComponents {
  override def lagomServer: LagomServer = LagomServer.forServices {
    bindService[OrderService].to(wire[OrderServiceImpl])
  }

  lazy val basketService: BasketService = serviceClient.implement[BasketService]

  persistentEntityRegistry.register(wire[Order])

  wire[BasketServiceSubscriber]
}

class OrderApplicationLoader extends LagomApplicationLoader {
  override def loadDevMode(context: LagomApplicationContext): LagomApplication = {
    new OrderApplication(context) with LagomDevModeComponents {
      override def jsonSerializerRegistry: JsonSerializerRegistry = OrderSerializerRegistry
    }
  }

  override def load(context: LagomApplicationContext): LagomApplication = {
    new OrderApplication(context) {
      override def serviceLocator: ServiceLocator = NoServiceLocator
      override def jsonSerializerRegistry: JsonSerializerRegistry = OrderSerializerRegistry
    }
  }
}

object OrderSerializerRegistry extends JsonSerializerRegistry {
  import OrderEntityFormats._
  override def serializers: Seq[JsonSerializer[_]] = {
    Seq(JsonSerializer[OrderInitialized],
      JsonSerializer[OrderState],
      JsonSerializer[CreateOrder],
      JsonSerializer[GetOrder.type],
      JsonSerializer[OrderItems])
  }
} 
开发者ID:tommpy,项目名称:demo-lagom-checkout,代码行数:57,代码来源:OrderApplication.scala


示例11: BasketApplication

//设置package包名称以及导入依赖的类
package demo.impl.basket

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.broker.kafka.LagomKafkaComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.playjson.{JsonSerializer, JsonSerializerRegistry}
import com.lightbend.lagom.scaladsl.server._
import com.softwaremill.macwire._
import demo.api.basket.{Basket, BasketService}
import play.api.libs.ws.ahc.AhcWSComponents

import scala.collection.immutable.Seq

abstract class BasketApplication(ctx: LagomApplicationContext) extends LagomApplication(ctx)
  with AhcWSComponents
  with LagomKafkaComponents
  with CassandraPersistenceComponents {
  override def lagomServer: LagomServer = LagomServer.forServices {
    bindService[BasketService].to(wire[BasketServiceImpl])
  }


  persistentEntityRegistry.register(wire[BasketEntity])
}

class BasketApplicationLoader extends LagomApplicationLoader {
  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new BasketApplication(context) with LagomDevModeComponents {
      override def jsonSerializerRegistry: JsonSerializerRegistry = BasketSerializerRegistry
    }

  override def load(context: LagomApplicationContext): LagomApplication = new BasketApplication(context) {
    override def serviceLocator: ServiceLocator = NoServiceLocator
    override def jsonSerializerRegistry: JsonSerializerRegistry = BasketSerializerRegistry
  }
}

object BasketSerializerRegistry extends JsonSerializerRegistry {
  import BasketEntityFormats._
  override def serializers: Seq[JsonSerializer[_]] = Seq (
    JsonSerializer[AddItem],
    JsonSerializer[GetBasket.type],
    JsonSerializer[GetTotal.type],
    JsonSerializer[ClearAll.type],
    JsonSerializer[BasketCleared.type],
    JsonSerializer[ItemAdded],
    JsonSerializer[BasketEntityState],
    JsonSerializer[Basket],
    JsonSerializer[OrderPlaced],
    JsonSerializer[PlaceOrder.type],
    JsonSerializer[Basket]
  )
} 
开发者ID:tommpy,项目名称:demo-lagom-checkout,代码行数:56,代码来源:BasketApplication.scala


示例12: BasketApplication

//设置package包名称以及导入依赖的类
package demo.impl.basket

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.broker.kafka.LagomKafkaComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.playjson.{JsonSerializer, JsonSerializerRegistry}
import com.lightbend.lagom.scaladsl.server._
import demo.api.basket.{Basket, BasketService, Item}
import play.api.libs.ws.ahc.AhcWSComponents
import com.softwaremill.macwire._

import scala.collection.immutable.Seq

abstract class BasketApplication(ctx: LagomApplicationContext) extends LagomApplication(ctx)
  with AhcWSComponents
  with LagomKafkaComponents
  with CassandraPersistenceComponents {
  override def lagomServer: LagomServer = LagomServer.forServices {
    bindService[BasketService].to(wire[BasketServiceImpl])
  }

  persistentEntityRegistry.register(wire[BasketEntity])
}

class BasketApplicationLoader extends LagomApplicationLoader {
  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new BasketApplication(context) with LagomDevModeComponents {
      override def jsonSerializerRegistry: JsonSerializerRegistry = BasketSerializerRegistry
    }

  override def load(context: LagomApplicationContext): LagomApplication = new BasketApplication(context) {
    override def serviceLocator: ServiceLocator = NoServiceLocator
    override def jsonSerializerRegistry: JsonSerializerRegistry = BasketSerializerRegistry
  }
}

object BasketSerializerRegistry extends JsonSerializerRegistry {
  import BasketEntityFormats._
  override def serializers: Seq[JsonSerializer[_]] = Seq (
    JsonSerializer[AddItem],
    JsonSerializer[GetBasket.type],
    JsonSerializer[GetTotal.type],
    JsonSerializer[ItemAdded],
    JsonSerializer[BasketEntityState],
    JsonSerializer[Basket]
  )
} 
开发者ID:tommpy,项目名称:demo-lagom-checkout,代码行数:50,代码来源:BasketApplication.scala


示例13: BasketApplication

//设置package包名称以及导入依赖的类
package demo.impl.basket

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.broker.kafka.LagomKafkaComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.playjson.{JsonSerializer, JsonSerializerRegistry}
import com.lightbend.lagom.scaladsl.server._
import demo.api.basket.{BasketService, Item}
import play.api.libs.ws.ahc.AhcWSComponents
import com.softwaremill.macwire._

import scala.collection.immutable.Seq

abstract class BasketApplication(ctx: LagomApplicationContext) extends LagomApplication(ctx)
  with AhcWSComponents
  with LagomKafkaComponents
  with CassandraPersistenceComponents {
  override def lagomServer: LagomServer = LagomServer.forServices {
    bindService[BasketService].to(wire[BasketServiceImpl])
  }
}

class BasketApplicationLoader extends LagomApplicationLoader {
  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new BasketApplication(context) with LagomDevModeComponents {
      override def jsonSerializerRegistry: JsonSerializerRegistry = BasketSerializerRegistry
    }

  override def load(context: LagomApplicationContext): LagomApplication = new BasketApplication(context) {
    override def serviceLocator: ServiceLocator = NoServiceLocator
    override def jsonSerializerRegistry: JsonSerializerRegistry = BasketSerializerRegistry
  }
}

object BasketSerializerRegistry extends JsonSerializerRegistry {
  override def serializers: Seq[JsonSerializer[_]] = Seq (
  )
} 
开发者ID:tommpy,项目名称:demo-lagom-checkout,代码行数:41,代码来源:BasketApplication.scala


示例14: BasketApplication

//设置package包名称以及导入依赖的类
package demo.impl.basket

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.broker.kafka.LagomKafkaComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.playjson.{JsonSerializer, JsonSerializerRegistry}
import com.lightbend.lagom.scaladsl.server._
import demo.api.basket.{Basket, BasketService, Item}
import play.api.libs.ws.ahc.AhcWSComponents
import com.softwaremill.macwire._

import scala.collection.immutable.Seq

abstract class BasketApplication(ctx: LagomApplicationContext) extends LagomApplication(ctx)
  with AhcWSComponents
  with LagomKafkaComponents
  with CassandraPersistenceComponents {
  override def lagomServer: LagomServer = LagomServer.forServices {
    bindService[BasketService].to(wire[BasketServiceImpl])
  }

  persistentEntityRegistry.register(wire[BasketEntity])
}

class BasketApplicationLoader extends LagomApplicationLoader {
  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new BasketApplication(context) with LagomDevModeComponents {
      override def jsonSerializerRegistry: JsonSerializerRegistry = BasketSerializerRegistry
    }

  override def load(context: LagomApplicationContext): LagomApplication = new BasketApplication(context) {
    override def serviceLocator: ServiceLocator = NoServiceLocator
    override def jsonSerializerRegistry: JsonSerializerRegistry = BasketSerializerRegistry
  }
}

object BasketSerializerRegistry extends JsonSerializerRegistry {
  import BasketEntityFormats._
  override def serializers: Seq[JsonSerializer[_]] = Seq (
    JsonSerializer[AddItem],
    JsonSerializer[GetBasket.type],
    JsonSerializer[ItemAdded],
    JsonSerializer[BasketEntityState],
    JsonSerializer[Basket]
  )
} 
开发者ID:tommpy,项目名称:demo-lagom-checkout,代码行数:49,代码来源:BasketApplication.scala


示例15: BasketApplication

//设置package包名称以及导入依赖的类
package demo.impl.basket

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.broker.kafka.LagomKafkaComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.playjson.{JsonSerializer, JsonSerializerRegistry}
import com.lightbend.lagom.scaladsl.server._
import demo.api.basket.{BasketService}
import play.api.libs.ws.ahc.AhcWSComponents
import com.softwaremill.macwire._

import scala.collection.immutable.Seq

abstract class BasketApplication(ctx: LagomApplicationContext) extends LagomApplication(ctx)
  with AhcWSComponents
  with LagomKafkaComponents
  with CassandraPersistenceComponents {
  override def lagomServer: LagomServer = LagomServer.forServices {
    ???
    //bindService[BasketService].to(wire[BasketServiceImpl])
  }
}

class BasketApplicationLoader extends LagomApplicationLoader {
  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new BasketApplication(context) with LagomDevModeComponents {
      override def jsonSerializerRegistry: JsonSerializerRegistry = BasketSerializerRegistry
    }

  override def load(context: LagomApplicationContext): LagomApplication = new BasketApplication(context) {
    override def serviceLocator: ServiceLocator = NoServiceLocator
    override def jsonSerializerRegistry: JsonSerializerRegistry = BasketSerializerRegistry
  }
}

object BasketSerializerRegistry extends JsonSerializerRegistry {
  override def serializers: Seq[JsonSerializer[_]] = Seq (
  )
} 
开发者ID:tommpy,项目名称:demo-lagom-checkout,代码行数:42,代码来源:BasketApplication.scala


示例16: BasketApplication

//设置package包名称以及导入依赖的类
package demo.impl.basket

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.broker.kafka.LagomKafkaComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.playjson.{JsonSerializer, JsonSerializerRegistry}
import com.lightbend.lagom.scaladsl.server._
import com.softwaremill.macwire._
import demo.api.basket.{Basket, BasketService}
import play.api.libs.ws.ahc.AhcWSComponents

import scala.collection.immutable.Seq

abstract class BasketApplication(ctx: LagomApplicationContext) extends LagomApplication(ctx)
  with AhcWSComponents
  with LagomKafkaComponents
  with CassandraPersistenceComponents {
  override def lagomServer: LagomServer = LagomServer.forServices {
    bindService[BasketService].to(wire[BasketServiceImpl])
  }

  persistentEntityRegistry.register(wire[BasketEntity])
}

class BasketApplicationLoader extends LagomApplicationLoader {
  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new BasketApplication(context) with LagomDevModeComponents {
      override def jsonSerializerRegistry: JsonSerializerRegistry = BasketSerializerRegistry
    }

  override def load(context: LagomApplicationContext): LagomApplication = new BasketApplication(context) {
    override def serviceLocator: ServiceLocator = NoServiceLocator
    override def jsonSerializerRegistry: JsonSerializerRegistry = BasketSerializerRegistry
  }
}

object BasketSerializerRegistry extends JsonSerializerRegistry {
  import BasketEntityFormats._
  override def serializers: Seq[JsonSerializer[_]] = Seq (
    JsonSerializer[AddItem],
    JsonSerializer[GetBasket.type],
    JsonSerializer[GetTotal.type],
    JsonSerializer[ClearAll.type],
    JsonSerializer[BasketCleared.type],
    JsonSerializer[ItemAdded],
    JsonSerializer[BasketEntityState],
    JsonSerializer[Basket]
  )
} 
开发者ID:tommpy,项目名称:demo-lagom-checkout,代码行数:52,代码来源:BasketApplication.scala


示例17: MappingLoader

//设置package包名称以及导入依赖的类
package com.ss.mapping.impl

import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.api.{Descriptor, ServiceLocator}
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.playjson.{JsonSerializer, JsonSerializerRegistry}
import com.lightbend.lagom.scaladsl.server._
import com.softwaremill.macwire._
import com.ss.mapping.api.MappingService
import org.slf4j.LoggerFactory
import play.api.libs.ws.ahc.AhcWSComponents

import scala.collection.immutable.Seq


class MappingLoader extends LagomApplicationLoader {
  val logger = LoggerFactory.getLogger(getClass)
  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new MappingApplication(context) with LagomDevModeComponents

  override def load(context: LagomApplicationContext): LagomApplication =
    new MappingApplication(context) {
      override def serviceLocator: ServiceLocator = NoServiceLocator
    }

  override def describeServices: Seq[Descriptor] = Seq(
    readDescriptor[MappingService]
  )
}

abstract class MappingApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
    with CassandraPersistenceComponents
    with AhcWSComponents {
  override def jsonSerializerRegistry: JsonSerializerRegistry = {
    MappingSerializerRegistry
  }
  override def lagomServer: LagomServer = {
    LagomServer.forServices(
      bindService[MappingService].to(wire[MappingServiceImpl])
    )
  }
  readSide.register(wire[NodeReadEventsProcessor])
}

object MappingSerializerRegistry extends JsonSerializerRegistry {
  override def serializers: Seq[JsonSerializer[_]] = Seq(
    JsonSerializer[RegisterMapping],
    JsonSerializer[MappingRegistered],
    JsonSerializer[LoadMapping.type],
    JsonSerializer[UnregisterMapping.type],
    JsonSerializer[MappingUnregistered.type]
  )
} 
开发者ID:ytaras,项目名称:iot_lagom_poc,代码行数:56,代码来源:MappingLoader.scala


示例18: Systems

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

import scala.collection.immutable.Seq

import core.Implicits._

object Systems {
  val motion: System = { (entities: Seq[Entity]) =>
    val events = for {
      e <- entities
      v <- e.componentOf[Component.Velocity]
    } yield {
      e.id -> EntityEvent.Motion(v.x, v.y, 0)
    }
    (events, Seq.empty)
  }
} 
开发者ID:Technius,项目名称:ecs-experiments,代码行数:18,代码来源:Systems.scala


示例19: EventHandler

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

import java.util.UUID
import scala.collection.immutable.Seq

import core.Implicits._

object EventHandler {
  def handle(entities: Seq[Entity], events: SimOutput): Seq[Entity] =  {
    val (entityEvents, worldEvents) = events
    val updEntities = handleEntities(entities, entityEvents)
    val updWorld = handleWorld(updEntities, worldEvents)
    updWorld
  }

  def handleEntities(entities: Seq[Entity], events: Seq[(Id, EntityEvent)]): Seq[Entity] = {
    val evMap = events.groupBy(_._1).mapValues(seq => seq.map(_._2))
    entities map { e =>
      evMap.get(e.id) match {
        case Some(ev3) =>
          ev3.foldLeft(e)((curE, nextEv) => handleEntityEvent(curE, nextEv))
        case None => e
      }
    }
  }

  def handleEntityEvent(entity: Entity, event: Event): Entity = event match {
    case EntityEvent.Motion(dx, dy, dangle) =>
      val p = entity.componentOf[Component.Position]
      upd(entity) {
        case p: Component.Position =>
          Some(p.copy(x = p.x + dx, y = p.y + dy, angle = p.angle + p.angle))
      }
    case _ => entity
  }

  def handleWorld(entities: Seq[Entity], events: Seq[WorldEvent]): Seq[Entity] = {
    import WorldEvent._
    events.foldLeft(entities)((e, event) => event match {
      case Spawn(comps: Seq[Component]) => e :+ (UUID.randomUUID -> comps) // TODO: Make deterministic
      case Die(id: Id) => e.filterNot(_.id == id)
      case _ => e
    })
  }

  private[this] def upd(entity: Entity)(f: PartialFunction[Component, Option[Component]]) = {
    val comps = entity.components flatMap { c =>
      if (f.isDefinedAt(c)) f(c)
      else Some(c)
    }
    entity.id -> comps
  }
} 
开发者ID:Technius,项目名称:ecs-experiments,代码行数:54,代码来源:EventHandler.scala


示例20: SimOutputOps

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

import java.util.UUID
import scala.collection.immutable.Seq

package object eventbased {
  type Id = BaseImpl.Id
  type Entity = BaseImpl.Entity
  type System = BaseImpl.System
  type SimOutput = (Seq[(Id, EntityEvent)], Seq[WorldEvent])

  implicit class SimOutputOps(val o: SimOutput) extends AnyVal {
    @inline def entityEvents: Seq[(Id, EntityEvent)] = o._1
    @inline def worldEvents: Seq[WorldEvent] = o._2
    @inline def ++(o2: SimOutput): SimOutput = (o._1 ++ o2._1, o._2 ++ o2._2)
  }

  object BaseImpl extends Base {
    type Id = UUID
    type Component = core.eventbased.Component
    type ComponentCol = Seq[Component]
    type EntityCol = Seq[Entity]
    type System = EntityCol => SimOutput
  }
} 
开发者ID:Technius,项目名称:ecs-experiments,代码行数:26,代码来源:package.scala



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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