SlideShare a Scribd company logo
1 of 10
Download to read offline
make your code easier and faster
New data structures 
● Multimap: one key - several values 
○ HashMultimap - does not allow duplicating key-value pairs 
○ LinkedListMultimap - traversal in order of adding 
○ TreeMultimap - sorted Multimap
Multimap before 
1. Map<Employee, List<Role>> map = new HashMap<Employee, List<Role>>(); 
2. public void grant(Employee employee, Role role) { 
3. List<Role> roles = map.get(employee); 
4. if (roles == null) { 
5. roles = new ArrayList<Role>(); 
6. map.put(employee, roles); 
7. } 
8. roles.add(role); 
9. }
Multimap after 
1. Multimap<Employee, Role> multimap = ArrayListMultimap.create(); 
2. public void grant(Employee employee, Role role) { 
3. multimap.put(employee, role); 
4. }
BiMap 
● Bidirectional map - values can be used as keys. 
1. BiMap<String, Integer> bimap = HashBiMap.create(); 
2. bimap.put("ONE", 1); 
3. bimap.put("TWO", 2); 
4. BiMap<Integer, String> inversed = bimap.inverse();
Multiset 
● allows adding duplicates 
● stores the number of duplicates 
● HashMultiset, LinkedHashMultiset, TreeMultiset, ConcurrentHashMultiset 
1. Multiset<String> tags = HashMultiset.create(); 
2. for (BlogPost post : getAllBlogPosts()) { 
3. tags.addAll(post.getTags()); 
4. } 
5. tags.elementSet(); 
6. tags.count("habr");
Immutable collections 
● ImmutableList, ImmutableSet, ImmutableMap etc. 
ImmutableSet<Integer> LUCKY_NUMBERS = 
ImmutableSet.of(4, 8, 15, 16, 23, 42); 
ImmutableMap<Integer, String> numberNames = 
ImmutableMap.of(1, "ONE", 2, "TWO", 3, "THREE"); 
//max 5 elements by .of
ImmutableMap builder 
1. Map<Integer, String> numberNamesExtended = 
2. ImmutableMap.<Integer, String>builder()() 
3. .putAll(numberNames) 
4. .put(5, "FIVE") 
5. .put(6, "SIX") 
6. .build();
Utils 
● Lists, Sets, Map, Strings 
● Iterables, FluentIterable, Optional 
● Predicate, Function 
● Ordering, Range 
Lets practice
Articles 
● http://docs.guava-libraries.googlecode. 
com/git/javadoc/index.html?overview-summary.html 
● http://java.dzone.com/articles/google-guava-cleaner-code 
● http://habrahabr.ru/post/91215

More Related Content

More from Alice Zabolotnaya

More from Alice Zabolotnaya (20)

Жизненный цикл проекта и взаимоотношения с разработчиками (Д. Зносков, 7.07.16)
Жизненный цикл проекта и взаимоотношения с разработчиками (Д. Зносков, 7.07.16)Жизненный цикл проекта и взаимоотношения с разработчиками (Д. Зносков, 7.07.16)
Жизненный цикл проекта и взаимоотношения с разработчиками (Д. Зносков, 7.07.16)
 
IT career advice or how to get your first job in IT
IT career advice or how to get your first job in ITIT career advice or how to get your first job in IT
IT career advice or how to get your first job in IT
 
IT industry. Ciklum. You
IT industry. Ciklum. You IT industry. Ciklum. You
IT industry. Ciklum. You
 
Getting job in IT: Technical Interview
Getting job in IT: Technical InterviewGetting job in IT: Technical Interview
Getting job in IT: Technical Interview
 
Getting job in IT: Special features
Getting job in IT: Special featuresGetting job in IT: Special features
Getting job in IT: Special features
 
HR interview
HR interviewHR interview
HR interview
 
You are on board: drive your routine
You are on board: drive your routineYou are on board: drive your routine
You are on board: drive your routine
 
Map of IT: Professions and trends (2015oct)
Map of IT: Professions and trends (2015oct)Map of IT: Professions and trends (2015oct)
Map of IT: Professions and trends (2015oct)
 
How to-day-say (HOW TO MAKE YOUR UNIVERSITY PROGRAM MORE IT-ISH)
How to-day-say (HOW TO MAKE YOUR UNIVERSITY PROGRAM MORE IT-ISH)How to-day-say (HOW TO MAKE YOUR UNIVERSITY PROGRAM MORE IT-ISH)
How to-day-say (HOW TO MAKE YOUR UNIVERSITY PROGRAM MORE IT-ISH)
 
How to-day-yay (HOW TO DIVE INTO THE WORLD OF MOBILE DEVELOPMENT)
How to-day-yay (HOW TO DIVE INTO THE WORLD OF MOBILE DEVELOPMENT)How to-day-yay (HOW TO DIVE INTO THE WORLD OF MOBILE DEVELOPMENT)
How to-day-yay (HOW TO DIVE INTO THE WORLD OF MOBILE DEVELOPMENT)
 
How to-day-bfi (HOW TO SUCCEED WORKING IN AN INTERNATIONAL ENVIRONMENT)
How to-day-bfi (HOW TO SUCCEED WORKING IN AN INTERNATIONAL ENVIRONMENT)How to-day-bfi (HOW TO SUCCEED WORKING IN AN INTERNATIONAL ENVIRONMENT)
How to-day-bfi (HOW TO SUCCEED WORKING IN AN INTERNATIONAL ENVIRONMENT)
 
How to-day ciklum-sye (WHAT IS CIKLUM )
How to-day ciklum-sye (WHAT IS CIKLUM )How to-day ciklum-sye (WHAT IS CIKLUM )
How to-day ciklum-sye (WHAT IS CIKLUM )
 
How to-day ciklum - elpo (HOW TO GET YOUR FIRST JOB IN IT)
How to-day ciklum - elpo (HOW TO GET YOUR FIRST JOB IN IT)How to-day ciklum - elpo (HOW TO GET YOUR FIRST JOB IN IT)
How to-day ciklum - elpo (HOW TO GET YOUR FIRST JOB IN IT)
 
Your supercool combo to get your first job in it
Your supercool combo to get your first job in it Your supercool combo to get your first job in it
Your supercool combo to get your first job in it
 
Internship programs; Code WW experience, Elena Avramenko
Internship programs; Code WW experience, Elena AvramenkoInternship programs; Code WW experience, Elena Avramenko
Internship programs; Code WW experience, Elena Avramenko
 
Simple rules of making a CV, Nadezhda Steblivets
Simple rules of making a CV, Nadezhda SteblivetsSimple rules of making a CV, Nadezhda Steblivets
Simple rules of making a CV, Nadezhda Steblivets
 
Map of IT : professions_and_trends, Maxym Mykhalchuk
Map of IT : professions_and_trends, Maxym MykhalchukMap of IT : professions_and_trends, Maxym Mykhalchuk
Map of IT : professions_and_trends, Maxym Mykhalchuk
 
Trends of IT labour market development: Ukraine in global context, Svetlana Y...
Trends of IT labour market development: Ukraine in global context, Svetlana Y...Trends of IT labour market development: Ukraine in global context, Svetlana Y...
Trends of IT labour market development: Ukraine in global context, Svetlana Y...
 
It career guidance by Maxym Mykhalchuk
It career guidance by Maxym MykhalchukIt career guidance by Maxym Mykhalchuk
It career guidance by Maxym Mykhalchuk
 
Sabina Krupko, Nadiia Steblivets
Sabina Krupko, Nadiia SteblivetsSabina Krupko, Nadiia Steblivets
Sabina Krupko, Nadiia Steblivets
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Recently uploaded (20)

DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

Google Guava

  • 1. make your code easier and faster
  • 2. New data structures ● Multimap: one key - several values ○ HashMultimap - does not allow duplicating key-value pairs ○ LinkedListMultimap - traversal in order of adding ○ TreeMultimap - sorted Multimap
  • 3. Multimap before 1. Map<Employee, List<Role>> map = new HashMap<Employee, List<Role>>(); 2. public void grant(Employee employee, Role role) { 3. List<Role> roles = map.get(employee); 4. if (roles == null) { 5. roles = new ArrayList<Role>(); 6. map.put(employee, roles); 7. } 8. roles.add(role); 9. }
  • 4. Multimap after 1. Multimap<Employee, Role> multimap = ArrayListMultimap.create(); 2. public void grant(Employee employee, Role role) { 3. multimap.put(employee, role); 4. }
  • 5. BiMap ● Bidirectional map - values can be used as keys. 1. BiMap<String, Integer> bimap = HashBiMap.create(); 2. bimap.put("ONE", 1); 3. bimap.put("TWO", 2); 4. BiMap<Integer, String> inversed = bimap.inverse();
  • 6. Multiset ● allows adding duplicates ● stores the number of duplicates ● HashMultiset, LinkedHashMultiset, TreeMultiset, ConcurrentHashMultiset 1. Multiset<String> tags = HashMultiset.create(); 2. for (BlogPost post : getAllBlogPosts()) { 3. tags.addAll(post.getTags()); 4. } 5. tags.elementSet(); 6. tags.count("habr");
  • 7. Immutable collections ● ImmutableList, ImmutableSet, ImmutableMap etc. ImmutableSet<Integer> LUCKY_NUMBERS = ImmutableSet.of(4, 8, 15, 16, 23, 42); ImmutableMap<Integer, String> numberNames = ImmutableMap.of(1, "ONE", 2, "TWO", 3, "THREE"); //max 5 elements by .of
  • 8. ImmutableMap builder 1. Map<Integer, String> numberNamesExtended = 2. ImmutableMap.<Integer, String>builder()() 3. .putAll(numberNames) 4. .put(5, "FIVE") 5. .put(6, "SIX") 6. .build();
  • 9. Utils ● Lists, Sets, Map, Strings ● Iterables, FluentIterable, Optional ● Predicate, Function ● Ordering, Range Lets practice
  • 10. Articles ● http://docs.guava-libraries.googlecode. com/git/javadoc/index.html?overview-summary.html ● http://java.dzone.com/articles/google-guava-cleaner-code ● http://habrahabr.ru/post/91215