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


Scala Set类代码示例

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


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

示例1: LinkedPeriodTest

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

import org.scalatest._

import scala.collection.Set


class LinkedPeriodTest extends FlatSpec with Matchers
{
  "the linkedPeriod id" should "always be 1 greater than the last one" in
    {
      var count = 1;
      var seenIDs: Set[Int] = Set()
      while (count < 100)
      {
        var id = LinkedPeriod.getNewID()
        seenIDs(id) should be === false
        seenIDs = seenIDs + id
        count = count + 1
      }
    }

} 
开发者ID:jb574,项目名称:BBTS,代码行数:24,代码来源:LinkedPeriodTest.scala

示例2: Common

//设置package包名称以及导入依赖的类
package com.github.luzhuomi.regex.deriv

import scala.collection.Set

object Common
{
	sealed trait GFlag 
	case object Greedy extends GFlag
	case object NotGreedy extends GFlag

	trait PosEps[T] 
	{
		def posEps(a:T):Boolean
	}

	trait IsEps[T]
	{
		def isEps(a:T):Boolean
	}

	trait IsPhi[T]
	{
		def isPhi(a:T):Boolean
	}

	trait IsGreedy[T]
	{
		def isGreedy(t:T):Boolean
	}

	def nubBy[A,B](l:List[A], p:A=>B):List[A] = 
	{
		def go[A,B](l:List[A], p:A=>B, s:Set[B], acc:List[A]):List[A] = l match 
		{
			case Nil => acc.reverse
			case (x::xs) if s.contains(p(x)) => go(xs,p,s,acc)
			case (x::xs)                     => go(xs,p,s+p(x),x::acc)
		}		
		go(l,p,Set.empty,Nil)
	}

	def nub[A](l:List[A]):List[A] = nubBy(l,(x:A)=>x)

} 
开发者ID:luzhuomi,项目名称:scala-deriv,代码行数:45,代码来源:Common.scala

示例3: Plum

//设置package包名称以及导入依赖的类
trait Card
trait Room extends Card
trait Weapon extends Card
trait Suspect extends Card
case object Plum extends Suspect
case object Scarlet extends Suspect
case object Green extends Suspect
case object White extends Suspect
case object Peacock extends Suspect
case object Mustard extends Suspect
case object Revolver extends Weapon
case object LeadPipe extends Weapon
case object Rope extends Weapon
case object Candleholder extends Weapon
case object Wrench extends Weapon
case object Knife extends Weapon
case object Ballroom extends Room
case object Hall extends Room
case object Conservatory extends Room
case object Lounge extends Room
case object Study extends Room
case object Kitchen extends Room
case object DiningRoom extends Room
case object Library extends Room
case object BilliardRoom extends Room

import scala.collection.Set

val Rooms: Set[Room] = Set(Ballroom, Hall, Conservatory, Lounge, Study, Kitchen, DiningRoom, Library, BilliardRoom)
val Weapons: Set[Weapon] = Set(Revolver, LeadPipe, Rope, Candleholder, Wrench, Knife)
val Suspects: Set[Suspect] = Set(Plum, Scarlet, Green, White, Peacock, Mustard)
val Deck: Set[Card] = Rooms ++ Weapons ++ Suspects

class Player(hand: Set[Card], moves: Suspect)

class Guess(room: Room, weapon: Weapon, suspect: Suspect, player: Player)

var Log: List[Guess] = List.empty 
开发者ID:colindean,项目名称:clue-scala,代码行数:39,代码来源:Clue.scala

示例4: Author

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

import play.api.libs.json.{JsString, Json, Writes}

import scala.collection.Set

final case class Author(handle: String)

object Author {
  implicit val authorWrites = Writes[Author](author => JsString(author.handle))
}

final case class Hashtag(name: String) {
  val hash = s"#$name"
}

object Hashtag {
  implicit val hashtagWrites = Writes[Hashtag](author => JsString(author.name))
}

case class PokemonTweet(author: Author, timestamp: Long, body: String) {

  def strignify(implicit writes: Writes[PokemonTweet]): String = Json.stringify(Json.toJson(this))

  def hashtags: Set[Hashtag] =
    body.split(" ")
      .filter(_.contains("#"))
      .flatMap(_.split("#"))
      .filterNot(_.isEmpty)
      .map(Hashtag(_))
      .toSet
}

object PokemonTweet {

  import play.api.libs.json._

  implicit val pokemonTweetWrites = Writes[PokemonTweet] { tweet =>
    Json.obj(
      "author" -> Json.toJson(tweet.author),
      "hashtags" -> JsArray(tweet.hashtags.map(v => JsString(v.name)).toList),
      "message" -> tweet.body
    )
  }

} 
开发者ID:fagossa,项目名称:poc_rest,代码行数:47,代码来源:PokemonTweet.scala

示例5: ContainLikeMatcher

//设置package包名称以及导入依赖的类
package org.quicli.testbase.matchers.base

import org.specs2.execute.Result
import org.specs2.matcher.Matcher

import scala.collection.Set
import scala.reflect.ClassTag


abstract class ContainLikeMatcher[C, E](implicit eTag: ClassTag[E]) extends BaseMatcher[C]
  with MatcherHelpers {

  private val elementClassName: String = eTag.runtimeClass.getSimpleName

  protected def matchingElements(c: C): Iterable[E]
  protected def allElements(c: C): Iterable[Any]

  def which(f: E => Result): Matcher[C] = doRelative(f)
  def whose(f: E => Result): Matcher[C] = doRelative(f)
  def where(f: E => Result): Matcher[C] = doRelative(f)

  private def doRelative(f: E => Result): Matcher[C] = NewMatcher { t =>
    result(
      test = matchingElements(t).exists(f(_).isSuccess),
      message = s"$elementClassName does not match."
    )
  }

  def only: Matcher[C] = NewMatcher { c =>
    val matching: Set[Any] = matchingElements(c).toSet
    val all: Set[Any] = allElements(c).toSet

    val diff: Set[Any] = all diff matching

    result(
      test = diff.isEmpty,
      message = {
        val cClassName: String = c.getClass.getSimpleName
        matching.size match {
          case 1 => s"<b>${matching.head}<> is not the only item in $cClassName! Actual: <y>$c<>".f
          case n if n > 1 => s"<b>${matching.mkString}<> are not the only items in $cClassName! Actual: <y>$c<>".f
        }
      }
    )
  }
} 
开发者ID:ovunccetin,项目名称:quicli,代码行数:47,代码来源:ContainLikeMatcher.scala

示例6: empty

//设置package包名称以及导入依赖的类
package scala
package collection.parallel

import scala.collection.SetLike
import scala.collection.GenSetLike
import scala.collection.GenSet
import scala.collection.Set


trait ParSetLike[T,
                 +Repr <: ParSetLike[T, Repr, Sequential] with ParSet[T],
                 +Sequential <: Set[T] with SetLike[T, Sequential]]
extends GenSetLike[T, Repr]
   with ParIterableLike[T, Repr, Sequential]
{ self =>

  def empty: Repr

  // note: should not override toSet (could be mutable)

  def union(that: GenSet[T]): Repr = sequentially {
    _ union that
  }

  def diff(that: GenSet[T]): Repr = sequentially {
    _ diff that
  }
} 
开发者ID:scala,项目名称:scala-parallel-collections,代码行数:29,代码来源:ParSetLike.scala


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