Utils.scala 980 Bytes
Newer Older
Christian Müller's avatar
Christian Müller committed
1 2
package de.tum.workflows

3
import de.tum.workflows.blocks._
Christian Müller's avatar
Christian Müller committed
4 5
import de.tum.workflows.foltl.FOLTL._

Christian Müller's avatar
Christian Müller committed
6
object Utils {
7 8

  def mkString[T](string: Iterable[T], start: String, mid: String, end: String) = {
Christian Müller's avatar
Christian Müller committed
9 10
    if (string.isEmpty) "" else string.mkString(start, mid, end)
  }
11 12 13 14 15 16 17 18 19 20

  def collectChoices(w: Block): List[Fun] = {
    w match {
      case Loop(steps)                     => steps.flatMap(collectChoices _)
      case ForallMayBlock(agents, pred, _) => List(Fun(pred, agents))
      case b: ForallBlock                  => List()
      case NondetChoice(l, r)              => l.flatMap(collectChoices) ++ r.flatMap(collectChoices)
    }
  }

21 22
  def allchoices(w: Workflow) = {
    w.steps flatMap (collectChoices _) toSet
Christian Müller's avatar
Christian Müller committed
23
  }
24 25 26 27

  def indentLines(s: String) = {
    s.lines.map("  " + _).mkString("\n")
  }
Christian Müller's avatar
Christian Müller committed
28 29 30 31 32 33 34
  
  def time[R](block: => R) = {  
    val t0 = System.nanoTime()
    val result = block    // call-by-name
    val t1 = System.nanoTime()
    ((t1 - t0)/1000000, result)
  }
Christian Müller's avatar
Christian Müller committed
35
}