Guavaの美味しい食べ方
Upcoming SlideShare
Loading in...5
×
 

Guavaの美味しい食べ方

on

  • 568 views

 

Statistics

Views

Total Views
568
Views on SlideShare
568
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Guavaの美味しい食べ方 Guavaの美味しい食べ方 Presentation Transcript

  • Guavaの食べ方2013/04/25松本 陽介
  • GuavaとはJavaの共通処理をまとめたライブラリ。主にGoogleのエンジニアが開発しています。Apache Commonsがライバル。
  • Guavaの特徴 ジェネリクス対応 並行処理の機能が豊富 fluent interface 可読性が高い Apache Commonsと併用可 View slide
  • Guavaの機能 com.google.common.annotations com.google.common.base com.google.common.cache com.google.common.collect com.google.common.eventbus com.google.common.io com.google.common.math com.google.common.net com.google.common.primitives com.google.common.reflect com.google.common.util.concurrent View slide
  • Guavaの機能 com.google.common.annotations com.google.common.base com.google.common.cache com.google.common.collect com.google.common.eventbus com.google.common.io com.google.common.math com.google.common.net com.google.common.primitives com.google.common.reflect com.google.common.util.concurrent
  • collect ListsList<String> list1 = Lists.newArrayList();List<String> list2 = Lists.newArrayList(“hoge”, ”fuga”);final List<String> list3 = ImmutableList.of(“tako”, ”ika”);
  • collect ListsList<User> userList = getUserList();// “taro”,”hanako”List<String> idList = Lists.transform(userList,new Function<User, String>() {@Overridepublic String apply(User user) {return user.getId();}});
  • collect MultiMapListMultimap<String, String> map = ArrayListMultiMap.create();map.put(“pigg”, “life”);map.put(“pigg”, ”cafe”);map.put(“card”, ”gf”);// “life”,”cafe”List<String> list = map.get(“pigg”);
  • base JoinerList<String> list = Lists.newArrayList(“hoge”, null, “fuga”);// “hoge,fuga”String join = Joiner.on(“,”).skipNulls().join(list);
  • base SplitterString val = “apple orange,peach”;CharMatcher matcher = CharMatcher.WHITESPACE.or(CharMatcher.is(„,‟));// “apple”,”orange”,”peach”Iterable<String> split =Splitter.on(matcher).omitEmptyStrings().split(val);
  • base PreconditionsInteger val = 10;Preconditions.checkNotNull(val, “required.”);Preconditions.checkArgument(val > 10, “over 10.”);
  • base StopwatchStopwatch stopwatch = new Stopwatch().start();execute();stopwatch.stop();// “elapsed time:12.3ms”log.info(“elapsed time:” + stopwatch);
  • io FilesBufferedReader reader = null;try {reader = Files.newReader(new File(“hoge.txt”), Charsets.UTF_8);} finally {Closeables.closeQuietly(reader);}
  • io FilesList<String> lines = Files.readLines(new File(“fuga.txt”), Charsets.UTF_8);byte[] bytes = Files.toByteArray(new File(“sample.jpg”));
  • util.concurrent ListeningFutureListeningExecutorService threadPool =MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(32));Callable<String> task = getTask();ListeningFuture<String> future = theadPool.submit(task);
  • util.concurrent ListeningFutureFutures.addCallback(future, new FutureCallback<String>() {@Overridepublic void onSuccess(String s) {log.info(“success! result:” + s);}@Overridepublic void onFailure(Throwable throwable) {log.error(“error!”, throwable);}});
  • util.concurrent RateLimiterRateLimiter limiter = RateLimiter.create(100.0);for (int i = 1; i <= 10000; i++) {limiter.acquire();execute();}for (byte[] bytes : getBytesList()) {limiter.acquire(bytes.length);execute(bytes);}
  • まとめGuavaを利用するとコーディングしやすくなり、ソースの可読性も向上します。便利な機能が沢山あるので、ぜひ利用してみてください。