![Page 1: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/1.jpg)
TECHNOLOGY DIVISION
0
The Java Evolution of Eclipse CollectionsGS.com/EngineeringQCon NY 2017
Kristen O’Leary
![Page 2: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/2.jpg)
TECHNOLOGY DIVISION
1
Agenda• Intro• What is Eclipse Collections• New features in 8.0• Optional• Collectors• Default methods• Primitive Collections • Java 9• Conclusion
1
![Page 3: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/3.jpg)
TECHNOLOGY DIVISION
2
Kristen O’Leary• Software developer at Goldman Sachs• Contributor to GS/Eclipse Collections
– http://www.goldmansachs.com/what-we-do/engineering/see-our-work/growing-with-gs-collections.html
• EC Kata Instructor and Contributor– https://www.eclipsecon.org/na2016/session/eclipse-collections-kata-
fun-way-learn-feature-rich-collections-framework
• Eclipse Collections Advocate– NY Java SIG 2016, JavaOne 2016, EclipseCon
2016, QCon NY 2014 2
![Page 4: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/4.jpg)
TECHNOLOGY DIVISION
3
Agenda• Intro• What is Eclipse Collections• New features in 8.0• Optional• Collectors• Default methods• Primitive Collections• Java 9 • Conclusion
3
![Page 5: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/5.jpg)
TECHNOLOGY DIVISION
4
What is Eclipse Collections?• Feature rich, memory efficient Java
Collections framework• Open sourced in 2012 as GS Collections• New – 8.0 compatible with JDK 8+• eclipse.org/collections• Eclipse Collections is open for contributions!
– https://github.com/eclipse/eclipse-collections/blob/master/CONTRIBUTING.md
4
![Page 6: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/6.jpg)
TECHNOLOGY DIVISION
5
Agenda• Intro• What is Eclipse Collections• New features in 8.0• Optional• Collectors• Default methods• Primitive Collections • Java 9• Conclusion
5
![Page 7: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/7.jpg)
TECHNOLOGY DIVISION
6
Version 8 for Java 8• Before, EC worked with Java 8• But did not require or embrace it• V 8 changes that. Now:
– If you have JDK 8 code → easy transition to EC
– If you have EC code → easier to use JDK 8 Collections/Streams features
6
![Page 8: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/8.jpg)
TECHNOLOGY DIVISION
7
What’s new in EC 8.0?• EC functional interfaces extend Java 8 functional
interfaces• New interop with Java 8 features directly in API
– reduce, reduceInPlace, summarize, detectOptional and more
• Collectors + Eclipse Collections Types = Collectors2• Default methods = More Features, Less Code• Primitive Collections and Java 8
7
![Page 9: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/9.jpg)
TECHNOLOGY DIVISION
8
Agenda• Intro• What is Eclipse Collections• New features in 8.0• Optional• Collectors• Default methods• Primitive Collections • Java 9• Conclusion
8
![Page 10: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/10.jpg)
TECHNOLOGY DIVISION
9
Our Domain
9
![Page 11: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/11.jpg)
TECHNOLOGY DIVISION
10
Optional• New JDK 8 feature• From the javadoc:
– “A container object which may or may not contain a non-null value. If a value is present, isPresent() will return true and get() will return the value.”
10
![Page 12: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/12.jpg)
TECHNOLOGY DIVISION
11
Where can we use this in EC?• RichIterable “detectWith” is one
example• From the javadoc:
– “Returns the first element that evaluates to true for the specified predicate2 and parameter, or null if none evaluate to true.”
11
![Page 13: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/13.jpg)
TECHNOLOGY DIVISION
12
So what happens?Kata exercise - find Mary Smith
java.lang.NullPointerException
Person person = this.people .detectWith(Person::named, "Mary Smith");
Assert.assertEquals("Mary", person.getFirstName());Assert.assertEquals("Smith", person.getLastName());
12
![Page 14: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/14.jpg)
TECHNOLOGY DIVISION
13
Pre 8.0 – Null checkPerson person = this.people .detectWith(Person::named, "Mary Smith");
if(person == null){ person = new Person("Mary", "Smith");}
Assert.assertEquals("Mary", person.getFirstName());Assert.assertEquals("Smith", person.getLastName());
13
![Page 15: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/15.jpg)
TECHNOLOGY DIVISION
14
Pre 8.0 – detectWithIfNone
Person person = this.people.detectWithIfNone(Person::named, "Mary Smith",() -> new Person("Mary", "Smith"));
Assert.assertEquals("Mary", person.getFirstName());Assert.assertEquals("Smith", person.getLastName());
Find Mary Smith, or create her
14
Test passes!
![Page 16: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/16.jpg)
TECHNOLOGY DIVISION
15
8.0 - OptionalFind Mary Smith, or create her
15
Optional<Person> optional = this.people .detectWithOptional(Person::named, "Mary Smith");
Person person = optional.orElseGet( () -> new Person("Mary", "Smith"));
Assert.assertEquals("Mary", person.getFirstName());Assert.assertEquals("Smith", person.getLastName());
Test passes!
![Page 17: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/17.jpg)
TECHNOLOGY DIVISION
16
Agenda• Intro• What is Eclipse Collections• New features in 8.0• Optional• Collectors• Default methods• Primitive Collections • Java 9• Conclusion
16
![Page 18: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/18.jpg)
TECHNOLOGY DIVISION
17
What is a Collector?• New feature in Java 8• A way to implement a mutable reduction
operation– Accumulating into a collection
• JDK 8 has several “built in” Collectors
17
![Page 19: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/19.jpg)
TECHNOLOGY DIVISION
18
JDK 8 Collector ExamplesList<String> names = this.people.stream()
.map(Person::getFirstName).collect(Collectors.toList());
int total = this.people.stream() .collect(Collectors.summingInt(Person::getNumberOfPets));
// Output: [Bob, Ted, Jake]
// Output: 4
18
![Page 20: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/20.jpg)
TECHNOLOGY DIVISION
19
Eclipse Collections and Collectors• Starting with Eclipse Collections 8.0, we
can leverage Collectors• Also has some “built in” – Collectors2
19
![Page 21: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/21.jpg)
TECHNOLOGY DIVISION
20
Collectors2 ExamplesMutableBag<Pet> bag = this.people.stream() .map(Person::getPets).flatMap(List::stream) .collect(Collectors2.toBag());
ImmutableSet<Person> catPeople = this.people.stream() .filter(person -> person.hasPet(PetType.CAT)) .collect(Collectors2.toImmutableSet());
// Bag Contents: Dog → 2Cat → 1Snake → 1
// Set Contents: Bob
20
![Page 22: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/22.jpg)
TECHNOLOGY DIVISION
21
Collectors2
Primitive Collections
MultimapsMost types
MutableList<Pair<T,U>>MutableList<ObjectIntPair<T>>
R extends Collection<T>
Misc
• toImmutableList• toSet• toSortedSet• toBiMap• toImmutableBag• toStack
• collect• select• selectWith• reject
• groupBy• toListMultimap• toImmutableBagMultimap
• sumToLong• sumToDouble• collectBoolean• collectLong
• chunk• partition• makeString
• zip• zipWithIndex
Collectors2
21
![Page 23: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/23.jpg)
TECHNOLOGY DIVISION
22
Interop w/Collectors & Collectors2
22
Map<Integer, String> people = this.people .stream() .collect(Collectors.groupingBy( Person::getNumberOfPets, Collectors2.makeString()));
Map<Integer, String> collect = this.people .stream() .collect(Collectors.groupingBy( Person::getNumberOfPets, Collectors.mapping( Object::toString, Collectors.joining(","))));
// Output:{1=Ted, Jake, 2=Bob}
![Page 24: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/24.jpg)
TECHNOLOGY DIVISION
23
Agenda• Intro• What is Eclipse Collections• New features in 8.0• Optional• Collectors• Default methods• Primitive Collections • Java 9• Conclusion
23
![Page 25: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/25.jpg)
TECHNOLOGY DIVISION
24
RichIterable.reduceInPlace
24
/** * This method produces the equivalent result as {@link Stream#collect(Collector)}. * * @since 8.0 */default <R, A> R reduceInPlace(Collector<? super T, A, R> collector){ A mutableResult = collector.supplier().get(); BiConsumer<A, ? super T> accumulator = collector.accumulator(); this.each(each -> accumulator.accept(mutableResult, each)); return collector.finisher().apply(mutableResult);}
![Page 26: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/26.jpg)
TECHNOLOGY DIVISION
25
Example
//using Eclipse Collections and CollectorsImmutableSet<Person> peopleReduce = this.people .selectWith(Person::hasPet, PetType.DOG) .reduceInPlace(Collectors2.toImmutableSet());
// Set Contents: [Bob, Ted]
25
//using Java 8 and Collectors2ImmutableSet<Person> people = this.people .stream() .filter(person -> person.hasPet(PetType.DOG)) .collect(Collectors2.toImmutableSet());
![Page 27: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/27.jpg)
TECHNOLOGY DIVISION
26
Lazy and immutable APIthis.people.toImmutable().stream()
this.people.asLazy().stream()
Set<Person> peopleReduced = this.people .asLazy() // stream() is no longer available .selectWith(Person::hasPet, PetType.DOG) .reduceInPlace(Collectors.toSet());
26
![Page 28: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/28.jpg)
TECHNOLOGY DIVISION
27
Agenda• Intro• What is Eclipse Collections• New features in 8.0• Optional• Collectors• Default methods• Primitive Collections • Java 9• Conclusion
27
![Page 29: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/29.jpg)
TECHNOLOGY DIVISION
28
Primitive Collections• Primitive Collections since GS Collections 3.0.• Memory Optimized Collections for primitive types.• Similar Interface hierarchy to the Object collections.• Symmetry among the primitive types.
28
![Page 30: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/30.jpg)
TECHNOLOGY DIVISION
29
How much should an int cost?
29
![Page 31: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/31.jpg)
TECHNOLOGY DIVISION
30
List<Integer> vs. IntList• Java has object and primitive arrays
– Primitive arrays have no behaviors• Java does not have primitive Lists, Sets or
Maps– Primitives must be boxed– Boxing is expensive
• Reference + Header + alignment
30
![Page 32: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/32.jpg)
TECHNOLOGY DIVISION
31
Primitive vs. JDK CollectionsType Eclipse Collections JDK Collections
Primitive List Yes Boxed
Primitive Set Yes Boxed
Primitive Map Yes Boxed
Primitive Stack Yes Boxed
Primitive Bag Yes Map and Boxed
Primitive Lazy / Stream Yes (all 8 primitives) Int, Long, Double only
31
![Page 33: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/33.jpg)
TECHNOLOGY DIVISION
32
IntStream vs. LazyIntIterable• Java has only 3 primitive stream: Int,
Long, Double– IntStream.of vs. Stream.of for creation.– Specialized lambda expressions– Interchangable between Primitive and Obj
stream
32
![Page 34: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/34.jpg)
TECHNOLOGY DIVISION
33
IntStream vs. LazyIntIterable cont.• LazyIterable for all 8 primitive types.
– AsLazy API for creation– Rich APIs both similar to object and type
specific.– Specialized functional interfacesThese functional interfaces now can be used in Java 8 streams too!– Reusability
33
![Page 35: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/35.jpg)
TECHNOLOGY DIVISION
34
Use or Reuse?• Streams – like Iterator
• LazyIterable – Iterable
IntStream stream = IntStream.of(1, 2, 3);Assert.assertEquals(1, stream.min().getAsInt());Assert.assertEquals(3, stream.max().getAsInt());
java.lang.IllegalStateException: stream has already been operated upon or closedat java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:229)at java.util.stream.IntPipeline.reduce(IntPipeline.java:461)at java.util.stream.IntPipeline.max(IntPipeline.java:424))
LazyIntIterable lazy = IntArrayList.newListWith(1, 2, 3).asLazy();Assert.assertEquals(1, lazy.min());Assert.assertEquals(3, lazy.max());
// throws IllegalStateException
// reuse!
34
![Page 36: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/36.jpg)
TECHNOLOGY DIVISION
35
MutableIntBag counts = this.people.asLazy() .flatCollect(Person::getPets) .collectInt(Pet::getAge) .toBag() .selectByOccurrences(IntPredicates.equal(1));
Filter Pet Ages Appearing Onceas
Lazy
stre
am
// Output: [3, 4]
35
List<Map.Entry<Integer, Long>> counts = this.people.stream() .flatMap(person -> person.getPets().stream()) .collect(Collectors.groupingBy(Pet::getAge, Collectors.counting())) .entrySet() .stream() .filter(e -> e.getValue().equals(Long.valueOf(1))) .collect(Collectors.toList()); // Output:
[3=1, 4=1]
![Page 37: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/37.jpg)
TECHNOLOGY DIVISION
36
List<Map.Entry<Integer, Long>> topOccurrenceList = this.people.stream() .flatMap(person -> person.getPets().stream()) .collect(Collectors.groupingBy(Pet::getAge, Collectors.counting())) .entrySet() .stream() .sorted(Map.Entry.<Integer, Long>comparingByValue().reversed()) .limit(1) .collect(Collectors.toList());
Find the Mode of Pet Ageas
Lazy
stre
am
MutableList<IntIntPair> topOccurrences = this.people.asLazy() .flatCollect(Person::getPets) .collectInt(Pet::getAge) .toBag() .topOccurrences(1);
// Output: [2=2]
// Output: [2:2] 36
![Page 38: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/38.jpg)
TECHNOLOGY DIVISION
37
List<Map.Entry<Integer, Long>> bottomOccurrenceList = this.people.stream() .flatMap(person -> person.getPets().stream()) .collect(Collectors.groupingBy(Pet::getAge, Collectors.counting())) .entrySet() .stream() .sorted(Map.Entry.<Integer, Long>comparingByValue()) .limit(1) .collect(Collectors.toList());
Find the Least Frequent Pet Ageas
Lazy
stre
am
MutableList<IntIntPair> bottomOccurrences = this.people.asLazy() .flatCollect(Person::getPets) .collectInt(Pet::getAge) .toBag() .bottomOccurrences(1);
// Output: [3:1] 37
// Output: [3=1]
![Page 39: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/39.jpg)
TECHNOLOGY DIVISION
38
Agenda• Intro• What is Eclipse Collections• New features in 8.0• Optional• Collectors• Default methods• Primitive Collections• Java 9 • Conclusion
38
![Page 40: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/40.jpg)
TECHNOLOGY DIVISION
39
What’s next?• Java 9 will introduce many interesting
changes to the Java ecosystem– Module System– Internal API Encapsulation
• Eclipse Collections must change in order to be compatible
39
![Page 41: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/41.jpg)
TECHNOLOGY DIVISION
40
Methods using reflection• We need to change our methods that
use reflection to build
40
![Page 42: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/42.jpg)
TECHNOLOGY DIVISION
41
What happens?• Compile, run tests, deprecate• Demo
41
![Page 43: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/43.jpg)
TECHNOLOGY DIVISION
42
ArrayListIterate
42
public final class ArrayListIterate{ private static final Field ELEMENT_DATA_FIELD; private static final Field SIZE_FIELD; private static final int MIN_DIRECT_ARRAY_ACCESS_SIZE = 100;
static { Field data = null; Field size = null; try { data = ArrayList.class.getDeclaredField("elementData"); size = ArrayList.class.getDeclaredField("size"); data.setAccessible(true); size.setAccessible(true); } catch (Exception ignored) { data = null; size = null; } ELEMENT_DATA_FIELD = data; SIZE_FIELD = size; }
![Page 44: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/44.jpg)
TECHNOLOGY DIVISION
43
Workarounds for reflection• http://mail.openjdk.java.net/pipermail/jig
saw-dev/2017-March/011763.html• Can avoid via command line arguments• EC proactively solved the problem
43
![Page 45: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/45.jpg)
TECHNOLOGY DIVISION
44
Agenda• Intro• What is Eclipse Collections• New features in 8.0• Optional• Collectors• Default methods• Primitive Collections• Java 9 • Conclusion
44
![Page 46: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/46.jpg)
TECHNOLOGY DIVISION
45
Resources• Eclipse Collections 8.2 release https://github.com/eclipse/eclipse-collections/releases/tag/8.2.0
• Collectors Fair: Developing and Marketing a New Kind of Componenthttps://static.rainfocus.com/oracle/oow16/sess/1462848741026001JnVD/ppt/CollectorsFair_J1_2016_final.pdf
• GS Collections Memory Benchmarkhttp://www.goldmansachs.com/gs-collections/presentations/GSC_Memory_Tests.pdf
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
45
![Page 47: GS.com/Engineering Collections QCon NY 2017 Kristen O’Leary · TECHNOLOGY DIVISION 1 Agenda • Intro • What is Eclipse Collections • New features in 8.0 • Optional • Collectors](https://reader035.vdocuments.net/reader035/viewer/2022071016/5fcf38b59fd7e912932050b3/html5/thumbnails/47.jpg)
TECHNOLOGY DIVISION
46
Learn more at GS.com/Engineering
© 2016 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.