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


Scala StringTokenizer类代码示例

本文整理汇总了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 
开发者ID:pmellati,项目名称:sbt-sqlpt-thrift,代码行数:34,代码来源:Helpers.scala

示例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)
    }
  }
} 
开发者ID:pmellati,项目名称:hivevalid,代码行数:48,代码来源:Matchers.scala


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