collect.FluentIterable
Iterable操作の集大成
基本の出力形式
- [] - 配列
- Iterable - FluentIterable
- List - ImmutableList
- Map - ImmutableMap
- Set - ImmutableSet/ImmutableSortedSet
- MultiMap - ImmutableListMultimap
staticメソッド
返り値 FluentIterable<E>
- from(Iterable
iterable) - Iterableから生成する
メソッド
返り値 boolean
- allMatch(Predicate<? super E> predicate) - Predicateにすべての値がマッチするかどうか
- anyMatch(Predicate<? super E> predicate) - Predicateにいずれかの値がマッチするかどうか
- contains(Object element) - Iterable中にelementがふくまれるかどうか
- isEmpty() - Iterableが空かどうか
返り値 FluentIterable<E>
- cycle() - 無限に続くiteratorを生成できる。
- filter(Predicate<? super E> predicate) - Predicateでフィルターする
- limit(int size) - サイズを限定する
- skip(int numberToSkip) - 指定数だけ飛ばす
cycleとlimitの組み合わせ
Iterable iterable=FluentIterable.from(Lists.newArrayList("hello","world")).cycle().limit(10);
Iterator it=iterable.iterator();
while(it.hasNext()){
LogUtils.log(it.next());
}
返り値 E
- get(int position) - positionの値を取り出す
返り値 Optional<E>
- first() - 最初の値をOptionalとして返す
- firstMatch(Predicate<? super E> predicate) - 最初にマッチしたのをOptionalとして返す
- last() - 最後の値をOptionalとして返す
返り値 int
- size() - Iterableの大きさ
返り値 String
- toString() - 文字列に変換
返り値 E[]
- toArray(Class
type) -配列として返す GWT未対応
返り値 ImmutableList<E>
- toList() - `Immutableなリストとして返す
- toSortedList(Comparator<? super E> comparator) - ソートしたImmutableなリストを返す
返り値 ImmutableMap<E,V>
- toMap(Function<? super E,V> valueFunction) - Valueに変換するファンクションを渡して、Immutableなマップとして返す
Map<String,Object> strings=FluentIterable.from(Lists.newArrayList("hello","world")).toMap( Functions.identity());
Map<String,String> strings2=FluentIterable.from(Lists.newArrayList("hello","world")).toMap( Functions.toStringFunction());
返り値 ImmutableMap<K,E>
- uniqueIndex(Function<? super E,K> keyFunction) - Keyに変換するファンクションを渡して、Immutableなマップとして返す
返り値 ImmutableSet<E>
- toSet() - ImmutableなSetを返す
返り値 ImmutableSortedSet<E>
- toSortedSet(Comparator<? super E> comparator) - ソートしたImmutableSortedセットを返す
返り値 <K> ImmutableListMultimap<K,E>
- index(Function<? super E,K> keyFunction) - キーに変換するファンクションをを渡してImmutableListマルチマップを返す
返り値 <C extends Collection<? super E>>
- copyInto(C collection) - collectionにコピー(追加)される
返り値 FluentIterable<T>
- filter(Class
type) - 指定クラスだけのフィルター GWT未対応
- transform(Function<? super E,T> function) - ファンクションで変換
- transformAndConcat(Function<? super E,? extends Iterable<? extends T>> function) - Iterableに変換するFunctionを渡して、それらの結果をまとめてIterableを返す