TECHNOLOGY DIVISION 1 Eclipse Collections by Example GS.com/Engineering Fall, 2015 Hiroshi Ito Donald Raab.

Slides:



Advertisements
Similar presentations
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Advertisements

 Specifies a set of methods (i.e., method headings) that any class that implements that interface must have.  An interface is a type (but is not a class).
Core Java Lecture 4-5. What We Will Cover Today What Are Methods Scope and Life Time of Variables Command Line Arguments Use of static keyword in Java.
Identity and Equality Based on material by Michael Ernst, University of Washington.
Problem Solving 5 Using Java API for Searching and Sorting Applications ICS-201 Introduction to Computing II Semester 071.
Mutability SWE 332 Fall 2011 Paul Ammann. SWE 3322 Data Abstraction Operation Categories Creators Create objects of a data abstraction Producers Create.
Object Oriented Programming Elhanan Borenstein Lecture #12 copyrights © Elhanan Borenstein.
TECHNOLOGY DIVISION 1 GS Collections and Java 8 Functional, Fluent, Friendly & Fun! GS.com/Engineering Fall, 2014 Donald Raab Craig Motlin.
1 Investment Banking Investment Management Securities Our Business.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
CS102 Data Types in Java CS 102 Java’s Central Casting.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
COMP 110 Introduction to Programming Mr. Joshua Stough September 10, 2007.
Principles of Computer Programming (using Java) Review Haidong Xue Summer 2011, at GSU.
© Dr. A. Williams, Fall Present Software Quality Assurance – JUnit Lab 1 JUnit A unit test framework for Java –Authors: Erich Gamma, Kent Beck Objective:
11 Values and References Chapter Objectives You will be able to: Describe and compare value types and reference types. Write programs that use variables.
Java. Why Java? It’s the current “hot” language It’s almost entirely object-oriented It has a vast library of predefined objects It’s platform independent.
Java Programming Robert Chatley William Lee
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
Presented by: Mojtaba Khezrian. Agenda Object Creation Object Storage More on Arrays Parameter Passing For Each VarArgs Spring 2014Sharif University of.
Lambdas and Streams. Functional interfaces Functional interfaces are also known as single abstract method (SAM) interfaces. Package java.util.function.
This presentation reflects information available to the Technology Division of Goldman Sachs only and not any other part of Goldman Sachs. It should not.
General Features of Java Programming Language Variables and Data Types Operators Expressions Control Flow Statements.
Effective Java: Generics Last Updated: Spring 2009.
Algorithm Programming Bar-Ilan University תשס"ח by Moshe Fresko.
Lecture 2 Object Oriented Programming Basics of Java Language MBY.
Basic Java Programming CSCI 392 Week Two. Stuff that is the same as C++ for loops and while loops for (int i=0; i
Basic Java Syntax CSE301 University of Sunderland Harry R Erwin, PhD.
GENERIC COLLECTIONS. Type-Wrapper Classes  Each primitive type has a corresponding type- wrapper class (in package java.lang).  These classes are called.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
Core Java: Essential Features 08/05/2015 Kien Tran.
Java 5 Part 1 CSE301 University of Sunderland Harry Erwin, PhD.
12-CRS-0106 REVISED 8 FEB 2013 CSG2H3 Object Oriented Programming.
Peyman Dodangeh Sharif University of Technology Fall 2013.
Sadegh Aliakbary Sharif University of Technology Spring 2011.
Scala Collections Performance GS.com/Engineering March, 2015 Craig Motlin.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs -
Types in programming languages1 What are types, and why do we need them?
C# C1 CSC 298 Elements of C# code (part 1). C# C2 Style for identifiers  Identifier: class, method, property (defined shortly) or variable names  class,
Copyright Curt Hill Variables What are they? Why do we need them?
Java Basics Opening Discussion zWhat did we talk about last class? zWhat are the basic constructs in the programming languages you are familiar.
In Java.... Variables contain the values of primitive data types Value Types.
Lec 23 Memory Maps Primitive variables and Reference (object) variables.
Cs2220: Engineering Software Class 3: Java Semantics Fall 2010 University of Virginia David Evans.
C++ (intro) Created by Hwansoo Han Edited by Ikjun Yeom.
PROG Mobile Java Application Development PROG Mobile Java Application Development Data Storage, Continued.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
Peyman Dodangeh Sharif University of Technology Spring 2014.
Lecture 7 February 24, Javadoc version and author Tags These go in the comments before named classes. –Put your SS# on a separate line from the.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
A comparison of C-Sharp and Java Zunaid Jogee Supervisor: T. Stakemire.
INTRODUCTION CHAPTER #1 Visual Basic.NET. VB.Net General features It is an object oriented language  In the past VB had objects but focus was not placed.
CSC 142 F 1 CSC 142 References and Primitives. CSC 142 F 2 Review: references and primitives  Reference: the name of an object. The type of the object.
Midterm Review Tami Meredith. Primitive Data Types byte, short, int, long Values without a decimal point,..., -1, 0, 1, 2,... float, double Values with.
Chapter 1: Preliminaries Lecture # 2. Chapter 1: Preliminaries Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation.
Eclipse Collections An Inside Look March 2016 Copyright © 2016 Goldman Sachs. All rights reserved.
CompSci 100E JB1.1 Java Basics (ala Goodrich & Tamassia)  Everything is in a class  A minimal program: public class Hello { public static void main(String[]
Coming up Implementation vs. Interface The Truth about variables Comparing strings HashMaps.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Information and Computer Sciences University of Hawaii, Manoa
Robots for the Kid in All of Us
Chapter 6 – Data Types CSCE 343.
Java package classes Java package classes.
null, true, and false are also reserved.
Introduction to Java Programming
Java Programming Review 1
Agenda Types and identifiers Practice Assignment Keywords in Java
Presentation transcript:

TECHNOLOGY DIVISION 1 Eclipse Collections by Example GS.com/Engineering Fall, 2015 Hiroshi Ito Donald Raab

TECHNOLOGY DIVISION 2 Introductions – JavaOne 2015

TECHNOLOGY DIVISION 3 Agenda What is GS Collections? What is Eclipse Collections? JCF and EC Memory Comparisons Hobson’s Choice Method Reference Preference Eclipse Collections Examples To Use or Reuse? More Features

TECHNOLOGY DIVISION 4 What is 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

TECHNOLOGY DIVISION 5 Trending Positively Monthly Maven central downloads have risen since JavaOne 2014 Spring Reactor includes GS Collections as a dependency quote from: In the Top 300 Java GitHub projects based on number of stars

TECHNOLOGY DIVISION 6 Agenda What is GS Collections? What is Eclipse Collections? JCF and EC Memory Comparisons Hobson’s Choice Method Reference Preference Eclipse Collections Examples To Use or Reuse? More Features

TECHNOLOGY DIVISION 7 What is Eclipse Collections? Eclipse Collections 7.0 Eclipse Foundation –Feature set is the same as GS Collections 7.0 –Packages renamed com.gs -> org.eclipse Eclipse Collections - Open for contributions! –Drop by the Eclipse Foundation or Goldman Sachs booths in the JavaOne exhibitor hall to find out more!

TECHNOLOGY DIVISION 8 Eclipse Collections Features 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 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 Java 8 Streams -Functional APIs -Lazy only -Single use -Serial & Parallel -Primitive streams (3 types) -Extensible Collectors Java 8 Streams -Functional APIs -Lazy only -Single use -Serial & Parallel -Primitive streams (3 types) -Extensible Collectors Eclipse Collections has Streams… And much much more! And you can contribute too!!!

TECHNOLOGY DIVISION 9 Agenda What is GS Collections? What is Eclipse Collections? JCF and EC Memory Comparisons Hobson’s Choice Method Reference Preference Eclipse Collections Examples To Use or Reuse? More Features

TECHNOLOGY DIVISION 10 Comparing Sets Data collected by

TECHNOLOGY DIVISION 11 Comparing Maps Data collected by

TECHNOLOGY DIVISION 12 Why Primitive Collections? Data collected by

TECHNOLOGY DIVISION 13 Agenda What is GS Collections? What is Eclipse Collections? JCF and EC Memory Comparisons Hobson’s Choice Method Reference Preference Eclipse Collections Examples To Use or Reuse? More Features

TECHNOLOGY DIVISION 14 Hobson’s choice “A Hobson's choice is a free choice in which only one option is actually offered.” –Wikipedia “You get what you get and you don’t get upset!”

TECHNOLOGY DIVISION 15 Hobson’s Choice - Iteration Patterns Lazy or Eager? –Java Collections Framework = Eager –Streams = Lazy –Eclipse Collections = You choose Assert.assertEquals(Integer.valueOf(1), Collections.min(Lists.mutable.with(1, 2, 3))); Assert.assertEquals(1, Lists.mutable.with(1, 2, 3).stream().mapToInt(i -> i).min().getAsInt()); Assert.assertEquals(1, IntLists.mutable.with(1, 2, 3).min()); Assert.assertEquals(1, IntLists.mutable.with(1, 2, 3).asLazy().min());

TECHNOLOGY DIVISION 16 Hobson’s Choice - Map TypeEclipse CollectionsJDK Collections Bag Use Map Multimap Use Map > BiMap Use two maps. PartitionPartitionIterable Use Map > Pair Use Map.Entry When your only tool is a Map, everything is either a key, a value or null.

TECHNOLOGY DIVISION 17 Hobson’s Choice - Primitives TypeEclipse CollectionsJDK Collections Primitive ListYesBoxed Primitive SetYesBoxed Primitive MapYesBoxed Primitive StackYesBoxed Primitive BagYesMap and Boxed Primitive Lazy / StreamYes (all 8 primitives)Int, Long, Double only

TECHNOLOGY DIVISION 18 Hobson’s Choice - Parallel Stream addresses = people.parallelStream().map(Person::getAddress); ParallelListIterable addresses = people.asParallel(executor, batchSize).collect(Person::getAddress);

TECHNOLOGY DIVISION 19 Agenda What is GS Collections? What is Eclipse Collections? JCF and EC Memory Comparisons Hobson’s Choice Method Reference Preference Eclipse Collections Examples To Use or Reuse? More Features

TECHNOLOGY DIVISION 20 Method Reference Preference I prefer to use method references whenever it is possible They are clear, concise and self-documenting Outputs: GOODBYE! HELLO! Lists.mutable.with("you", "say", "goodbye!").asLazy().collect(each -> each.toUpperCase()).select(each -> each.equals("GOODBYE!")).each(each -> System.out.println(each)); Lists.mutable.with("i", "say", "hello!", "hello!").asLazy().collect(String::toUpperCase).select("HELLO!"::equals).each(System.out::println);

TECHNOLOGY DIVISION 21 Agenda What is GS Collections? What is Eclipse Collections? JCF and EC Memory Comparisons Hobson’s Choice Method Reference Preference Eclipse Collections Examples To Use or Reuse? More Features

TECHNOLOGY DIVISION 22 Eclipse Collections by Example Powered by Astah public boolean hasPet(PetType petType) { return this.pets.anySatisfy(pet -> pet.getType().equals(petType)); }

TECHNOLOGY DIVISION 23 Setup private MutableList public void setUp() throws Exception { this.people = Lists.mutable.with( new Person("Mary", "Smith").addPet(PetType.CAT, "Tabby", 2), new Person("Bob", "Smith").addPet(PetType.CAT, "Dolly", 3).addPet(PetType.DOG, "Spot", 2), new Person("Ted", "Smith").addPet(PetType.DOG, "Spike", 4), new Person("Jake", "Snake").addPet(PetType.SNAKE, "Serpy", 1), new Person("Barry", "Bird").addPet(PetType.BIRD, "Tweety", 2), new Person("Terry", "Turtle").addPet(PetType.TURTLE, "Speedy", 1), new Person("Harry", "Hamster").addPet(PetType.HAMSTER, "Fuzzy", 1).addPet(PetType.HAMSTER, "Wuzzy", 1) ); }

TECHNOLOGY DIVISION 24 Do any people have cats? boolean result = this.people.stream().anyMatch(person -> person.hasPet(PetType.CAT)); boolean result = this.people.anySatisfy(person -> person.hasPet(PetType.CAT)); boolean resultMethodRef = this.people.anySatisfyWith(Person::hasPet, PetType.CAT); eager boolean result = this.people.asLazy().anySatisfy(person -> person.hasPet(PetType.CAT)); boolean resultMethodRef = this.people.asLazy().anySatisfyWith(Person::hasPet, PetType.CAT); asLazy stream

TECHNOLOGY DIVISION 25 How many people have cats? long result = this.people.stream().filter(person -> person.hasPet(PetType.CAT)).count(); int result = this.people.count(person -> person.hasPet(PetType.CAT)); int resultMethodRef = this.people.countWith(Person::hasPet, PetType.CAT); eager int result = this.people.asLazy().count(person -> person.hasPet(PetType.CAT)); int resultMethodRef = this.people.asLazy().countWith(Person::hasPet, PetType.CAT); asLazy stream

TECHNOLOGY DIVISION 26 How does “count” stack up? eager asLazy stream this.people.stream().filter(person -> person.hasPet(PetType.CAT)).count(); this.people.countWith(Person::hasPet, PetType.CAT); this.people.asLazy().countWith(Person::hasPet, PetType.CAT);

TECHNOLOGY DIVISION 27 Follow the Rabbit Stream count() public final long count() { return mapToLong(e -> 1L).sum(); } public final long sum() { // use better algorithm to compensate for intermediate overflow? return reduce(0, Long::sum); } public final LongStream mapToLong(ToLongFunction mapper) { Objects.requireNonNull(mapper); return new LongPipeline.StatelessOp (this, StreamShape.REFERENCE, StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) Sink opWrapSink(int flags, Sink sink) { return new Sink.ChainedReference (sink) public void accept(P_OUT u) { downstream.accept(mapper.applyAsLong(u)); } }; } }; } public final long reduce(long identity, LongBinaryOperator op) { return evaluate(ReduceOps.makeLong(identity, op)); } final R evaluate(TerminalOp terminalOp) { assert getOutputShape() == terminalOp.inputShape(); if (linkedOrConsumed) throw new IllegalStateException(MSG_STREAM_LINKED); linkedOrConsumed = true; return isParallel() ? terminalOp.evaluateParallel(this, sourceSpliterator(terminalOp.getOpFlags())) : terminalOp.evaluateSequential(this, sourceSpliterator(terminalOp.getOpFlags())); } … …

TECHNOLOGY DIVISION 28 countWith() Eclipse Collections public int countWith(Predicate2 predicate, P parameter) { return InternalArrayIterate.countWith(this.items, this.size, predicate, parameter); } public static int countWith(T[] array, int size, Predicate2 predicate, P parameter) { int count = 0; for (int i = 0; i < size; i++) { if (predicate.accept(array[i], parameter)) { count++; } } return count; }

TECHNOLOGY DIVISION 29 Who has cats? eager asLazy stream MutableList peopleWithCats = this.people.select(person -> person.hasPet(PetType.CAT)); MutableList peopleWithCatsMethodRef = this.people.selectWith(Person::hasPet, PetType.CAT); List peopleWithCats = this.people.stream().filter(person -> person.hasPet(PetType.CAT)).collect(Collectors.toList()); MutableList peopleWithCats = this.people.asLazy().select(person -> person.hasPet(PetType.CAT)).toList(); MutableList peopleWithCatsMethodRef = this.people.asLazy().selectWith(Person::hasPet, PetType.CAT).toList(); // select: descriptive API

TECHNOLOGY DIVISION 30 Who doesn’t have cats? eager asLazy stream MutableList peopleWithoutCats = this.people.reject(person -> person.hasPet(PetType.CAT)); MutableList peopleWithoutCatsMethodRef = this.people.rejectWith(Person::hasPet, PetType.CAT); List peopleWithoutCats = this.people.stream().filter(person -> !person.hasPet(PetType.CAT)).collect(Collectors.toList()); MutableList peopleWithoutCats = this.people.asLazy().reject(person -> person.hasPet(PetType.CAT)).toList(); MutableList peopleWithoutCatsMethodRef = this.people.asLazy().rejectWith(Person::hasPet, PetType.CAT).toList(); // not! // detect: descriptive API

TECHNOLOGY DIVISION 31 Partition people with/without cats eager asLazy stream PartitionMutableList catsAndNoCats = this.people.partition(person -> person.hasPet(PetType.CAT)); Map > catsAndNoCats = this.people.stream().collect( Collectors.partitioningBy(person -> person.hasPet(PetType.CAT))); PartitionMutableList catsAndNoCatsMethodRef = this.people.partitionWith(Person::hasPet, PetType.CAT); PartitionIterable catsAndNoCats = this.people.asLazy().partition(person -> person.hasPet(PetType.CAT)); PartitionIterable catsAndNoCatsMethodRef = this.people.asLazy().partitionWith(Person::hasPet, PetType.CAT); // PartitionIterable supports getSelected() and getRejected()

TECHNOLOGY DIVISION 32 Get the names of Bob’s pets eager stream Person person = this.people.stream().filter(each -> each.named("Bob Smith")).findFirst().get(); Assert.assertEquals("Dolly & Spot", person.getPets().stream().map(Pet::getName).collect(Collectors.joining(" & "))); Person person = this.people.detectWith(Person::named, "Bob Smith"); Assert.assertEquals("Dolly & Spot", person.getPets().collect(Pet::getName).makeString(" & "));

TECHNOLOGY DIVISION 33 Get the set of all pet types eager stream Set allPetTypes = this.people.stream().flatMap(person -> person.getPetTypes().stream()).collect(Collectors.toSet()); asLazy MutableSet allPetTypesTarget = this.people.flatCollect(Person::getPetTypes, Sets.mutable.empty()); MutableSet allPetTypes = this.people.asLazy().flatCollect(Person::getPetTypes).toSet(); MutableSet allPetTypesTarget = this.people.asLazy().flatCollect(Person::getPetTypes, Sets.mutable.empty()); MutableSet allPetTypes = this.people.flatCollect(Person::getPetTypes).toSet(); // copies and iterates twice // Better performance with target collection

TECHNOLOGY DIVISION 34 Group people by their last name eager stream Map > byLastName = this.people.stream().collect( Collectors.groupingBy(Person::getLastName)); Map > byLastNameTargetBag = this.people.stream().collect( Collectors.groupingBy(Person::getLastName, Collectors.toCollection(Bags.mutable::empty))); MutableListMultimap byLastName = this.people.groupBy(Person::getLastName); MutableBagMultimap byLastNameTargetBagMultimap = this.people.groupBy(Person::getLastName, Multimaps.mutable.bag.empty()); // Multimap // Native target collection handling // Interop with Eclipse Collections Bag

TECHNOLOGY DIVISION 35 Get the age statistics of pets asLazy stream List agesList = this.people.stream().flatMap(person -> person.getPets().stream()).map(Pet::getAge).collect(Collectors.toList()); IntSummaryStatistics stats = agesList.stream().collect(Collectors.summarizingInt(i -> i)); Assert.assertEquals(stats.getMin(), agesList.stream().mapToInt(i -> i).min().getAsInt()); Assert.assertEquals(stats.getMax(), agesList.stream().mapToInt(i -> i).max().getAsInt()); Assert.assertEquals(stats.getSum(), agesList.stream().mapToInt(i -> i).sum()); IntList agesList = this.people.asLazy().flatCollect(Person::getPets).collectInt(Pet::getAge).toList(); IntSummaryStatistics stats = new IntSummaryStatistics(); agesList.each(stats::accept); Assert.assertEquals(stats.getMin(), agesList.min()); Assert.assertEquals(stats.getMax(), agesList.max()); Assert.assertEquals(stats.getSum(), agesList.sum()); // Primitive collection type // Native support for statistics APIs // collect method available for all 8 primitive types

TECHNOLOGY DIVISION 36 Counts by pet age asLazy stream ImmutableIntBag counts = this.people.asLazy().flatCollect(Person::getPets).collectInt(Pet::getAge).toBag().toImmutable(); Assert.assertEquals(4, counts.occurrencesOf(1)); Assert.assertEquals(3, counts.occurrencesOf(2)); Assert.assertEquals(0, counts.occurrencesOf(5)); Map counts = Collections.unmodifiableMap( this.people.stream().flatMap(person -> person.getPets().stream()).collect(Collectors.groupingBy(Pet::getAge, Collectors.counting()))); Assert.assertEquals(Long.valueOf(4), counts.get(1)); Assert.assertEquals(Long.valueOf(3), counts.get(2)); Assert.assertNull(counts.get(5)); Verify.assertThrows(UnsupportedOperationException.class, () -> counts.put(5, 0L)); // Immutable type => no mutation APIs available // Unmodifiable => throws at runtime mutation // Bag native support // Bag returns 0 for non-existing occurrence

TECHNOLOGY DIVISION 37 Agenda What is GS Collections? What is Eclipse Collections? JCF and EC Memory Comparisons Hobson’s Choice Method Reference Preference Eclipse Collections Examples To Use or Reuse? More Features

TECHNOLOGY DIVISION 38 Use or Reuse? Streams – like Iterator LazyIterable – Iterable Stream 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. (AbstractPipeline.java:203) at java.util.stream.IntPipeline. (IntPipeline.java:91) at java.util.stream.IntPipeline$StatelessOp. (IntPipeline.java:592) at java.util.stream.ReferencePipeline$4. (ReferencePipeline.java:204) at java.util.stream.ReferencePipeline.mapToInt(ReferencePipeline.java:203) LazyIterable 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

TECHNOLOGY DIVISION 39 Agenda What is GS Collections? What is Eclipse Collections? JCF and EC Memory Comparisons Hobson’s Choice Method Reference Preference Eclipse Collections Examples To Use or Reuse? More Features

TECHNOLOGY DIVISION 40 The “as” methods (O(1) cost) MethodVisible on TypeReturns asLazyRichIterable, {primitive}Iterable LazyIterable, Lazy{primitive}Iterable asUnmodifiableMutable{Collection}, Mutable{primitive}{Collection} asSynchronizedMutable{Collection}, Mutable{primitive}{Collection} asParallelListIterable, SetIterableParallelListIterable, ParallelSetIterable asReversedReversibleIterable, Reversible{primitive}Iterable LazyIterable, Lazy{primitive}Iterable {Collection} = Collection, List, Set, Bag, Map {primitive} = boolean, byte, char, short, int, float, long, double

TECHNOLOGY DIVISION 41 The “to” methods (O(n) cost) MethodAvailable on TypeReturns toImmutable{Collection}Iterable, Mutable{primitive}{Collection} Immutable{Collection}, Immutable{primitive}{Collection} toList, toSortedList (By)RichIterable, {primitive}IterableMutableList, Mutable{primitive}List toSetRichIterable, {primitive}IterableMutableSet, Mutable{primitive}Set toSortedSet (By)RichIterableMutableSortedSet toBagRichIterable, {primitive}IterableMutableBag, Mutable{primitive}Bag toSortedBag (By)RichIterableMutableSortedBag toMapRichIterableMutableMap toSortedMapRichIterableMutableSortedMap toArrayRichIterable, {primitive}IterableObject[], {primitive}[] toReversedReversibleIterable, Reversible{primitive}Iterable {Collection} = Collection, List, Set, Bag, Map {primitive} = boolean, byte, char, short, int, float, long, double

TECHNOLOGY DIVISION 42 ImmutableList eclipseList = Lists.immutable.with("two"); eclipseList.each(Procedures.throwing(appendable::append)); Assert.assertEquals("onetwo", appendable.toString()); Handling Exceptions Appendable appendable = new StringBuilder(); List 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

TECHNOLOGY DIVISION 43 Resources Eclipse Collections Proposal GS Collections on GitHub GS Collections Memory Benchmark JavaOne 2014 – GS Collections and Java 8 Presentation Parallel-lazy Performance: Java 8 vs Scala vs GS Collections Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.

TECHNOLOGY DIVISION 44 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.