Created
April 22, 2014 02:28
-
-
Save sifue/11163444 to your computer and use it in GitHub Desktop.
切り出したい処理が処理の中間にあるメソッド同士の重複行排除の例
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 重複行を排除した上記と同様の処理を持つオブジェクト | |
*/ | |
object DeleteDuplicate extends App { | |
/** | |
* メッセージを受け取りテンプレートに埋め込んだ上でそのUTF-8でのバイト数と内容を表示する | |
* @param message | |
*/ | |
def printByteLengthAndContent(message: String) = printTargetLengthAndContent(message, { | |
content => content.getBytes(Charset.forName("UTF-8")).length | |
}) | |
/** | |
* メッセージを受け取りテンプレートに埋め込んだ上でその文字数と内容を表示する | |
* @param message | |
*/ | |
def printCharLengthAndContent(message: String) = printTargetLengthAndContent(message, { _.length }) | |
/** | |
* メッセージと対象の長さを取得する関数を受けとり、テンプレートに埋め込んだ上で長さと内容を表示する | |
* @param message | |
* @param targetLengthProvider | |
*/ | |
def printTargetLengthAndContent(message: String, targetLengthProvider: String => Int) = { | |
val template = RandomTemplateProvider.get | |
val content = String.format(template, message) | |
val length = targetLengthProvider(content) | |
println(length) | |
println(content) | |
} | |
printByteLengthAndContent("こんにちわ") | |
printCharLengthAndContent("おはよう") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment