+ All Categories
Home > Technology > Collections Java e Google Collections

Collections Java e Google Collections

Date post: 11-Nov-2014
Category:
Upload: andre-faria-gomes
View: 2,793 times
Download: 2 times
Share this document with a friend
Description:
Introdução as Collections do JDK e Google Collections
Popular Tags:
91
Java and Google Collections André Faria Gomes
Transcript
Page 1: Collections Java e Google Collections

Java and Google Collections

André Faria Gomes

Page 2: Collections Java e Google Collections

What is a Collection?

Page 3: Collections Java e Google Collections

It is a container ?

Page 4: Collections Java e Google Collections

is simply an object that groups multiple

elements into a single unit

Page 5: Collections Java e Google Collections

Why?

Page 6: Collections Java e Google Collections

store, retrieve, manipulate, and

communicate aggregate data

Page 7: Collections Java e Google Collections

The Java Collections Framework

Page 8: Collections Java e Google Collections

Generics

Page 9: Collections Java e Google Collections

The Collection Interface

Page 10: Collections Java e Google Collections

The Iterator Interface

Page 11: Collections Java e Google Collections

Lists (Positional access, Search, Iteration, Range-view)

Page 12: Collections Java e Google Collections

The List Interface

Page 13: Collections Java e Google Collections

The List Iterator

Page 14: Collections Java e Google Collections

ArrayListResizable-array implementation of the List interface.

Page 15: Collections Java e Google Collections

Linked List (Doubly-linked)better performance if elements are frequently inserted or deleted within the list.

Page 16: Collections Java e Google Collections

VectorSynchronized resizable-array with legacy methods.

Page 17: Collections Java e Google Collections

Stack (LIFO)

PushPopPeek

The ArrayDeque is a better option

Page 18: Collections Java e Google Collections

Queue

Page 19: Collections Java e Google Collections

Queue Offer(element) MethodInserts 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.

Page 20: Collections Java e Google Collections

Queue add() MethodInserts 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.

Page 21: Collections Java e Google Collections

Queue Pool MethodRetrieves and removes the head of this queue, or returns null if this queue is empty.

Page 22: Collections Java e Google Collections

Queue Peek MethodRetrieves, but does not remove, the head of this queue, or returns null if this queue is

empty.

Page 23: Collections Java e Google Collections

Queue element() MethodRetrieves, 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.

Page 25: Collections Java e Google Collections

Linked List (FIFO)Insertion Order (QUEUE - LIST - DEQUE)

Page 26: Collections Java e Google Collections

PriorityQueueA Queue Ordered By Natural or Non Natural Order

Page 27: Collections Java e Google Collections

The Deque Interface (Java 6)element insertion and removal at both ends

Page 28: Collections Java e Google Collections

Deque Interface Methods

Page 29: Collections Java e Google Collections

Deque Descending Iterator

Page 30: Collections Java e Google Collections

The ArrayDeque Implementation

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.

Page 31: Collections Java e Google Collections

BlockingQueue / BlockingDequeadditionally 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

Page 32: Collections Java e Google Collections

Sets

Page 33: Collections Java e Google Collections

The Set Interface

Page 34: Collections Java e Google Collections

HashSet (Fast, No Order)

Page 35: Collections Java e Google Collections

TreeSet (Ordered by Value)

Page 36: Collections Java e Google Collections

LinkedHashSet (Insertion Order)

Page 37: Collections Java e Google Collections

Maps

Page 38: Collections Java e Google Collections

The Map Interface

Page 39: Collections Java e Google Collections

HashMap, TreeMap, LinkedHashMap

Page 40: Collections Java e Google Collections

Hashtable (Synchronized HashMap)

Page 41: Collections Java e Google Collections

Concurrent MapA java.util.Map providing additional atomic putIfAbsent(k,v), remove(k,v), and replace (k,

oldV,newV) methods.

Page 42: Collections Java e Google Collections

WeakHashMapAn 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.

Page 43: Collections Java e Google Collections

Ordering

Page 44: Collections Java e Google Collections

The Comparable Interface (Natural Order)

Page 45: Collections Java e Google Collections

The Comparable Interface (Non Natural Order)

Page 46: Collections Java e Google Collections

The Sorted Set and Sorted Map Interfacesmaintains 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)

Page 47: Collections Java e Google Collections

The SortedSet Interface

Page 48: Collections Java e Google Collections

The SortedMap Interface

Page 49: Collections Java e Google Collections

The NavigableSet Interface

Page 50: Collections Java e Google Collections

The NavigableSet Interface

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

Page 51: Collections Java e Google Collections

The NavigableMap IntefaceImplemented by TreeMao

Page 52: Collections Java e Google Collections

Enums

Page 53: Collections Java e Google Collections

EnumSet

Page 54: Collections Java e Google Collections

EnumMap

Page 55: Collections Java e Google Collections

Wrapper Implementations

Page 56: Collections Java e Google Collections

Unmodifiable

Page 57: Collections Java e Google Collections

Synchronized

Page 58: Collections Java e Google Collections

Checked Collections

Page 59: Collections Java e Google Collections

Joshua Bloch

Page 60: Collections Java e Google Collections

Google Collections

Extending the Java Collections Library

Page 61: Collections Java e Google Collections

What?

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.

Page 62: Collections Java e Google Collections

Multimap

Page 63: Collections Java e Google Collections

MultiMap

Page 64: Collections Java e Google Collections

Multisets

Page 65: Collections Java e Google Collections

Multiset

very useful for histograms and counting purposes

Page 66: Collections Java e Google Collections

BiMap

Page 67: Collections Java e Google Collections

BiMap

BiMap provides bi-directional map functionality. In a bidirectional map, both keys and values are unique, and looking up a key from a value is possible.

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

Page 68: Collections Java e Google Collections

MapMaker

Page 69: Collections Java e Google Collections

MapMaker

Page 70: Collections Java e Google Collections

Immutable Collections

Page 71: Collections Java e Google Collections

Immutable Collections

Page 72: Collections Java e Google Collections

Functional Programming

Page 73: Collections Java e Google Collections

Predicates

Page 74: Collections Java e Google Collections

Predicate

Page 75: Collections Java e Google Collections

Class Predicates

Page 76: Collections Java e Google Collections

Functions (Transformation)

Page 77: Collections Java e Google Collections

Functions

Page 78: Collections Java e Google Collections

Preconditions (Constraints)

Page 79: Collections Java e Google Collections

Preconditions

Page 80: Collections Java e Google Collections

Utilities

Page 81: Collections Java e Google Collections

Joiner

Page 82: Collections Java e Google Collections

Joiner

Page 83: Collections Java e Google Collections

Object - Equals and HashCode

Page 84: Collections Java e Google Collections

Reducing Verbosity

Page 85: Collections Java e Google Collections

Get Only Element

Page 86: Collections Java e Google Collections

Reducing Verbosity

Map<String, List<String>> mapOfLists = Maps.newHashMap();List<String> strings = Lists.newArrayList();

Page 87: Collections Java e Google Collections

You Tubehttp://www.youtube.com/watch?v=ZeO_J2OcHYM

Page 88: Collections Java e Google Collections

Java Possehttp://www.javaposse.com

Page 89: Collections Java e Google Collections

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....

Page 90: Collections Java e Google Collections

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/

Page 91: Collections Java e Google Collections

References

Google Collections JavaDochttp://google-collections.googlecode.com/svn/trunk/javadoc/index.html

The Google Collections Libraryhttp://www.developer.com/open/article.php/3735441


Recommended