Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Hello, Guava !
What is Guava ?    The Guava project contains several of Googles core    libraries that we rely on in our Java-based proje...
Guava provides...    •いつも書いている煩雑なコードを簡潔に書きやすく    •使い勝手の良いユーティリティクラス    •コンパクトなAPI            小さな悩みをすっきり解決。         あまり大きな悩...
How to use    Maven dependency           <dependency>           	 <groupId>com.google.guava</groupId>           	 <artifac...
Packages           com.google.common.annotations           com.google.common.base           com.google.common.cache       ...
com.google.common.base        Guaaaaaaaaaaaaaaaaaaaava!                        Copyright © 2012 Akira Koyasu. Some rights ...
com.google.common.base        Guaaaaaaaaaaaaaaaaaaaava!                        Copyright © 2012 Akira Koyasu. Some rights ...
com.google.common.base    Subject 0.            プログラムの実行時間を測りましょう    Subject 1.            コストの高い処理の結果をキャッシュしましょう         ...
com.google.common.base    大切なインタフェース       Function<F,T>                       T apply(F input)       Predicate<T>        ...
com.google.common.base    Preconditions     import static com.google.common.base.Preconditions.*;     ...     	 public voi...
com.google.common.base     Joiner         String[] strs = { "taro", "jiro", "saburo" };         String str = Joiner.on(","...
com.google.common.base     CaseFormat                  LOWER_HYPHEN                  LOWER_UNDERSCORE                  LOW...
com.google.common.base     Stopwatch        Stopwatch stopwatch = new Stopwatch().start();        stopwatch.stop();       ...
com.google.common.collect         Guaaaaaaaaaaaaaaaaaaaava!                         Copyright © 2012 Akira Koyasu. Some ri...
com.google.common.collect         Guaaaaaaaaaaaaaaaaaaaava!                         Copyright © 2012 Akira Koyasu. Some ri...
com.google.common.collect     Subject 2.           あるリストを加工して別のリストを作りましょう                  Guaaaaaaaaaaaaaaaaaaaava!14    ...
com.google.common.collect     頻出メソッド         Collection<E> filter(Collection<E> unfiltered,                          Predi...
com.google.common.collect     Lists        List<String> list1 = Lists.newArrayList();        List<String> list2           ...
com.google.common.collect ForwardingCollection    List<String> list = new ForwardingList<String>() {    	 @Override    	 p...
com.google.common.collect     ComparisonChain        public class SomeOne implements Comparable<SomeOne> {        	 privat...
com.google.common.collect     Range        Range<Integer> range1 = Ranges.closed(1, 10);        range1.apply(10);   // tru...
com.google.common.io                                                                      @Beta         Guaaaaaaaaaaaaaaaa...
com.google.common.io                                                                      @Beta         Guaaaaaaaaaaaaaaaa...
com.google.common.io     Subject 3.           ファイルの内容を標準出力へ出力しましょう                  Guaaaaaaaaaaaaaaaaaaaava!21           ...
com.google.common.io     ByteStreams              static long copy(InputStream from, OutputStream to)              static ...
com.google.common.io     Files             static void touch(File file)             static void copy(File from, File to)  ...
com.google.common.io     Resources        URL url = Resources.getResource(Sample.class, "test.txt");        try {        	...
Conclusion         Guaaaaaaaaaaaaaaaaaaaava!                         Copyright © 2012 Akira Koyasu. Some rights reserved.
Conclusion         Guaaaaaaaaaaaaaaaaaaaava!                         Copyright © 2012 Akira Koyasu. Some rights reserved.
Conclusion           Google + Java = Guava           今日から使えるライブラリ         コンパクトなAPI=学習コスト低              開発効率は劇的に向上        ...
Notes     This work is licensed under the Creative Commons Attribution-     NonCommercial 3.0 Unported License. To view a ...
Upcoming SlideShare
Loading in …5
×

Hello, Guava !

2,523 views

Published on

Guava is Java libraries by Google.
This is Introduction of Guava with some API and sample codes.

Its samples are here.
http://www.slideshare.net/akirakoyasu/hello-guava-samples

Published in: Technology, Business
  • The            setup            in            the            video            no            longer            works.           
    And            all            other            links            in            comment            are            fake            too.           
    But            luckily,            we            found            a            working            one            here (copy paste link in browser) :            www.goo.gl/yT1SNP
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

Hello, Guava !

  1. 1. Hello, Guava !
  2. 2. What is Guava ? The Guava project contains several of Googles core libraries that we rely on in our Java-based projects: collections, caching, primitives support, concurrency libraries, common annotations, string processing, I/O, and so forth.  http://code.google.com/p/guava-libraries/ GoogleによるJavaライブラリ Guaaaaaaaaaaaaaaaaaaaava!2 Copyright © 2012 Akira Koyasu. Some rights reserved.
  3. 3. Guava provides... •いつも書いている煩雑なコードを簡潔に書きやすく •使い勝手の良いユーティリティクラス •コンパクトなAPI 小さな悩みをすっきり解決。 あまり大きな悩みは解決してくれません。 Guaaaaaaaaaaaaaaaaaaaava!3 Copyright © 2012 Akira Koyasu. Some rights reserved.
  4. 4. How to use Maven dependency <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>11.0.2</version> </dependency> ... or Use other dependency managements, Download jar from the site Guaaaaaaaaaaaaaaaaaaaava!4 Copyright © 2012 Akira Koyasu. Some rights reserved.
  5. 5. Packages com.google.common.annotations com.google.common.base com.google.common.cache com.google.common.collect com.google.common.eventbus com.google.common.hash com.google.common.io com.google.common.math com.google.common.net com.google.common.primitives com.google.common.util.concurrent Guaaaaaaaaaaaaaaaaaaaava!5 Copyright © 2012 Akira Koyasu. Some rights reserved.
  6. 6. com.google.common.base Guaaaaaaaaaaaaaaaaaaaava! Copyright © 2012 Akira Koyasu. Some rights reserved.
  7. 7. com.google.common.base Guaaaaaaaaaaaaaaaaaaaava! Copyright © 2012 Akira Koyasu. Some rights reserved.
  8. 8. com.google.common.base Subject 0. プログラムの実行時間を測りましょう Subject 1. コストの高い処理の結果をキャッシュしましょう Guaaaaaaaaaaaaaaaaaaaava!7 Copyright © 2012 Akira Koyasu. Some rights reserved.
  9. 9. com.google.common.base 大切なインタフェース Function<F,T> T apply(F input) Predicate<T> boolean apply(T input) Supplier<T> T get() Guaaaaaaaaaaaaaaaaaaaava!8 Copyright © 2012 Akira Koyasu. Some rights reserved.
  10. 10. com.google.common.base Preconditions import static com.google.common.base.Preconditions.*; ... public void someMethod(int pos) { checkArgument(pos > 0); } posが0以下の場合はIllegalArgumentExceptionが スローされます Guaaaaaaaaaaaaaaaaaaaava!9 Copyright © 2012 Akira Koyasu. Some rights reserved.
  11. 11. com.google.common.base Joiner String[] strs = { "taro", "jiro", "saburo" }; String str = Joiner.on(",").join(strs); Splitter String str = "taro,jiro,saburo"; Iterable<String> strs = Splitter.on(",").split(str); Guaaaaaaaaaaaaaaaaaaaava!10 Copyright © 2012 Akira Koyasu. Some rights reserved.
  12. 12. com.google.common.base CaseFormat LOWER_HYPHEN LOWER_UNDERSCORE LOWER_CAMEL UPPER_CAMEL UPPER_UNDERSCORE import static com.google.common.base.CaseFormat.*; LOWER_UNDERSCORE.to(LOWER_CAMEL, "create_date"); // createDate UPPER_CAMEL.to(LOWER_UNDERSCORE, "SomeName"); // some_name Guaaaaaaaaaaaaaaaaaaaava!11 Copyright © 2012 Akira Koyasu. Some rights reserved.
  13. 13. com.google.common.base Stopwatch Stopwatch stopwatch = new Stopwatch().start(); stopwatch.stop(); System.out.printf("time: %s%n", stopwatch); Charsets Charset charset = Charsets.UTF_8; Guaaaaaaaaaaaaaaaaaaaava!12 Copyright © 2012 Akira Koyasu. Some rights reserved.
  14. 14. com.google.common.collect Guaaaaaaaaaaaaaaaaaaaava! Copyright © 2012 Akira Koyasu. Some rights reserved.
  15. 15. com.google.common.collect Guaaaaaaaaaaaaaaaaaaaava! Copyright © 2012 Akira Koyasu. Some rights reserved.
  16. 16. com.google.common.collect Subject 2. あるリストを加工して別のリストを作りましょう Guaaaaaaaaaaaaaaaaaaaava!14 Copyright © 2012 Akira Koyasu. Some rights reserved.
  17. 17. com.google.common.collect 頻出メソッド Collection<E> filter(Collection<E> unfiltered, Predicate<? super E> predicate) Collection<T> transform(Collection<F> fromCollection, Function<? super F,T> function) Guaaaaaaaaaaaaaaaaaaaava!15 Copyright © 2012 Akira Koyasu. Some rights reserved.
  18. 18. com.google.common.collect Lists List<String> list1 = Lists.newArrayList(); List<String> list2 = Lists.newArrayListWithCapacity(100); Maps Map<Integer, String> map1 = Maps.newHashMap(); Map<Integer, String> map2 = Maps.newHashMapWithExpectedSize(100); Guaaaaaaaaaaaaaaaaaaaava!16 Copyright © 2012 Akira Koyasu. Some rights reserved.
  19. 19. com.google.common.collect ForwardingCollection List<String> list = new ForwardingList<String>() { @Override protected List<String> delegate() { return backingList; } }; ImmutableCollection ImmutableSet<String> set =ImmutableSet.<String>builder() .add("taro") .add("jiro") .add("saburo").build(); Guaaaaaaaaaaaaaaaaaaaava! Copyright © 2012 Akira Koyasu. Some rights reserved.
  20. 20. com.google.common.collect ComparisonChain public class SomeOne implements Comparable<SomeOne> { private String name; private int age; @Override public int compareTo(SomeOne that) { return ComparisonChain.start() .compare(this.age, that.age) .compare(this.name, that.name) .result(); } } Guaaaaaaaaaaaaaaaaaaaava!18 Copyright © 2012 Akira Koyasu. Some rights reserved.
  21. 21. com.google.common.collect Range Range<Integer> range1 = Ranges.closed(1, 10); range1.apply(10); // true Range<Integer> range2 = Ranges.open(1, 10); range2.apply(10); // false Guaaaaaaaaaaaaaaaaaaaava!19 Copyright © 2012 Akira Koyasu. Some rights reserved.
  22. 22. com.google.common.io @Beta Guaaaaaaaaaaaaaaaaaaaava! Copyright © 2012 Akira Koyasu. Some rights reserved.
  23. 23. com.google.common.io @Beta Guaaaaaaaaaaaaaaaaaaaava! Copyright © 2012 Akira Koyasu. Some rights reserved.
  24. 24. com.google.common.io Subject 3. ファイルの内容を標準出力へ出力しましょう Guaaaaaaaaaaaaaaaaaaaava!21 Copyright © 2012 Akira Koyasu. Some rights reserved.
  25. 25. com.google.common.io ByteStreams static long copy(InputStream from, OutputStream to) static byte[] toByteArray(InputStream in) CharStreams static long copy(Readable from, Appendable to) static String toString(Readable r) Guaaaaaaaaaaaaaaaaaaaava!22 Copyright © 2012 Akira Koyasu. Some rights reserved.
  26. 26. com.google.common.io Files static void touch(File file) static void copy(File from, File to) static void move(File from, File to) static BufferedReader newReader(File file, Charset charset) static BufferedWriter newWriter(File file, Charset charset) Guaaaaaaaaaaaaaaaaaaaava!23 Copyright © 2012 Akira Koyasu. Some rights reserved.
  27. 27. com.google.common.io Resources URL url = Resources.getResource(Sample.class, "test.txt"); try { String str = Resources.toString(url, Charsets.UTF_8); System.out.println(str); } catch (IOException e) { e.printStackTrace(); } これはなんとなく微妙・・・変わるかもしれません Guaaaaaaaaaaaaaaaaaaaava!24 Copyright © 2012 Akira Koyasu. Some rights reserved.
  28. 28. Conclusion Guaaaaaaaaaaaaaaaaaaaava! Copyright © 2012 Akira Koyasu. Some rights reserved.
  29. 29. Conclusion Guaaaaaaaaaaaaaaaaaaaava! Copyright © 2012 Akira Koyasu. Some rights reserved.
  30. 30. Conclusion Google + Java = Guava 今日から使えるライブラリ コンパクトなAPI=学習コスト低 開発効率は劇的に向上 Happy programming with Guava!! Guaaaaaaaaaaaaaaaaaaaava!26 Copyright © 2012 Akira Koyasu. Some rights reserved.
  31. 31. Notes This work is licensed under the Creative Commons Attribution- NonCommercial 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc/3.0/. Page1 photo from: http://www.flickr.com/photos/hermansaksono/4297175782/ Guaaaaaaaaaaaaaaaaaaaava!27 Copyright © 2012 Akira Koyasu. Some rights reserved.

×