Palestra collection google

861 views

Published on

Apresentação sobre google collection

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
861
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
12
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Palestra collection google

  1. 1. Wende Mendes HiginoWende Mendes Higino email: wende.mendes@bluesoft.com.bremail: wende.mendes@bluesoft.com.br Google CollectionsGoogle Collections
  2. 2. ObjetivoObjetivo
  3. 3. Google CollectionsGoogle Collections - List- List - Set- Set - Map- Map - Multimap- Multimap - Multiset- Multiset
  4. 4. Google CollectionsGoogle Collections ListList
  5. 5. Google CollectionsGoogle Collections Antes: final List<String> dias = new ArrayList<String>(); dias.add("Segunda"); dias.add("Terça"); Agora: final List<String> dias = Lists.newArrayList("Segunda", "Terça");
  6. 6. Google CollectionsGoogle Collections MapMap
  7. 7. Google CollectionsGoogle Collections Antes: final Map<Integer, Fornecedor> fornecedores = new HashMap<Integer, Fornecedor>(); fornecedores.put(1, new Fornecedor(1, "Bolha Peixes")); fornecedores.put(2, new Fornecedor(1, "Lui Bebidas")); Agora: final Map<Integer, Fornecedor> fornecedoresGoogle = Maps.newHashMap(); fornecedoresGoogle.put(1, new Fornecedor(1, "Bolha Peixes")); fornecedoresGoogle.put(2, new Fornecedor(1, "Lui Bebidas"));
  8. 8. Google CollectionsGoogle Collections Antes: Map<Integer, String> imutableMapAntigo; final Map<Integer, String> mapAntigo = new HashMap<Integer, String>(); mapAntigo.put(1, "Bolha"); mapAntigo.put(2, "Wende"); imutableMapAntigo = Collections.unmodifiableMap(mapAntigo); Agora: ImmutableMap<Integer, String> immutableMap = ImmutableMap.of(1, "Bolha", 2, "Wende");
  9. 9. Google CollectionsGoogle Collections Set
  10. 10. Google CollectionsGoogle Collections - HashSet; - LinkedHashSet; - TreeSet; - ImmutableSet
  11. 11. Google CollectionsGoogle Collections Antes: final Set<String> dias = new HashSet<String>(); dias.add("Segunda"); dias.add("Terça"); Ou: final Set<String> dias = new HashSet<String>(Arrays.asList("Segunda", "Terça"); Agora: final Set<String> dias = Sets.newHashSet("Segunda", "Terça"); Console: Terça, Segunda ou Segunda, Terça
  12. 12. Google CollectionsGoogle Collections Antes: final Set<String> dias = new LinkedHashSet<String>(); dias.add("Segunda"); dias.add("Terça"); dias.add("Quarta"); Agora: final Set<String> dias = Sets.newLinkedHashSet(); dias.add("Segunda"); dias.add("Terça"); dias.add("Quarta"); Console: Segunda, Terça, Quarta
  13. 13. Google CollectionsGoogle Collections Antes: final Set<String> dias = new TreeSet<String>(); dias.add("Segunda"); dias.add("Terça"); dias.add("Quarta"); Agora: final Set<String> dias = Sets.newTreeSet(); dias.add("Segunda"); dias.add("Terça"); dias.add("Quarta"); Console: Quarta, Segunda, Terça
  14. 14. Google CollectionsGoogle Collections Antes: Set<String> setAntigo = new HashSet<String>(); setAntigo.add("Bolha"); setAntigo.add("Wende"); Collection<String> imutableSetAntigo = Collections.unmodifiableCollection(setAntigo); Agora: ImmutableSet<String> immutableSet = ImmutableSet.of("Lui", "Bolha");
  15. 15. Google CollectionsGoogle Collections MultimapsMultimaps
  16. 16. Google CollectionsGoogle Collections Antes: final Map<Integer, List<Fornecedor>> map = new HashMap<Integer, List<Fornecedor>>(); public void popular(final Integer fornecedorKey, final Fornecedor fornecedor) { List<Fornecedor> fornecedores = map.get(fornecedorKey); if (fornecedores == null) { fornecedores = new ArrayList<Fornecedor>(); map.put(fornecedorKey, fornecedores); } fornecedores.add(fornecedor); }
  17. 17. Google CollectionsGoogle Collections Agora: - ArrayListMultimap; - LinkedListMultimap; - TreeMultimap; - HashMultimap; - LinkedHashMultimap; - ImmutableListMultimap - ImmutableSetMultimap
  18. 18. Google CollectionsGoogle Collections Agora: final Multimap<Integer, Fornecedor> multimap = ArrayListMultimap.create(); public void popular(final Integer fornecedorKey, final Fornecedor fornecedor) { multimap.put(fornecedorKey, fornecedor); }
  19. 19. Google CollectionsGoogle Collections final Multimap<Integer, Fornecedor> multimap = ArrayListMultimap.create(); multimap.put(1, "Lui"); multimap.put(2, "Wende"); multimap.put(2, "Wende"); multimap.put(2, "Wende"); multimap.put(1, "Andre"); multimap.put(2, "Bolha"); Console: 1 = {Lui, André} 2 = {Wende, Wende, Wende, Bolha}
  20. 20. Google CollectionsGoogle Collections final Multimap<Integer, String> multimap = HashMultimap.create(); multimap.put(1, "Lui"); multimap.put(2, "Bolha"); multimap.put(2, "Wende"); multimap.put(2, "Wende"); multimap.put(2, "Wende"); multimap.put(1, "Andre"); Console: 1 = {André, Lui} 2 = {Wende, Bolha}
  21. 21. Google CollectionsGoogle Collections final Multimap<Integer, String> multimap = LinkedHashMultimap.create(); multimap.put(1, "Lui"); multimap.put(2, "Bolha"); multimap.put(2, "Wende"); multimap.put(2, "Wende"); multimap.put(2, "Wende"); multimap.put(1, "Andre"); Console: 1 = {Lui, André} 2 = {Bolha, Wende}
  22. 22. Google CollectionsGoogle Collections final Multimap<Integer, String> multimap = TreeMultimap.create(); multimap.put(1, "Lui"); multimap.put(2, "Bolha"); multimap.put(2, "Wende"); multimap.put(2, "Wende"); multimap.put(2, "Wende"); multimap.put(1, "Andre"); Console: 1 = {André, Lui} 2 = {Bolha, Wende}
  23. 23. Google CollectionsGoogle Collections Agora: Multimap<Integer, String> multimap = ImmutableListMultimap.of(1, "Lui", 2, "Wende", 1, "China", 1, "Lui"); Console: 1 = { Lui, China, Lui } 2 = { Wende }
  24. 24. Google CollectionsGoogle Collections Agora: Multimap<Integer, String> multimap = ImmutableSetMultimap.of(1, "Lui", 2, "Wende", 1, "China", 1, "Lui"); Console: 1 = { Lui, China} 2 = { Wende }
  25. 25. Google CollectionsGoogle Collections MultisetsMultisets
  26. 26. Google CollectionsGoogle Collections - HashMultiset - LinkedHashMultiset - TreeMultiset - EnumMultiset
  27. 27. Google CollectionsGoogle CollectionsAgora: Multiset<String> nomes = HashMultiset.create(); nomes.add("Wende"); nomes.add("China", 3); nomes.add("Bolha");
  28. 28. Google CollectionsGoogle Collections for (final String nome : nomes) { System.out.println(nome); } O que será impresso ???
  29. 29. Google CollectionsGoogle Collections Console: Wende, Bolha, China, China, China
  30. 30. Google CollectionsGoogle Collections System.out.println(nomes.elementSet()); Console: Wende, Bolha, China System.out.println(nomes.count("China")); Console: 3 System.out.println(nomes.size()); Console: 5
  31. 31. Google CollectionsGoogle Collections enum Fornecedor { BolhaPeixes, DouglasCafe } final EnumMultiset<Fornecedor> fornecedores = EnumMultiset.create(Fornecedor.class); fornecedores.add(Fornecedor.BolhaPeixes); fornecedores.add(Fornecedor.BolhaPeixes); fornecedores.add(Fornecedor.BolhaPeixes); fornecedores.add(Fornecedor.DouglasCafe); System.out.println(fornecedores.elementSet()); Console: BolhaPeixes, DouglasCafe
  32. 32. Google CollectionsGoogle Collections Também tenho estas opções: final Multiset<String> nomes = LinkedHashMultiset.create(); final Multiset<String> nomes = TreeMultiset.create();
  33. 33. ImagensImagens http://www.flickr.com/photos/dannysullivan/272645770/ http://www.flickr.com/photos/northbaywanderer/121971249/ http://www.fl ickr.com/photos/colm/551068416/ http://www.fl ickr.com/photos/vermininc/2335148856/ http://www.fl ickr.com/photos/caveman_92223/3185534518/ http://www.fl ickr.com/photos/fdecomite/2908653728/

×