Eclipse Collections 最新アップデート

285
-1

Published on

2016/01/23に開催した関ジャバイベント「JavaOne報告会 in 大阪」でのセッション「Eclipse Collections 最新アップデート」のスライドです。
http://kanjava.connpass.com/event/24474/

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
285
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
1
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • Eclipse Collections update

    Goldman Sachs
    Technology division Vice President
    Hiroshi Ito
  • Engineering at Goldman Sachs
  • Engineering at Goldman Sachs
  • Engineering at Goldman Sachs

    Goldman Sachs
    A leading global investment banking, securities and investment management firm that provides a wide range of financial services to a substantial and diversified client base that includes corporations, financial institutions, governments and high-net-worth individuals. Founded in 1869, the firm is headquartered in New York and maintains offices in all major financial centers around the world.

    Goldman Sachs Technology Division:
    We build solutions to some of the most complex problems, creating transformational technologies and developing systems that drive business and financial markets worldwide.
  • From GS Collections to Eclipse Collections
    Basics
    Benefit of Eclipse Collections compared to Streams and JCF
    Learning Eclipse Collections by solving problems
    Future roadmap

  • GS Collections
  • Open source Java collections framework developed in Goldman Sachs
    Inspired by Smalltalk Collections Framework
    In development since 2004
    Hosted on GitHub w/ Apache 2.0 License in January 2012
    github.com/goldmansachs/gs-collections
    GS Collections Kata
    Internal training developed in 2007
    Taught to > 2,000 GS Java developers
    Hosted on GitHub w/ Apache 2.0 License in January 2012
    github.com/goldmansachs/gs-collections-kata
  • Trending Positively

    Spring Reactor includes GS Collections as a dependency

    Monthly Maven central downloads have risen since JavaOne 2014

    In the Top 300 Java GitHub projects based on number of stars
  • It’s been talked about in Japan

    There have been blog/Twitter posts after Java Day Tokyo 2015 and JJUG CCC 2015 Spring.

    [cites]
    [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
    [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
  • JavaOne2015 – Eclipse Collections by Example
  • Eclipse Collections
  • Eclipse Collections
    Project @ Eclipse Foundation
    https://projects.eclipse.org/proposals/eclipse-collections
    Project lead: Don Raab / Hiroshi Ito
    7.0, public Released on Jan 20th!
    Oct 2015: Proposal submitted
    Nov 2015: Project proposal approved
    Dec 2015: Repository migration completed
    Jan 20th 2016: Release review approved
    Eclipse Collections 7.0 feature set is the same as GS Collections 7.0
    Dual license under EPL/EDL
    Packages renamed
    com.gs -> org.eclipse

    Eclipse Collections - Open for contributions!
  • Java 8 Streams
    Functional APIs
    Lazy only
    Single use
    Serial & Parallel
    Primitive streams (3 types)
    Extensible Collectors

    Eclipse Collections 7.0

    Eager & Lazy, Serial & Parallel
    Memory efficient containers
    Primitive containers (all 8)
    Immutable containers
    More container types
    More iteration patterns
    “With” method patterns
    “target” method patterns
    Covariant return types
    Java 5+ compatible

  • How to initialize
  • There are factory methods for all containers, such as List, Set, Bag, Map, Multimap etc. You can choose either methods of() or with().

    There are factories for both Mutable and Immutable.

    You can create empty collections by empty(), of(), with().

    There are memory efficient fixed size factories for some containers like List, Set and Map etc.
  • There are factory methods for all primitive containers.

    You can create ranged int collections with IntInterval.
  • Benefit of Eclipse Collections compared to Streams and JCF
  • You can write codes in more concise manner
  • You can leverage method references in more cases
  • You can write codes in better readability.
  • You can reuse the collection
  • More memory efficient (HashSet vs UnifiedSet)
  • More memory efficient (HashMap vs UnifiedMap)
  • More memory efficient (primitive collections)
  • You can write Exception handling in more concise manner.
  • Learning Eclipse Collections by solving problems
    (please try to solve them with JDK Collections, Streams and compare yourself)
  • You want to implement a simple shopping cart. To make it easy, assume items are simple Strings. After executing each operation below, output the strings like below with the order of item string.

    Operation1: Add “Item1” to the cart.
    Operation2: Add “Item2” to the cart.
    Operation3: Add “Item1” to the cart.
    Operation4: Add “Item3” with 3 quantity to the cart.

    Outputs:
    “There are 2 Item1”
    “There is 1 Item2”
    “There are 3 Item3”

    How would you implement?
    (in Japanese, there is no difference between “are” and “is”, so the output is simpler)
  • You want to implement a simple shopping cart. To make it easy, assume items are simple Strings. After executing each operation below, output the strings like below with the order of item string.

    Operation1: Add “Item1” to the cart.
    Operation2: Add “Item2” to the cart.
    Operation3: Add “Item1” to the cart.
    Operation4: Add “Item3” with 3 quantity to the cart.

    Outputs:
    “There are 2 Item1”
    “There is 1 Item2”
    “There are 3 Item3”

    How would you implement?
    (in Japanese, there is no difference between “are” and “is”, so the output is simpler)
  • You want to implement a functionality to match a gift with each member at random. Given the strings below,

    Member: "Hiroshi", "Yusuke", "Fumio", "Shotaro", "Tatsuya", "Sumire"
    Gifts: "Smart Phone", "PC", "Video Game", "Guitar", "Robot", "Media Player“

    match each member and gift at random, and output the strings such as below.

    Output example:
    Shotaro got Smart Phone!
    Sumire got PC!
    Hiroshi got Video Game!
    Fumio got Guitar!
    Tatsuya got Robot!
    Yusuke got Media Player!

    How would you implement?
  • You want to implement a functionality to match a gift with each member at random. Given the strings below,

    Member: "Hiroshi", "Yusuke", "Fumio", "Shotaro", "Tatsuya", "Sumire"
    Gifts: "Smart Phone", "PC", "Video Game", "Guitar", "Robot", "Media Player“

    match each member and gift at random, and output the strings such as below.

    Output example:
    Shotaro got Smart Phone!
    Sumire got PC!
    Hiroshi got Video Game!
    Fumio got Guitar!
    Tatsuya got Robot!
    Yusuke got Media Player!

    How would you implement?

  • You want to implement a batching logic. Given a collections with 1,000,000 elements, you want to process 2,000 elements per batch.

    How would you implement?
  • You want to implement a batching logic. Given a collections with 1,000,000 elements, you want to process 2,000 elements per batch.

    How would you implement?
  • Given there are 2 sets of people below.

    Band member: “Ken”, “Irene”, “Hiroshi”
    Java community member: “Fumio”, “Sumire”, “Yusuke”, “Hiroshi”

    Write a program that outputs strings such like below based on the 2 sets.

    Output example:
    Belongs to both band and Java community: Hiroshi
    Belongs to either band or Java community: Fumio, Sumire, Ken, Hiroshi, Irene, Yusuke
    Belongs to band only: Ken, Irene
    Belongs to Java community only: Fumio, Sumire, Yusuke

    How would you implement?
  • Given there are 2 sets of people below.

    Band member: “Ken”, “Irene”, “Hiroshi”
    Java community member: “Fumio”, “Sumire”, “Yusuke”, “Hiroshi”

    Write a program that outputs strings such like below based on the 2 sets.

    Output example:
    Belongs to both band and Java community: Hiroshi
    Belongs to either band or Java community: Fumio, Sumire, Ken, Hiroshi, Irene, Yusuke
    Belongs to band only: Ken, Irene
    Belongs to Java community only: Fumio, Sumire, Yusuke

    How would you implement?

  • You have a string collection like below. You want to extract the digit parts only, and create a new string collection.

    ["[A12345]", "[A99234]", "[A43156]", "[A55324]“]

    Output example
    [12345, 99234, 43156, 55324]

    How would you implement?
  • You have a string collection like below. You want to extract the digit parts only, and create a new string collection.

    ["[A12345]", "[A99234]", "[A43156]", "[A55324]“]

    Output example
    [12345, 99234, 43156, 55324]

    How would you implement?

    * This is a new feature introduced in version 7.0
    * There is also CodePointAdapter which can handle surrogate pairs, too
  • Learning Eclipse Collections by solving problems.

    If you want to learn more about Eclipse Collections, try solving Kata, too.

    GS Collections Kata
    Training material by passing unit test one by one
    It’s the best material to learn Eclipse Collections/GS Collections
    It’s used in Goldman Sachs trainings
    You can also learn Streams and Lambda with Kata
  • Eclipse Collections Roadmap

    Eclipse Collections 7.1 – 2016 Q1
    Minor updates and brush up OSS characteristics
    Migrate GS Collections Kata to Eclipse Collections Kata
    Feature enhancements and performance improvement
    Enrich documentation and tutorials
    Increase contributors, committers
    Eclipse Collections 8.0 – 2016 Q2/Q3
    Make Eclipse Collections functional interfaces extend Java 8 functional interfaces
    Create our own Streams and override the stream() method for better performance
    Add new API methods that return Optional
    Use default methods to reduce lines of code and jar size

  • Eclipse Collections accepts contributions

    Please let us know if you’re interested in contributing!!

    How To Contribute: https://github.com/eclipse/eclipse-collections/blob/master/CONTRIBUTING.md
    Summary: Sign Eclipse Foundation CLA and submit pull-requests
    Developer mailing list: https://dev.eclipse.org/mailman/listinfo/collections-dev 
    Issues: https://github.com/eclipse/eclipse-collections/issues

    Contribution examples:
    Sign up to the issues you’re interested in, and implement
    Write documentation/tutorial, and/or translate to Japanese
    Translate Kata to Japanese

  • Eclipse Collections 最新アップデート

    1. 1. TECHNOLOGY DIVISION 1 Eclipse Collections最新アップデート ゴールドマン・サックス テクノロジー部 ヴァイス・プレジデント 伊藤博志 #kanjava #j1ec
    2. 2. TECHNOLOGY DIVISION 2 http://www.eclipse.org/collections #kanjava #j1ec
    3. 3. TECHNOLOGY DIVISION 3 ゴールドマン・サックスのエンジニアリング #kanjava #j1ec
    4. 4. TECHNOLOGY DIVISION 4 ゴールドマン・サックスのエンジニアリング ゴールドマン・サックスとは 投資銀行業務、証券業務および投資運用業務を中心に、企業、金融機関、政府機関、富 裕層など多岐にわたるお客様を対象に幅広い金融サービスを提供している世界有数の金 融機関です。1869年に創業、ニューヨークを本拠地として、世界の主要な金融市場に拠点 を擁しています。 ゴールドマン・サックス エンジニアリング 複雑な問題へのソリューションの構築、時代を変えるテクノロジーの創出、ビジネスと金融 マーケットをグローバルに牽引するシステム開発を行っています。 http://www.goldmansachs.com/japan/what-we-do/engineering/index.html Java Community Process – Executive Committee JCP Executive CommitteeはJavaプラットフォームの仕様策定における重要なプロセスを 担う委員会。ゴールドマン・サックスは2011年より本委員会の一員に選任。 #kanjava #j1ec
    5. 5. TECHNOLOGY DIVISION 5 Agenda • GS CollectionsからEclipse Collectionsへ • 基本的な初期化方法 • Stream API & JCFとの比較例で見るEclipse Collectionsの利点 • 問題を解きながら学ぶEclipse Collections • 今後のロードマップ #kanjava #j1ec
    6. 6. TECHNOLOGY DIVISION 6 GS Collectionsから Eclipse Collectionsへ #kanjava #j1ec
    7. 7. 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
    8. 8. 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
    9. 9. 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コレクション系のライブラリ、GSCollections使いやすくて好きなので大体のプロジェクトやるときはまずこれ入れて る [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_8080on @Qiita http://qiita.com/opengl- 8080/items/a13773e0653800e23323…" [Twitter post]. Retrievedfrom https://twitter.com/ihcomega/status/588348537156411392 [8] toshi_miura. (2015, Apr 11). JJUG CCCで一番心に刺さったこと。「GSCollections」使ってみっか・・・である。 [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のコレクションフレームワークで物足りないならGSCollections使ったほうが良いかもしれない [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
    10. 10. TECHNOLOGY DIVISION 10 JavaOne2015 – Eclipse Collections by Example #kanjava #j1ec
    11. 11. TECHNOLOGY DIVISION 11 Eclipse Collections #kanjava #j1ec
    12. 12. 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
    13. 13. 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
    14. 14. TECHNOLOGY DIVISION 14 基本的な初期化方法 #kanjava #j1ec
    15. 15. 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
    16. 16. 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
    17. 17. TECHNOLOGY DIVISION 17 Stream API & JCFとの比較例で見る Eclipse Collectionsの利点 #kanjava #j1ec
    18. 18. 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)); EclipseCollectionsStreamAPI より簡潔に書ける #kanjava #j1ec
    19. 19. 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); EclipseCollectionsStreamAPI *Stream APIではメソッドに引数(この場合はPetType)を渡したいときにメソッド参照を使うことができない。 #kanjava #j1ec
    20. 20. 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(); EclipseCollectionsStreamAPI より高い可読性で記述できる #kanjava #j1ec
    21. 21. TECHNOLOGY DIVISION 21 EclipseCollectionsStreamAPI 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
    22. 22. TECHNOLOGY DIVISION 22 0 10 20 30 40 50 60 Size(Mb) Elements JDK HashSet Eclipse Collections UnifiedSet Data collected by https://github.com/goldmansachs/gs-collections/tree/master/jmh-tests メモリ効率が良い(HashSet vs UnifiedSet) #kanjava #j1ec
    23. 23. TECHNOLOGY DIVISION 23 0 5 10 15 20 25 30 35 40 45 Size(Mb) Elements JDK HashMap Eclipse Collections UnifiedMap Data collected by https://github.com/goldmansachs/gs-collections/tree/master/jmh-tests メモリ効率が良い(HashMap vs UnifiedMap) #kanjava #j1ec
    24. 24. TECHNOLOGY DIVISION 24 0 5 10 15 20 25 Size(Mb) Elements JDK ArrayList Eclipse Collections IntArrayList Data collected by https://github.com/goldmansachs/gs-collections/tree/master/jmh-tests メモリ効率が良い(プリミティブコレクション) #kanjava #j1ec
    25. 25. 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()); Eclipse Collections Java Collections より簡潔にExceptionの対処が記述できる #kanjava #j1ec
    26. 26. TECHNOLOGY DIVISION 26 問題を解きながら学ぶ Eclipse Collections (ぜひ標準のJava Collections FrameworkやStream APIを使用して解き比べてみてください) #kanjava #j1ec
    27. 27. 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
    28. 28. 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 + "個あります。") );
    29. 29. 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
    30. 30. 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", "を手に入れました!"));
    31. 31. TECHNOLOGY DIVISION 31 #ccc_gh4 コレクションの分割処理を実装したいと思います。1,000,000要素あるコレクションを、2,000要素ずつ分割処理します。 どのように実装するか考えてみてください。 問題3
    32. 32. 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 -----
    33. 33. TECHNOLOGY DIVISION 33 #ccc_gh4 下記のように、2種類の集合があるとします。 バンドメンバー:"Ken", "Irene", "Hiroshi" Javaコミュニティメンバー:"Fumio", "Sumire", "Yusuke", "Hiroshi“ それぞれの集合から、下記のような文字列の出力を得るプログラムを書きます。 出力例: バンドとJavaコミュニティ両方に所属: Hiroshi バンドまたはJavaコミュニティに所属: Fumio, Sumire, Ken, Hiroshi, Irene, Yusuke バンドのみ所属: Ken, Irene Javaコミュニティのみ所属: Fumio, Sumire, Yusuke どのように実装するか考えてみてください。 問題4
    34. 34. TECHNOLOGY DIVISION 34 #ccc_gh4 下記のように、2種類の集合があるとします。 バンドメンバー:"Ken", "Irene", "Hiroshi" Javaコミュニティメンバー:"Fumio", "Sumire", "Yusuke", "Hiroshi“ それぞれの集合から、下記のような文字列の出力を得るプログラムを書きます。 出力例: バンドとJavaコミュニティ両方に所属: Hiroshi バンドまたはJavaコミュニティに所属: Fumio, Sumire, Ken, Hiroshi, Irene, Yusuke バンドのみ所属: Ken, Irene Javaコミュニティのみ所属: 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()もあります。
    35. 35. TECHNOLOGY DIVISION 35 #ccc_gh4 下記のような文字列のコレクションから、数字のみ抽出して別の文字列コレクションを作りたいと思います。 ["[A12345]", "[A99234]", "[A43156]", "[A55324]“] 出力例 [12345, 99234, 43156, 55324] どのように実装するか考えてみてください。 問題5:
    36. 36. 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] どのように実装するか考えてみてください。
    37. 37. TECHNOLOGY DIVISION 37 問題を解きながら学ぶEclipse Collections Eclipse 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やラムダ式の学習にも使える
    38. 38. TECHNOLOGY DIVISION 38 #ccc_gh4 Eclipse 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以前の後方互換性は撤廃
    39. 39. TECHNOLOGY DIVISION 39 #ccc_gh4 Eclipse 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の日本語化
    40. 40. 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 GitHub https://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 Collections http://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
    41. 41. 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
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×