本文整理汇总了Scala中java.util.StringTokenizer类的典型用法代码示例。如果您正苦于以下问题:Scala StringTokenizer类的具体用法?Scala StringTokenizer怎么用?Scala StringTokenizer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StringTokenizer类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: beSameScalaCodeAs
//设置package包名称以及导入依赖的类
package sqlpt.thriftplugin.testhelpers
import java.util.StringTokenizer
import org.specs2.matcher.Matcher
import org.specs2.matcher.Matchers._
import sqlpt.thriftplugin.Utils.BasicThriftParser
import treehugger.forest._
trait CodeTreeMatchers {
def beSameScalaCodeAs(codeStr: String): Matcher[Tree] = {
def tokenized(sourceCode: String): List[String] = {
val Delimiters = " \n()[]{},;:"
def toList(t: StringTokenizer): List[String] =
if(t.hasMoreTokens)
t.nextToken :: toList(t)
else
Nil
toList(new StringTokenizer(sourceCode, Delimiters, true)).filterNot(_.trim.isEmpty)
}
(
(tree: Tree) =>
tokenized(codeStr) == tokenized(treeToString(tree)),
(tree: Tree) =>
s"${treeToString(tree)}\n\nis not the same scala code as:\n$codeStr"
)
}
}
trait Helpers extends BasicThriftParser with CodeTreeMatchers
示例2: Matchers
//设置package包名称以及导入依赖的类
package hivevalid
import java.util.StringTokenizer
import org.specs2.matcher.{Expectable, MatchResult, Matcher}
import HiveValid.CompileResult._
object Matchers {
type Hql = String
case class beSameHqlAs(expected: Hql) extends Matcher[Hql] {
override def apply[S <: Hql](self: Expectable[S]): MatchResult[S] = {
val expectedCompilation = HiveValid.compile(expected)
val selfCompilation = HiveValid.compile(self.value)
val areTheSame = tokenized(self.value.trim) == tokenized(expected.trim)
val results = (expectedCompilation, areTheSame, selfCompilation)
def failureMessage = results match {
case (Failure(msg), _, _) =>
s"The expected query:\n\n'${expected.trim}'\n\ndid not compile: $msg"
case (Success, false, _) =>
s"${self.value.trim}\n\nwas not the same HiveQL as:\n\n${expected.trim}"
case other =>
sys error s"Unexpected results: $results"
}
result(
results == (Success, true, Success),
"The queries compiled and matched",
failureMessage,
self)
}
private def tokenized(hql: Hql): List[String] = {
val Delimiters = " \n()[]{},;:"
def toList(t: StringTokenizer): List[String] =
if(t.hasMoreTokens)
t.nextToken :: toList(t)
else
Nil
toList(new StringTokenizer(hql, Delimiters, true)).filterNot(_.trim.isEmpty)
}
}
}