本文整理汇总了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
}
}
}
示例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")
}
}
示例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")
}
}