eclipse collections 最新アップデート

41
TECHNOLOGY DIVISION 1 Eclipse Collections 最最最最最最最最 最最最最最最 最最最最 最最最最最最最 最最最最 最最最最最最 最最最最 #kanjava #j1ec

Upload: java

Post on 09-Jan-2017

3.366 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Eclipse Collections 最新アップデート

TECHNOLOGY DIVISION

1

Eclipse Collections 最新アップデートゴールドマン・サックステクノロジー部 ヴァイス・プレジデント伊藤博志 #kanjava #j1ec

Page 2: Eclipse Collections 最新アップデート

TECHNOLOGY DIVISION

2

http://www.eclipse.org/collections

#kanjava #j1ec

Page 3: Eclipse Collections 最新アップデート

TECHNOLOGY DIVISION

3

ゴールドマン・サックスのエンジニアリング

#kanjava #j1ec

Page 4: Eclipse Collections 最新アップデート

TECHNOLOGY DIVISION

4

ゴールドマン・サックスのエンジニアリングゴールドマン・サックスとは投資銀行業務、証券業務および投資運用業務を中心に、企業、金融機関、政府機関、富裕層など多岐にわたるお客様を対象に幅広い金融サービスを提供している世界有数の金融機関です。 1869 年に創業、ニューヨークを本拠地として、世界の主要な金融市場に拠点を擁しています。ゴールドマン・サックス エンジニアリング複雑な問題へのソリューションの構築、時代を変えるテクノロジーの創出、ビジネスと金融マーケットをグローバルに牽引するシステム開発を行っています。http://www.goldmansachs.com/japan/what-we-do/engineering/index.html  Java Community Process – Executive CommitteeJCP Executive Committee は Java プラットフォームの仕様策定における重要なプロセスを担う委員会。ゴールドマン・サックスは 2011 年より本委員会の一員に選任。  

#kanjava #j1ec

Page 5: Eclipse Collections 最新アップデート

TECHNOLOGY DIVISION

5

Agenda• GS Collections から Eclipse Collections へ• 基本的な初期化方法• Stream API & JCF との比較例で見る Eclipse Collections の利点• 問題を解きながら学ぶ Eclipse Collections• 今後のロードマップ

#kanjava #j1ec

Page 6: Eclipse Collections 最新アップデート

TECHNOLOGY DIVISION

6

GS Collections からEclipse Collections へ

#kanjava #j1ec

Page 7: Eclipse Collections 最新アップデート

TECHNOLOGY DIVISION

7

GS Collections とは ?• ゴールドマン・サックスの開発したオープンソースコレクションフレームワーク

– Smalltalk に影響を受けたコレクションフレームワーク– 2004 年より開発を開始– 2012 年に GitHub にて公開 ( Apache 2.0 License )

• github.com/goldmansachs/gs-collections

• GS Collections Kata– 2007 年に開発されたトレーニング教材– 2,000 人以上の GS Java エンジニアが受講– GitHub にて公開 ( Apache 2.0 License )

• github.com/goldmansachs/gs-collections-kata

#kanjava #j1ec

Page 8: Eclipse Collections 最新アップデート

TECHNOLOGY DIVISION

8

人気上昇中Maven central のダウンロード数が JavaOne 2014 から右肩上がりSpring Reactor が GS Collections を依存ライブラリに追加

quote from: https://spring.io/blog/2014/05/06/reactor-1-1-0-release-now-available

GitHub 内のスター数で Java プロジェクトの Top 300 入り

#kanjava #j1ec

Page 9: Eclipse Collections 最新アップデート

TECHNOLOGY DIVISION

9

日本でも話題にJava Day Tokyo 2015 や JJUG CCC 2015 Spring 後に blog やTwitter で話題に  [1, 2, 3, 4, 5, 6, 7, 8, 9]

[5] 俺九番 . (2015, Sep 12). Java コレクション系のライブラリ、 GS Collections 使いやすくて好きなので大体のプロジェクトやるときはまずこれ入れてる [Twitter post]. Retrieved from https://twitter.com/orekyuu/status/642356311791767552[6] Kiyoshi SATOH. (2015, Jun 22). GS Collections という Java のコレクションのライブラリ。メソッドチェインで書けて、 Java8 のラムダ使えば Java で色々と関数型で書ける良い感じなライブラリ。 / “Java - GS Collections 使い方…” http://htn.to/utfBWD [Twitter post]. Retrieved from https://twitter.com/stealthinu/status/612816288226787328[7] よこな . (2015, Apr 15). 話題沸騰中やな〜 "Java - GS Collections 使い方メモ by @opengl_8080 on @Qiita http://qiita.com/opengl-8080/items/a13773e0653800e23323 …" [Twitter post]. Retrieved from https://twitter.com/ihcomega/status/588348537156411392[8] toshi_miura. (2015, Apr 11). JJUG CCC で一番心に刺さったこと。「 GS Collections 」使ってみっか・・・である。 [Twitter post]. Retrieved from https://twitter.com/toshi_miura/status/586879465537417217[9]eiryu@ 西新宿篇 . (2015, Apr 10). GS Collections アツいな / 他 43 コメント http://b.hatena.ne.jp/entry/www.goldmansachs.com/gs-collections/presentations/2015-04-08_JavaDayTokyo.pdf#tw?u=eiryu9 … “[PDF] ゴールドマン・サックスの Java への取り組み” http://htn.to/v3CtWq [Twitter post]. Retrieved from https://twitter.com/eiryu/status/586316836729262080

[ 出展 ][1] yy_yank. (2015, April 15). Java のコレクションフレームワークで物足りないなら GS Collections 使ったほうが良いかもしれない [Blog post]. Retrieved from http://yyyank.blogspot.jp/2015/04/javagscollections.html[2] mike_neck. (2015, Apr 16). GS-Collections は code kata で練習すると面白い [Blog post]. Retrieved from http://mike-neck.hatenadiary.com/entry/2015/04/16/075014[3] tokuhirom. (2015, Apr 16). GS Collections Kata をひと通りやった [Blog post]. Retrieved from http://blog.64p.org/entry/2015/04/16/094947[4] opengl-8080. (2015, Apr 15). GS Collections 使い方メモ [Qiita post]. Retriefed from http://qiita.com/opengl-8080/items/a13773e0653800e23323

#kanjava #j1ec

Page 10: Eclipse Collections 最新アップデート

TECHNOLOGY DIVISION

10

JavaOne2015 – Eclipse Collections by Example#kanjava #j1ec

Page 11: Eclipse Collections 最新アップデート

TECHNOLOGY DIVISION

11

Eclipse Collections

#kanjava #j1ec

Page 12: Eclipse Collections 最新アップデート

TECHNOLOGY DIVISION

12

Eclipse Collections とは ?• Eclipse Collections

– Eclipse 財団へ移管されたプロジェクト– プロジェクトリード:  Don Raab / Hiroshi Ito  – 1 月 20 日に公式リリース!

• 2015 年 10 月:プロポーザル提出• 2015 年 11 月:正式プロジェクトとして承認• 2015 年 12 月:リポジトリの移管作業完了• 2016 年 1 月 20 日、成果物の承認がおり公式リリース

– EPL/EDL のデュアルライセンス– Eclipse Collections 7.0 の機能は GS Collections 7.0 と同一– パッケージ名が変更

• com.gs -> org.eclipse

• Open for contributions!

#kanjava #j1ec

Page 13: Eclipse Collections 最新アップデート

TECHNOLOGY DIVISION

13

Eclipse Collections の機能Eclipse Collections 7.0

即時 & 遅延 , 逐次 & 並行 メモリ効率のよいコンテナ プリミティブ型コンテナ (8 種類すべて ) イミュータブルなコンテナ 多彩なコンテナ型 多彩なイテレーションパターン With メソッドパターン Target メソッドパターン 共変な戻り値型 Java 5+ まで後方互換

Java 8 Stream API- 関数型 API- 遅延実行のみ- 逐次処理と並行処理- プリミティブ型

Stream (3 種類 )- 拡張可能な

Collectors

Eclipse Collections では Stream API も使え、 さらに便利な機能を備えていますプロジェクトに貢献することもできます!!

#kanjava #j1ec

Page 14: Eclipse Collections 最新アップデート

TECHNOLOGY DIVISION

14

基本的な初期化方法

#kanjava #j1ec

Page 15: Eclipse Collections 最新アップデート

TECHNOLOGY DIVISION

15

初期化の方法( 1 )List, Set, Bag, Map, Multimap 等、すべてのコンテナに対してファクトリメソッドが存在( of(), with() どちら でも同様の初期化が可能)

MutableList<String> mutableList = Lists.mutable.of("One", "One", "Two", "Three");MutableList<String> mutableList = Lists.mutable.with("One", "One", "Two", "Three");

MutableSet<String> mutableSet = Sets.mutable.of("One", "One", "Two", "Three");

MutableBag<String> mutableBag = Bags.mutable.of("One", "One", "Two", "Three");

MutableMap<String, String> mutableMap = Maps.mutable.of("key1", "value1", "key2", "value2", "key3", "value3");

Multimap<String, String> multimapWithList = Multimaps.mutable.list.of("key1", "value1-1", "key1", "value1-2", "key2", "value2-1");

それぞれ Mutable, Immutable のファクトリが存在MutableList<String> mutableList = Lists.mutable.of(“One”, “Two”, “Three”); ImmutableList<String> immutableList= Lists.immutable.of("One", "Two", "Three");

空のコレクションを作るには empty(), of(), with() どれでも可MutableList<String> mutableListWithBlank = Lists.mutable.empty(); MutableList<String> mutableListWithBlank = Lists.mutable.of(); MutableList<String> mutableListWithBlank = Lists.mutable.with();

List, Set, Map 等のコンテナにはメモリ効率のよい FixedSize 用のファクトリも存在FixedSizeList<String> fixedSizeList= Lists.fixedSize.of("One", "Two");

#kanjava #j1ec

Page 16: Eclipse Collections 最新アップデート

TECHNOLOGY DIVISION

16

初期化の方法( 2 )すべてのプリミティブコンテナに対してもファクトリメソッドが存在

MutableIntList intList = IntLists.mutable.of(1, 2, 3);MutableLongList longList = LongLists.mutable.of(1L, 2L, 3L);MutableCharList charList = CharLists.mutable.of('a', 'b', 'c');MutableShortList shortList = ShortLists.mutable.of((short)1, (short)2, (short)3);MutableByteList byteList = ByteLists.mutable.of((byte)1, (byte)2, (byte)3);MutableBooleanList booleanList = BooleanLists.mutable.of(true, false);MutableFloatList floatList = FloatLists.mutable.of(1.0f, 2.0f, 3.0f);MutableDoubleList doubleList = DoubleLists.mutable.of(1.0, 2.0, 3.0);

IntInterval を使うと範囲指定した int のコレクションを作成することが可能IntInterval oneTo10 = IntInterval.fromTo(1, 10);// 1 から 10 までの int// [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]IntInterval oneTo10By3 = IntInterval.fromToBy(1, 10, 3); // 1 から 10 まで 3 ずつ増分した int // [1, 4, 7, 10]IntInterval oddsFrom1To10 = IntInterval.oddsFromTo(1, 10); // 1 から 10 までの奇数// [1, 3, 5, 7, 9]IntInterval evensFrom1To10 = IntInterval.evensFromTo(1, 10); // 1 から 10 までの偶数// [2, 4, 6, 8, 10]

#kanjava #j1ec

Page 17: Eclipse Collections 最新アップデート

TECHNOLOGY DIVISION

17

Stream API & JCF との比較例で見るEclipse Collections の利点

#kanjava #j1ec

Page 18: Eclipse Collections 最新アップデート

TECHNOLOGY DIVISION

18

boolean result = this.people.stream().anyMatch(person -> person.hasPet(PetType.CAT));

long result = this.people.stream().filter(person -> person.hasPet(PetType.CAT)).count();

List<Person> peopleWithCats = this.people.stream().filter(person -> person.hasPet(PetType.CAT))

.collect(Collectors.toList());

boolean result = this.people.anySatisfy(person -> person.hasPet(PetType.CAT));

int result = this.people.count(person -> person.hasPet(PetType.CAT));

MutableList<Person> peopleWithCats = this.people.select(person -> person.hasPet(PetType.CAT));

Eclip

se C

olle

ction

sSt

ream

API

より簡潔に書ける #kanjava #j1ec

Page 19: Eclipse Collections 最新アップデート

TECHNOLOGY DIVISION

19

より多くのケースでメソッド参照を活用できるboolean result = this.people.stream().anyMatch(person -> person.hasPet(PetType.CAT));

long result = this.people.stream().filter(person -> person.hasPet(PetType.CAT)).count();

List<Person> peopleWithCats = this.people.stream().filter(person -> person.hasPet(PetType.CAT))

.collect(Collectors.toList());

boolean result = this.people.anySatisfyWith(Person::hasPet, PetType.CAT);

int result = this.people.countWith(Person::hasPet, PetType.CAT);

MutableList<Person> peopleWithCats =this.people.selectWith(Person::hasPet, PetType.CAT);

Eclip

se C

olle

ction

sSt

ream

API

*Stream API ではメソッドに引数(この場合は PetType )を渡したいときにメソッド参照を使うことができない。

#kanjava #j1ec

Page 20: Eclipse Collections 最新アップデート

TECHNOLOGY DIVISION

20

List<Person> peopleWithCats = this.people.stream().filter(person -> person.hasPet(PetType.CAT))

.collect(Collectors.toList());

List<Person> peopleWithoutCats = this.people.stream().filter(person -> !person.hasPet(PetType.CAT))

.collect(Collectors.toList());

Map<Boolean, List<Person>> peopleWithcatsAndNoCats = this.people.stream().collect( Collectors.partitioningBy(person ->

person.hasPet(PetType.CAT)));peopleWithcatsAndNoCats.get(true);peopleWithcatsAndNoCats.get(false);MutableList<Person> peopleWithCats = this.people.select(person -> person.hasPet(PetType.CAT));

MutableList<Person> peopleWithoutCats = this.people.reject(person -> person.hasPet(PetType.CAT));

PartitionMutableList<Person> peopleWithcatsAndNoCats = this.people.partition(person -> person.hasPet(PetType.CAT));

peopleWithcatsAndNoCats.getSelected();peopleWithcatsAndNoCats.getRejected();Ec

lipse

Col

lecti

ons

Stre

am A

PIより高い可読性で記述できる #kanjava #j1ec

Page 21: Eclipse Collections 最新アップデート

TECHNOLOGY DIVISION

21

Eclip

se C

olle

ction

sSt

ream

API Stream<Integer> stream = Lists.mutable.with(1, 2, 3).stream();

Assert.assertEquals(1, stream.mapToInt(i -> i).min().getAsInt());Assert.assertEquals(3, stream.mapToInt(i -> i).max().getAsInt());java.lang.IllegalStateException: stream has already been operated upon or closed

at java.util.stream.AbstractPipeline.<init>(AbstractPipeline.java:203)

at java.util.stream.IntPipeline.<init>(IntPipeline.java:91)at

java.util.stream.IntPipeline$StatelessOp.<init>(IntPipeline.java:592)at

java.util.stream.ReferencePipeline$4.<init>(ReferencePipeline.java:204)at

java.util.stream.ReferencePipeline.mapToInt(ReferencePipeline.java:203)

LazyIterable<Integer> lazy = Lists.mutable.with(1, 2, 3).asLazy();Assert.assertEquals(1, lazy.collectInt(i -> i).min());Assert.assertEquals(3, lazy.collectInt(i -> i).max());

// throws

再利用が可能 #kanjava #j1ec

Page 22: Eclipse Collections 最新アップデート

TECHNOLOGY DIVISION

22

0

10,000,000

20,000,000

30,000,000

40,000,000

50,000,000

60,000,000

JDK HashSetEclipse Collections UnifiedSet

Elements

Size

(Mb)

Data collected by https://github.com/goldmansachs/gs-collections/tree/master/jmh-tests

メモリ効率が良い( HashSet vs UnifiedSet )

#kanjava #j1ec

Page 23: Eclipse Collections 最新アップデート

TECHNOLOGY DIVISION

23

0

5000000

10000000

15000000

20000000

25000000

30000000

35000000

40000000

45000000

JDK HashMapEclipse Collections UnifiedMap

Elements

Size

(Mb)

Data collected by https://github.com/goldmansachs/gs-collections/tree/master/jmh-tests

メモリ効率が良い( HashMap vs UnifiedMap )

#kanjava #j1ec

Page 24: Eclipse Collections 最新アップデート

TECHNOLOGY DIVISION

24

0

5,000,000

10,000,000

15,000,000

20,000,000

25,000,000

JDK ArrayListEclipse Collections IntArrayList

Elements

Size

(Mb)

Data collected by https://github.com/goldmansachs/gs-collections/tree/master/jmh-tests

メモリ効率が良い(プリミティブコレクション)#kanjava #j1ec

Page 25: Eclipse Collections 最新アップデート

TECHNOLOGY DIVISION

25

ImmutableList<String> eclipseList = Lists.immutable.with("two"); eclipseList.each(Procedures.throwing(appendable::append)); Assert.assertEquals("onetwo", appendable.toString());

Appendable appendable = new StringBuilder(); List<String> jdkList = Arrays.asList("one");

// jdkList.forEach(appendable::append);// Compile Error: incompatible thrown types java.io.IOException in method reference

jdkList.forEach(each -> { try { appendable.append(each); } catch (IOException e) { throw new RuntimeException(e); } }); Assert.assertEquals("one", appendable.toString());

Eclip

seCo

llecti

ons

Java

Co

llecti

ons

より簡潔に Exception の対処が記述できる#kanjava #j1ec

Page 26: Eclipse Collections 最新アップデート

TECHNOLOGY DIVISION

26

問題を解きながら学ぶEclipse Collections

(ぜひ標準の Java Collections Framework や Stream API を使用して解き比べてみてください)

#kanjava #j1ec

Page 27: Eclipse Collections 最新アップデート

TECHNOLOGY DIVISION

27

簡易なショッピングカートを実装したいと思います。アイテムは単純な文字列とし、下記の操作をした後、アイテムの文字列順にカート内の個数を出力します。- 操作 1 :“ Item B” をカートに追加- 操作 2 :“ Item A” をカートに追加- 操作 3 :“ Item C” を 3個カートに追加- 操作 4 :“ Item A” をカートに追加出力例:“Item A が 2個あります。”“Item B が 1個あります。”“Item C が 3個あります。”どのように実装するか考えてみてください。

問題1 #kanjava #j1ec

Page 28: Eclipse Collections 最新アップデート

TECHNOLOGY DIVISION

28

#ccc_gh4

簡易なショッピングカートを実装したいと思います。アイテムは単純な文字列とし、下記の操作をした後、アイテムの文字列順にカート内の個数を出力します。- 操作 1 :“ Item B” をカートに追加- 操作 2 :“ Item A” をカートに追加- 操作 3 :“ Item C” を 3個カートに追加- 操作 4 :“ Item A” をカートに追加出力例:“Item A が 2個あります。”“Item B が 1個あります。”“Item C が 3個あります。”どのように実装するか考えてみてください。

問題1 : SortedBag を使用した実装例// Bag をつかうと要素の出現回数を保持することができ、さらにSortedBag を使うと要素順にソートすることができます。MutableSortedBag<String> shoppingCart = SortedBags.mutable.empty();

shoppingCart.add("Item B");shoppingCart.add("Item A");shoppingCart.addOccurrences("Item C", 3); shoppingCart.add("Item A");

shoppingCart.forEachWithOccurrences( (item, count) -> System.out.println(item + " が " + count + " 個あります。"));

Page 29: Eclipse Collections 最新アップデート

TECHNOLOGY DIVISION

29

#ccc_gh4

プレゼントをランダムに決める機能を実装したいと思います。下記のような文字列が与えられたとして、メンバー: "Hiroshi", "Yusuke", "Fumio", "Shotaro", "Tatsuya", "Sumire"プレゼント: "Smart Phone", "PC", "Video Game", "Guitar", "Robot", "Media Player“

メンバーとプレゼントをそれぞれランダムに対応づけて、下記のような文字列を出力します。出力例:Shotaro は Smart Phone を手に入れました! Sumire は PC を手に入れました! Hiroshi は Video Game を手に入れました! Fumio は Guitar を手に入れました! Tatsuya は Robot を手に入れました! Yusuke は Media Player を手に入れました!どのように実装するか考えてみてください。

問題 2

Page 30: Eclipse Collections 最新アップデート

TECHNOLOGY DIVISION

30

#ccc_gh4

プレゼントをランダムに決める機能を実装したいと思います。下記のような文字列が与えられたとして、メンバー: "Hiroshi", "Yusuke", "Fumio", "Shotaro", "Tatsuya", "Sumire"プレゼント: "Smart Phone", "PC", "Video Game", "Guitar", "Robot", "Media Player“

メンバーとプレゼントをそれぞれランダムに対応づけて、下記のような文字列を出力します。出力例:Shotaro は Smart Phone を手に入れました! Sumire は PC を手に入れました! Hiroshi は Video Game を手に入れました! Fumio は Guitar を手に入れました! Tatsuya は Robot を手に入れました! Yusuke は Media Player を手に入れました!どのように実装するか考えてみてください。

問題 2: shuffleThis 、 zip を使用した実装例MutableList<String> names = Lists.mutable.of("Hiroshi", "Yusuke", "Fumio", "Shotaro", "Tatsuya", "Sumire");MutableList<String> presents = Lists.mutable.of("Smart Phone", "PC", "Video Game", "Guitar", "Robot", "Media Player");

MutableList<Pair<String, String>> nameAndPresentPairs = names .shuffleThis() //順番をランダムに入れ替えます .zip(presents); //name と present のペアをつくり、リストを返しますSystem.out.println( nameAndPresentPairs .collect(pair -> pair.getOne() + " は " + pair.getTwo()) .makeString("", " を手に入れました! \n", " を手に入れました! "));

Page 31: Eclipse Collections 最新アップデート

TECHNOLOGY DIVISION

31

#ccc_gh4

コレクションの分割処理を実装したいと思います。 1,000,000 要素あるコレクションを、 2,000 要素ずつ分割処理します。どのように実装するか考えてみてください。

問題 3

Page 32: Eclipse Collections 最新アップデート

TECHNOLOGY DIVISION

32

#ccc_gh4

コレクションの分割処理を実装したいと思います。 1,000,000 要素あるコレクションを、 2,000 要素ずつ分割処理します。どのように実装するか考えてみてください。

問題 3: chunk を使用した実装例LazyIterable<String> elements = Interval.oneTo(1_000_000).collect(i -> "element" + i); //[element1, element2, .... element1000000]

LazyIterable<RichIterable<String>> chunk = elements.chunk(2000); //2000 要素ごとに分割chunk.each(batchedElements -> { System.out.println("Processing from: " + batchedElements.getFirst() + " to: " + batchedElements.getLast() + "\n"); System.out.println("\t---- Do something -----\n");});

出力:Processing from: element1 to: element2000

---- Do something -----

Processing from: element2001 to: element4000

---- Do something -----…

Processing from: element996001 to: element998000

---- Do something -----

Processing from: element998001 to: element1000000

---- Do something -----

Page 33: Eclipse Collections 最新アップデート

TECHNOLOGY DIVISION

33

#ccc_gh4

下記のように、 2種類の集合があるとします。バンドメンバー: "Ken", "Irene", "Hiroshi"Java コミュニティメンバー: "Fumio", "Sumire", "Yusuke", "Hiroshi“

それぞれの集合から、下記のような文字列の出力を得るプログラムを書きます。出力例:バンドと Java コミュニティ両方に所属 : Hiroshiバンドまたは Java コミュニティに所属 : Fumio, Sumire, Ken, Hiroshi, Irene, Yusukeバンドのみ所属 : Ken, IreneJava コミュニティのみ所属 : Fumio, Sumire, Yusuke

どのように実装するか考えてみてください。

問題4

Page 34: Eclipse Collections 最新アップデート

TECHNOLOGY DIVISION

34

#ccc_gh4

下記のように、 2種類の集合があるとします。バンドメンバー: "Ken", "Irene", "Hiroshi"Java コミュニティメンバー: "Fumio", "Sumire", "Yusuke", "Hiroshi“

それぞれの集合から、下記のような文字列の出力を得るプログラムを書きます。出力例:バンドと Java コミュニティ両方に所属 : Hiroshiバンドまたは Java コミュニティに所属 : Fumio, Sumire, Ken, Hiroshi, Irene, Yusukeバンドのみ所属 : Ken, IreneJava コミュニティのみ所属 : Fumio, Sumire, Yusuke

どのように実装するか考えてみてください。

問題4 : SetIterable の API を使用した実装例

MutableSet<String> bandMember = Sets.mutable.of("Ken", "Irene", "Hiroshi");MutableSet<String> javaCommunityMember = Sets.mutable.of("Fumio", "Sumire", "Yusuke", "Hiroshi");

System.out.println(" バンドと Java コミュニティ両方に所属 : " + bandMember.intersect(javaCommunityMember).makeString());System.out.println(" バンドまたは Java コミュニティに所属 : " + bandMember.union(javaCommunityMember).makeString());System.out.println(" バンドのみ所属 : " + bandMember.difference(javaCommunityMember).makeString());System.out.println("Java コミュニティのみ所属 : " + javaCommunityMember.difference(bandMember).makeString());

intersect

difference difference

union

* スペースの都合上、例には挙げていませんが、  XOR をとる symmetricDifference() もあります。

Page 35: Eclipse Collections 最新アップデート

TECHNOLOGY DIVISION

35

#ccc_gh4

下記のような文字列のコレクションから、数字のみ抽出して別の文字列コレクションを作りたいと思います。["[A12345]", "[A99234]", "[A43156]", "[A55324]“]

出力例[12345, 99234, 43156, 55324]

どのように実装するか考えてみてください。

問題 5:

Page 36: Eclipse Collections 最新アップデート

TECHNOLOGY DIVISION

36

#ccc_gh4問題 5: CharAdapter を使用した実装例

// CharAdapter は Java 8 で導入された String.chars() と似た機能です。// しかし、 chars() は IntStream を返すため、下記のように単純に書くことはできません。// ぜひ試してみてください。MutableList<String> strings = Lists.mutable.of("[A12345]", "[A99234]", "[A43156]", "[A55324]");LazyIterable<String> idList = strings.asLazy().collect( string -> CharAdapter.adapt(string) .select(Character::isDigit) .makeString(""));

System.out.println(idList);

* バージョン 7.0 で新しく導入された機能です。* サロゲートペアに対応した CodePointAdapter もあります。

下記のような文字列のコレクションから、数字のみ抽出して別の文字列コレクションを作りたいと思います。["[A12345]", "[A99234]", "[A43156]", "[A55324]“]

出力例[12345, 99234, 43156, 55324]

どのように実装するか考えてみてください。

Page 37: Eclipse Collections 最新アップデート

TECHNOLOGY DIVISION

37

問題を解きながら学ぶ Eclipse CollectionsEclipse Collections には他にも便利な機能が多数備わっています。さらに Eclipse Collections を学んでみたい方は、 Kata を解いてみてください。GS/Eclipse Collections Kata (Kata はこれから Eclipse Collections へ移行作業に入ります )

#ccc_gh4

https://github.com/goldmansachs/gs-collections-kata https://github.com/eclipse/eclipse-collections-kata - ユニットテストをひとつずつパスしていく TDD 型トレーニングマテリアル- Eclipse Collections/GS Collections の使用法を学習するのに最適- ゴールドマン・サックスの研修にも使用- Stream API やラムダ式の学習にも使える

Page 38: Eclipse Collections 最新アップデート

TECHNOLOGY DIVISION

38

#ccc_gh4Eclipse Collections  ロードマップ

• Eclipse Collections 7.1 – 2016 Q1– GS Collections Kata を Eclipse Collections Kata に移行– GS Collections からの移行スクリプトのリリース– ドキュメント、チュートリアルの充実– コントリビューター、コミッターの拡充

• Eclipse Collections 8.0 – 2016 Q2/Q3– Java8 の関数インタフェースとの互換性を確保– Java8 の Optional 型を返す API を導入( detect 、 max 、 min等)– 独自の Stream実装による stream() のパフォーマンス改善– Default メソッド活用によるコード量削減– 上記変更により Java8 以前の後方互換性は撤廃

Page 39: Eclipse Collections 最新アップデート

TECHNOLOGY DIVISION

39

#ccc_gh4Eclipse Collections にコントリビュートしてみよう開発に貢献してみたい方はお知らせ下さい!!

How To Contribute: https://github.com/eclipse/eclipse-collections/blob/master/CONTRIBUTING.md 要約: Eclipse 財団の CLA にサインしてプルリクエストでコントリビュート開発者メーリングリスト : https://dev.eclipse.org/mailman/listinfo/collections-dev Issues: https://github.com/eclipse/eclipse-collections/issues

コントリビュート例– 興味のある Issue にサインアップして実装– ドキュメント、チュートリアルの拡充、日本語化– Kata の日本語化

Page 40: Eclipse Collections 最新アップデート

TECHNOLOGY DIVISION

40

Resources• Eclipse Collections website

http://www.eclipse.org/collections • JavaOne 2015 – Eclipse Collections by Example

https://published-rs.lanyonevents.com/published/oracleus2015/sessionsFiles/1528/CON10915_2015-10-28%20JavaOne%20-%

20EclipseCollectionsByExample.pdf

• Eclipse Collections on GitHubhttps://github.com/eclipse/eclipse-collections https://github.com/eclipse/eclipse-collections/wiki https://github.com/eclipse/eclipse-collections-kata

• JJUG CCC - GS CollectionsとJava 8 実用的で流暢なAPIで楽しい開発を!http://www.goldmansachs.com/gs-collections/presentations/2015-04-11_JJUG_CCC.pdf

• Parallel-lazy Performance: Java 8 vs Scala vs GS Collectionshttp://www.infoq.com/presentations/java-streams-scala-parallel-collections

Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.

#ccc_gh4

Page 41: Eclipse Collections 最新アップデート

TECHNOLOGY DIVISION

41

Learn more at GS.com/Engineering

© 2015 Goldman Sachs. This presentation should not be relied upon or considered investment advice. Goldman Sachs does not warrant or guarantee to anyone the accuracy, completeness or efficacy of this presentation, and recipients should not rely on it except at their own risk. This presentation may not be forwarded or disclosed except with this disclaimer intact.

#ccc_gh4