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


Scala Breaks类代码示例

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


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

示例1: searchFrom

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

import java.io.InputStreamReader
import java.io.BufferedReader
import scala.util.control.Breaks
//import scala.util.control.Breaks._


  def searchFrom(i: Int): Int =
    if (i >= args.length) -1
    else if ( args(i).startsWith("-")) searchFrom(i+1)
    else if ( args(i).endsWith(".scala")) i
    else searchFrom(i+1)
    
  val i2 = searchFrom(0)
  
  // ???? ??? ??? break? ????? ???? ??? ???, ??? ??????? Breaks ???? ??.
  
  val in = new BufferedReader(new InputStreamReader(System.in))
  // Breaks ???? break?? ??? ???, ??? breakable ????? ? ??? ?? ???? ?? ????.
  // ??? break ??? breakable? ??? ???? ?? ??? ??.
  Breaks.breakable {
    while(true) {
      println("? ")
      if (in.readLine() == "") Breaks.break
    }
  }
} 
开发者ID:seraekim,项目名称:srkim-lang-scala,代码行数:29,代码来源:c07_i06.scala

示例2: Palindrome

//设置package包名称以及导入依赖的类
package de.tu_berlin.dima.bdapro.flink.palindrome.plehmann93


import org.apache.flink.api.common.operators.Order
import org.apache.flink.api.scala.ExecutionEnvironment
import org.apache.flink.api.scala._
import org.apache.flink.util.Collector

import scala.math.Ordering.String
import scala.util.control.Breaks

object Palindrome {



  def main(args: Array[String]) {
    if (args.length != 1) {
      Console.err.println("Usage: <jar> inputPath")
      System.exit(-1)
    }
    val inputPath = args(0)

    val env = ExecutionEnvironment.getExecutionEnvironment
    val result= env.readTextFile(inputPath)
      .flatMap(_.toLowerCase.split("/n"))
      .filter(x => x.replace(" ","")==x.replace(" ","").reverse)
      .map( x => (1,x.replace(" ","").size,x)  )
      .groupBy(0).sortGroup(1,Order.DESCENDING)
      .reduceGroup{ (in, out: Collector[(Int, Int, String)]) =>
      var max: Int = -1
      Breaks.breakable{for (x <- in){
        if(max==(-1)) {max=x._2}
        if(max>x._2){Breaks.break()}
        out.collect(x)
      }}
    }
    result.collect().foreach(x=>Console.println("The biggest palindrome sentence: <"+x._3+">"))
    //env.execute("bdapro-ws1617-flink")
  }
} 
开发者ID:cristiprg,项目名称:BDAPRO.GlobalStateML,代码行数:41,代码来源:Palindrome.scala

示例3: OddSemordnilaps

//设置package包名称以及导入依赖的类
package de.tu_berlin.dima.bdapro.flink.oddsemordnilaps.plehmann93

import org.apache.flink.api.scala._
import org.apache.flink.util.Collector

import scala.util.control.Breaks


object OddSemordnilaps {


  def main(args: Array[String]) {
    if (args.length != 1) {
      Console.err.println("Usage: <jar> inputPath")
      System.exit(-1)
    }

    val inputPath = args(0)

    val env = ExecutionEnvironment.getExecutionEnvironment
    val result=env.readTextFile(inputPath)
      .flatMap(_.toLowerCase.split("\\W+"))
      .filter(x => x.toInt%2==1)
      .map{x=>if (x<x.reverse) (x,x) else (x.reverse,x) }
      .groupBy(0)
      .reduceGroup { (in, out: Collector[(String)]) =>
        var value:String="null"
        Breaks.breakable{ for (x <- in){
          if(value=="null") {
            value=x._2
            if(value==value.reverse) {
              out.collect(value)
              Breaks.break
            }
          }
          else{
            if(value.reverse==x._2){
              out.collect(value)
              out.collect(x._2)
              Breaks.break()
            }
          }
        }
        }}
    Console.println("The result is "+result.collect().size.toString)
    // env.execute("bdapro-ws1617-flink")
  }

} 
开发者ID:cristiprg,项目名称:BDAPRO.GlobalStateML,代码行数:50,代码来源:OddSemordnilaps.scala


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