本文整理汇总了Scala中com.google.common.base.Splitter类的典型用法代码示例。如果您正苦于以下问题:Scala Splitter类的具体用法?Scala Splitter怎么用?Scala Splitter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Splitter类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: ConsoleProgressBarTest
//设置package包名称以及导入依赖的类
package hu.ssh.progressbar.console
import java.io.{ByteArrayOutputStream, PrintStream}
import com.google.common.base.{Splitter, Strings}
import com.google.common.collect.Iterables
import org.scalatest.{FlatSpec, Matchers}
class ConsoleProgressBarTest extends FlatSpec with Matchers {
"ProgressBar" should "output as expected" in {
val outputstream = new ByteArrayOutputStream
try {
val progressBar = ConsoleProgressBar.on(new PrintStream(outputstream)).withFormat(":percent")
progressBar.tick(0)
assert(getLastOutput(outputstream.toString) == " 0.00")
progressBar.tick(25)
assert(getLastOutput(outputstream.toString) == " 25.00")
progressBar.tick(30)
assert(getLastOutput(outputstream.toString) == " 55.00")
progressBar.tick(44)
assert(getLastOutput(outputstream.toString) == " 99.00")
progressBar.tickOne()
assert(getLastOutput(outputstream.toString) == "100.00")
} finally outputstream.close()
}
private def getLastOutput(string: String): String = {
if (Strings.isNullOrEmpty(string)) return string
val outputs = Splitter.on(ConsoleProgressBar.CARRIAGE_RETURN).omitEmptyStrings.split(string)
Iterables.getLast(outputs)
}
}