This file contains hidden or 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
// Case #1 | |
// リスト内の要素の重複を排除したリストを作る | |
def list = ['a', 'b', 'c', 'b', 'c'] | |
assert list.unique() == ['a', 'b', 'c'] | |
// 少し関連して注意すべき点。 | |
// PowerAssertの結果について、少し注意すべき。 | |
// 下記のアサートを実行すると、 |
This file contains hidden or 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
// Case #1 | |
// リストの要素数を取得する | |
def list = ['a', 'b', 'c', 'b', 'c'] | |
assert list.size() == 5 |
This file contains hidden or 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
// Case #1 | |
// 数値によるソート(昇順)。 | |
def numList=[5, 2, 0, 3, 4] | |
assert numList.sort() == [0, 2, 3, 4, 5] | |
// Case #2 | |
// 数値によるソート(降順)。 | |
numList=[5, 2, 0, 3, 4] |
This file contains hidden or 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
// Case #1 | |
// リストを結合する。 | |
assert [1] + 2 + [3, 4] == [1, 2, 3, 4] | |
def list = [1] | |
// Case #2 | |
// リストを結合する。 |
This file contains hidden or 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
// Case #1 | |
// リストを任意の値で埋める | |
def list = [255] * 5 | |
assert list == [255, 255, 255, 255, 255 ] | |
// Case #2 | |
// リストをリストの繰り返しで設定する | |
def list2 = [1, 2, 3] * 3 |
This file contains hidden or 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
// Case #1 | |
// リストの指定した要素で新たなリストを取得する | |
def list = ['a', 'b', 'c', 'd', 'e'] | |
assert list[0, 2, 4] == ['a', 'c', 'e'] | |
// Case #2 | |
// リストの指定した範囲で新たなリストを取得する | |
list = ['a', 'b', 'c', 'd', 'e'] |
This file contains hidden or 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
// Case #1 | |
// リストの最初の要素を取得する。 | |
def list = ['a', 'b', 'c'] | |
assert list.first() == 'a' | |
assert list.head() == 'a' | |
assert list[0] == 'a' | |
assert list == ['a', 'b', 'c'] // リスト自体に変化なし。 | |
// Case #2 |
This file contains hidden or 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
// Case #1 | |
// 各要素が文字列であるListからCSV出力する。 | |
def listA = ['A', 'B"', 'C', 4, 3.14] | |
println listA.join(',') | |
// 結果 | |
// A,B",C,4,3.14 | |
// Case #2 |
This file contains hidden or 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
package ListPut | |
// Case #1 | |
// リストの最初の要素を取得する。 | |
def list = ['a', 'b', 'c'] | |
assert list.first() == 'a' | |
assert list.head() == 'a' | |
assert list[0] == 'a' | |
assert list == ['a', 'b', 'c'] // リスト自体に変化なし。 |
This file contains hidden or 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
package org.eiji | |
@Grapes([ | |
@Grab(group='org.slf4j', module='slf4j-log4j12', version='1.6.6'), | |
@Grab(group='ch.qos.logback', module='logback-classic', version='0.9.28') | |
] | |
) | |
import org.slf4j.Logger | |
import org.slf4j.LoggerFactory |