Java and Google Collections




                  André Faria Gomes
What is a Collection?
It is a container ?
is simply an object
that groups multiple
   elements into a
      single unit
Why?
store, retrieve,
manipulate, and
 communicate
aggregate data
The Java Collections Framework
Generics
The Collection Interface
The Iterator Interface
Lists (Positional access, Search, Iteration, Range-view)
The List Interface
The List Iterator
ArrayList
Resizable-array implementation of the List interface.
Linked List (Doubly-linked)
better performance if elements are frequently inserted or deleted within the list.
Vector
Synchronized resizable-array with legacy methods.
Push
               Pop
               Peek
         The ArrayDeque is a better option




Stack (LIFO)
Queue
Queue Offer(element) Method
Inserts the specified element into this queue if it is possible to do so immediately without
 ...
Queue add() Method
Inserts the specified element into this queue if it is possible to do so immediately without
       vio...
Queue Pool Method
Retrieves and removes the head of this queue, or returns null if this queue is empty.
Queue Peek Method
Retrieves, but does not remove, the head of this queue, or returns null if this queue is
               ...
Queue element() Method
Retrieves, but does not remove, the head of this queue. This method differs from peek
             ...
The Queue Interface
ArrayDeque, LinkedBlockingDeque, LinkedList
Linked List (FIFO)
Insertion Order (QUEUE - LIST - DEQUE)
PriorityQueue
A Queue Ordered By Natural or Non Natural Order
The Deque Interface (Java 6)
 element insertion and removal at both ends
Deque Interface Methods
Deque Descending Iterator
Resizable-array implementation of the
Deque interface. Array deques have no
capacity restrictions; they grow as necessary
...
BlockingQueue / BlockingDeque
   additionally supports operations that wait for the queue to become non-empty when
retriev...
Sets
The Set Interface
HashSet (Fast, No Order)
TreeSet (Ordered by Value)
LinkedHashSet (Insertion Order)
Maps
The Map Interface
HashMap, TreeMap, LinkedHashMap
Hashtable (Synchronized HashMap)
Concurrent Map
A java.util.Map providing additional atomic putIfAbsent(k,v), remove(k,v), and replace (k,
                ...
WeakHashMap
   An implementation of the Map interface that stores only weak references to its keys.
Storing only weak refe...
Ordering
The Comparable Interface (Natural Order)
The Comparable Interface (Non Natural Order)
The Sorted Set and Sorted Map Interfaces
maintains its elements in ascending order, sorted according to the elements' natu...
The SortedSet Interface
The SortedMap Interface
The NavigableSet Interface
A SortedSet extended with navigation methods. Methods lower, floor,
ceiling, and higher return elements respectively less ...
The NavigableMap Inteface
     Implemented by TreeMao
Enums
EnumSet
EnumMap
Wrapper Implementations
Unmodifiable
Synchronized
Checked Collections
Joshua Bloch
Google Collections

Extending the Java Collections
            Library
The Google Collections Library
1.0 is a set of new collection
types, implementations and
related goodness for Java 5 and
h...
Multimap
MultiMap
Multisets
very useful for histograms and counting purposes




                   Multiset
BiMap
Bi-directional map functionality. Both keys and values are
unique, and looking up a key from a value is possible.




    ...
MapMaker
MapMaker
Immutable Collections
Immutable Collections
Functional Programming
Predicates
Predicate
Class Predicates
Functions (Transformation)
Functions
Preconditions (Constraints)
Preconditions
Utilities
Joiner
Joiner
Object - Equals and HashCode
Reducing Verbosity
Get Only Element
Map<String, List<String>> mapOfLists = Maps.newHashMap();
List<String> strings = Lists.newArrayList();




               ...
You Tube
http://www.youtube.com/watch?v=ZeO_J2OcHYM
Java Posse
http://www.javaposse.com
Creative Commons Images (1/2)
 http://www.flickr.com/photos/tonyjcase/2381294958/
 http://www.flickr.com/photos/rcsaxon/68...
Creative Commons Images (2/2)
 http://www.flickr.com/photos/gadl/89650415/
 http://www.flickr.com/photos/29714836@N08/2956...
References

 Google Collections JavaDoc
    http://google-collections.googlecode.
    com/svn/trunk/javadoc/index.html
 Th...
Upcoming SlideShare
Loading in …5
×

Collections Java e Google Collections

2,362 views

Published on

Introdução as Collections do JDK e Google Collections

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,362
On SlideShare
0
From Embeds
0
Number of Embeds
15
Actions
Shares
0
Downloads
97
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Collections Java e Google Collections

  1. 1. Java and Google Collections André Faria Gomes
  2. 2. What is a Collection?
  3. 3. It is a container ?
  4. 4. is simply an object that groups multiple elements into a single unit
  5. 5. Why?
  6. 6. store, retrieve, manipulate, and communicate aggregate data
  7. 7. The Java Collections Framework
  8. 8. Generics
  9. 9. The Collection Interface
  10. 10. The Iterator Interface
  11. 11. Lists (Positional access, Search, Iteration, Range-view)
  12. 12. The List Interface
  13. 13. The List Iterator
  14. 14. ArrayList Resizable-array implementation of the List interface.
  15. 15. Linked List (Doubly-linked) better performance if elements are frequently inserted or deleted within the list.
  16. 16. Vector Synchronized resizable-array with legacy methods.
  17. 17. Push Pop Peek The ArrayDeque is a better option Stack (LIFO)
  18. 18. Queue
  19. 19. Queue Offer(element) Method Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions. When using a capacity-restricted queue, this method is generally preferable to add(E), which can fail to insert an element only by throwing an exception.
  20. 20. Queue add() Method Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions, returning true upon success and throwing an IllegalStateException if no space is currently available.
  21. 21. Queue Pool Method Retrieves and removes the head of this queue, or returns null if this queue is empty.
  22. 22. Queue Peek Method Retrieves, but does not remove, the head of this queue, or returns null if this queue is empty.
  23. 23. Queue element() Method Retrieves, but does not remove, the head of this queue. This method differs from peek only in that it throws an exception if this queue is empty.
  24. 24. The Queue Interface ArrayDeque, LinkedBlockingDeque, LinkedList
  25. 25. Linked List (FIFO) Insertion Order (QUEUE - LIST - DEQUE)
  26. 26. PriorityQueue A Queue Ordered By Natural or Non Natural Order
  27. 27. The Deque Interface (Java 6) element insertion and removal at both ends
  28. 28. Deque Interface Methods
  29. 29. Deque Descending Iterator
  30. 30. Resizable-array implementation of the Deque interface. Array deques have no capacity restrictions; they grow as necessary to support usage. They are not thread-safe; in the absence of external synchronization, they do not support concurrent access by multiple threads. Null elements are prohibited. This class is likely to be faster than Stack when used as a stack, and faster than LinkedList when used as a queue. The ArrayDeque Implementation
  31. 31. BlockingQueue / BlockingDeque additionally supports operations that wait for the queue to become non-empty when retrieving an element, and wait for space to become available in the queue when storing an element
  32. 32. Sets
  33. 33. The Set Interface
  34. 34. HashSet (Fast, No Order)
  35. 35. TreeSet (Ordered by Value)
  36. 36. LinkedHashSet (Insertion Order)
  37. 37. Maps
  38. 38. The Map Interface
  39. 39. HashMap, TreeMap, LinkedHashMap
  40. 40. Hashtable (Synchronized HashMap)
  41. 41. Concurrent Map A java.util.Map providing additional atomic putIfAbsent(k,v), remove(k,v), and replace (k, oldV,newV) methods.
  42. 42. WeakHashMap An implementation of the Map interface that stores only weak references to its keys. Storing only weak references allows key-value pairs to be garbage-collected when the key is no longer referenced outside of the WeakHashMap.
  43. 43. Ordering
  44. 44. The Comparable Interface (Natural Order)
  45. 45. The Comparable Interface (Non Natural Order)
  46. 46. The Sorted Set and Sorted Map Interfaces maintains its elements in ascending order, sorted according to the elements' natural ordering or according to a Comparator provided at SortedSet creation time. (TreeSet and TreeMap)
  47. 47. The SortedSet Interface
  48. 48. The SortedMap Interface
  49. 49. The NavigableSet Interface
  50. 50. A SortedSet extended with navigation methods. Methods lower, floor, ceiling, and higher return elements respectively less than, less than or equal, greater than or equal, and greater than a given element, returning null if there is no such element. Ascending or descending order. This interface additionally defines methods pollFirst and pollLast that return and remove the lowest and highest element, if one exists, else returning null. Methods subSet, headSet, and tailSet. Implemented By TreeMap The NavigableSet Interface
  51. 51. The NavigableMap Inteface Implemented by TreeMao
  52. 52. Enums
  53. 53. EnumSet
  54. 54. EnumMap
  55. 55. Wrapper Implementations
  56. 56. Unmodifiable
  57. 57. Synchronized
  58. 58. Checked Collections
  59. 59. Joshua Bloch
  60. 60. Google Collections Extending the Java Collections Library
  61. 61. The Google Collections Library 1.0 is a set of new collection types, implementations and related goodness for Java 5 and higher, brought to you by Google. It is a natural extension of the Java Collections Framework you already know and love. What?
  62. 62. Multimap
  63. 63. MultiMap
  64. 64. Multisets
  65. 65. very useful for histograms and counting purposes Multiset
  66. 66. BiMap
  67. 67. Bi-directional map functionality. Both keys and values are unique, and looking up a key from a value is possible. BiMap
  68. 68. MapMaker
  69. 69. MapMaker
  70. 70. Immutable Collections
  71. 71. Immutable Collections
  72. 72. Functional Programming
  73. 73. Predicates
  74. 74. Predicate
  75. 75. Class Predicates
  76. 76. Functions (Transformation)
  77. 77. Functions
  78. 78. Preconditions (Constraints)
  79. 79. Preconditions
  80. 80. Utilities
  81. 81. Joiner
  82. 82. Joiner
  83. 83. Object - Equals and HashCode
  84. 84. Reducing Verbosity
  85. 85. Get Only Element
  86. 86. Map<String, List<String>> mapOfLists = Maps.newHashMap(); List<String> strings = Lists.newArrayList(); Reducing Verbosity
  87. 87. You Tube http://www.youtube.com/watch?v=ZeO_J2OcHYM
  88. 88. Java Posse http://www.javaposse.com
  89. 89. Creative Commons Images (1/2) http://www.flickr.com/photos/tonyjcase/2381294958/ http://www.flickr.com/photos/rcsaxon/689732379/ http://www.flickr.com/photos/caveman_92223/3185534518/ http://www.flickr.com/photos/northbaywanderer/121971249/ http://www.flickr.com/photos/photohome_uk/1494590209/ http://www.flickr.com/photos/mworrell/266913194/ http://www.flickr.com/photos/romanlily/2609759239/ http://www.flickr.com/photos/seandreilinger/713631512/ http://www.flickr.com/photos/thatguyfromcchs08/2300190277/ http://www.flickr.com/photos/flyzipper/61475775/ http://www.flickr.com/photos/kasaa/2315571104/ http://www.flickr.com/photos/vermininc/2335148856/ http://www.flickr.com/photos/stewf/2026818238/ http://www.flickr.com/photos/kinghuang/3172003953/ http://www.flickr.com/photos/jgoforth/3111875161/ http://farm3.static.flickr.com/2045/2247502690_d72ec4c683.jpg?v=0 http://www.flickr.com/photos/expressmonorail/3024990539/ http://www.flickr.com/photos/tonivc/403265960/ http://www.flickr.com/photos/kt/146500920/ http://www.flickr.com/photos/marcelgermain/2070007716/ http://www.flickr.com/photos/darwinbell/465459020/ http://www.flickr.com/photos/vgm8383/2482555985/ http://www.flickr.com/photos/darhadubai/2950522110/ http://www.flickr.com/photos/jackhynes/330890500/ http://www.flickr.com/photos/breakfastpirate/167192101/ continue....
  90. 90. Creative Commons Images (2/2) http://www.flickr.com/photos/gadl/89650415/ http://www.flickr.com/photos/29714836@N08/2956409782/ http://www.flickr.com/photos/phonono/520421532/ http://www.flickr.com/photos/mika/279115724/ http://www.flickr.com/photos/smaku/2602374677/ http://www.flickr.com/photos/colm/551068416/ http://www.flickr.com/photos/gaetanlee/298680664/ http://www.flickr.com/photos/charliegentle/94736480/ http://www.flickr.com/photos/theamarand/2616794227/
  91. 91. References Google Collections JavaDoc http://google-collections.googlecode. com/svn/trunk/javadoc/index.html The Google Collections Library http://www.developer.com/open/article.php/3735441

×