Google Guava Margus Martsepp History Java collections was

  • Slides: 13
Download presentation
Google Guava Margus Martsepp

Google Guava Margus Martsepp

History Java collections was created in 1997 3 big ideas: interfaces (define collections) implementations

History Java collections was created in 1997 3 big ideas: interfaces (define collections) implementations (concrete or abstract) algorithms (to manipulate collections) • • • Basic idea around this framework: Extensible - people can build on it

Overview 1. Utilities - {static constructors, functional {predicates, transform}} 2. Objects {equal, coalesce, Comparison.

Overview 1. Utilities - {static constructors, functional {predicates, transform}} 2. Objects {equal, coalesce, Comparison. Chain} 3. Immutable - {why, how, collections}

Utilities - static constructors Create a list of 2 elements

Utilities - static constructors Create a list of 2 elements

Utilities - functional - predicates Apply predicates on collections/iterables Functional language equivalent

Utilities - functional - predicates Apply predicates on collections/iterables Functional language equivalent

Utilities - functional - transform Create a transformed view of a collection

Utilities - functional - transform Create a transformed view of a collection

Object - {equals, coalesce} Equals (null safe) Coalesce Objects. first. Non. Null(obj, default)

Object - {equals, coalesce} Equals (null safe) Coalesce Objects. first. Non. Null(obj, default)

Object - Comparison. Chain Compare. To method:

Object - Comparison. Chain Compare. To method:

Immutable - why Why? + Your life is easy (no trust problems) + Free

Immutable - why Why? + Your life is easy (no trust problems) + Free thread safety + Can be used as a constant + Uses less memory - Rejects null values Compared to Collections. unmodifiable? - overhead - unsafe • •

Immutable - how Create a set of elements Immutable. Set. of("a", "b", "c", "a",

Immutable - how Create a set of elements Immutable. Set. of("a", "b", "c", "a", "d", "b") Using a builder public static final Immutable. Set<Color> GOOGLE_COLORS = Immutable. Set. <Color>builder(). add. All(WEBSAFE_COLORS). add(new Color(0, 191, 255)). build(); Creating a defencive copy Immutable. List. copy. Of(collection);

Immutable - collections JDK Immutable. Collection Immutable. List Immutable. Set Immutable. Sorted. Set Immutable.

Immutable - collections JDK Immutable. Collection Immutable. List Immutable. Set Immutable. Sorted. Set Immutable. Map Immutable. Sorted. Map Guava Immutable. Multiset Immutable. Sorted. Multiset Immutable. Multimap Immutable. List. Multimap Immutable. Set. Multimap Immutable. Bi. Map Immutable. Class. To. Instance. Map Immutable. Table

Summary I talked about: 1. Utilities - {static constructors, functional {predicates, transform}} 2. Objects

Summary I talked about: 1. Utilities - {static constructors, functional {predicates, transform}} 2. Objects {equal, coalesce, Comparison. Chain} 3. Immutable - {why, how, collections}

The end

The end