XKE - Google Guava

1,548 views
1,416 views

Published on

Google Guava overview.
Given at Xebia during XKE (March 3rd, 2011).

Published in: Technology, Business
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,548
On SlideShare
0
From Embeds
0
Number of Embeds
24
Actions
Shares
0
Downloads
5
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

XKE - Google Guava

  1. 1. Introduction to Google Guava Romain MATON Google Guava XKE Avril 2011 www.xebia.fr / blog.xebia.fr 1
  2. 2. What is Google Guava ?  An API, now in r08  com.google.common.annotations  com.google.common.base  com.google.common.collect  com.google.common.io  com.google.common.net  com.google.common.primitives  com.google.common.util.concurrent www.xebia.fr / blog.xebia.fr 2
  3. 3. What is Google Guava ?  An API, now in r08  com.google.common.annotations  com.google.common.base  com.google.common.collect  com.google.common.io  com.google.common.net  com.google.common.primitives  com.google.common.util.concurrent www.xebia.fr / blog.xebia.fr 3
  4. 4. And in base and collect ?  Objects  Strings, Ints  Charsets  Preconditions  Joiner, Splitter  Lists, Sets  ListMultiMap  Iterables  Functions  Predicates  Ordering  Example www.xebia.fr / blog.xebia.fr 4
  5. 5. Base : Objects www.xebia.fr / blog.xebia.fr 5
  6. 6. Base : Objects www.xebia.fr / blog.xebia.fr 6
  7. 7. Base : Strings www.xebia.fr / blog.xebia.fr 7
  8. 8. Primitives : Ints www.xebia.fr / blog.xebia.fr 8
  9. 9. Base : Charsets www.xebia.fr / blog.xebia.fr 9
  10. 10. Base : Preconditions // Will throw NPE Preconditions.checkNotNull(lisa.getId()); // Will throw ILE Preconditions.checkState(!lisa.isSick()); // Will throw ILE Preconditions.checkArgument(lisa.getAddress() != null, "No description for customer with id %s",lisa.getId()); www.xebia.fr / blog.xebia.fr 10
  11. 11. Base : Joiner www.xebia.fr / blog.xebia.fr 11
  12. 12. Base : Splitter www.xebia.fr / blog.xebia.fr 12
  13. 13. Question ? ",a,,b,".split(",") returns... (a) "", "a", "", "b", "" (b) null, "a", null, "b", null (c) "a", null, "b" (d) "a", "b" (e) None of the above www.xebia.fr / blog.xebia.fr 13
  14. 14. Answer ! ",a,,b,".split(",") returns... (a) "", "a", "", "b", "" (b) null, "a", null, "b", null (c) "a", null, "b" (d) "a", "b" (e) None of the above "", "a", "", "b" www.xebia.fr / blog.xebia.fr 14
  15. 15. Puzzler www.xebia.fr / blog.xebia.fr 15
  16. 16. Base : Splitter www.xebia.fr / blog.xebia.fr 16
  17. 17. Collect : Iterables  cycle(iterable)  concat(Iterable... inputs)  any(iterable, predicate)  all(iterable, predicate)  filter(iterable, predicate)  find(iterable, predicate)  transform(iterable, function)  frequency(iterable, element)  get(iterable, index, default)  ... www.xebia.fr / blog.xebia.fr 17
  18. 18. Collect : Iterables www.xebia.fr / blog.xebia.fr 18
  19. 19. Collect : Iterables www.xebia.fr / blog.xebia.fr 19
  20. 20. Collect : Lists  asList(E, E[])  newArrayList()  newArrayList(E...)  newLinkedList()  newLinkedList(iterable)  partition(iterable, predicate)  transform(iterable, predicate)  ... www.xebia.fr / blog.xebia.fr 20
  21. 21. Collect : Lists www.xebia.fr / blog.xebia.fr 21
  22. 22. Collect : Sets www.xebia.fr / blog.xebia.fr 22
  23. 23. Collect : ListMultiMap www.xebia.fr / blog.xebia.fr 23
  24. 24. Base : Functions  compose(Function<B, C>, Function<A, B>) => Function<A, C>  constant(E)  forPredicate(predicate<T>) => Function<T, Boolean>  identity  toStringFunction www.xebia.fr / blog.xebia.fr 24
  25. 25. Base : Predicates  alwaysTrue()  alwaysFalse()  contains(pattern)  in(collection)  isNull()  notNull()  not(predicate)  and(...)  or(...) www.xebia.fr / blog.xebia.fr 25
  26. 26. Base : Predicates www.xebia.fr / blog.xebia.fr 26
  27. 27. Collect : Ordering  sortedCopy(iterable)  onResultOf(function)  nullsFirst()  nullsLast()  usingToString()  natural()  from(comparator)  isOrdered(iterable)  compare(a, b) www.xebia.fr / blog.xebia.fr 27
  28. 28. Collect : Ordering www.xebia.fr / blog.xebia.fr 28
  29. 29. Last example www.xebia.fr / blog.xebia.fr 29
  30. 30. Last example www.xebia.fr / blog.xebia.fr 30

×