﻿{"id":694,"date":"2013-04-10T11:36:38","date_gmt":"2013-04-10T02:36:38","guid":{"rendered":"http:\/\/yucchi.jp\/blog\/?p=694"},"modified":"2013-04-24T19:38:37","modified_gmt":"2013-04-24T10:38:37","slug":"jdk8-lambda-%e3%81%9d%e3%81%ae%e4%bb%96%e3%81%84%e3%82%8d%e3%81%84%e3%82%8d-%e3%81%aa%e3%82%93%e3%81%a7%e3%82%82%e3%81%84%e3%81%84%e3%81%8b%e3%82%89%e5%8b%95%e3%81%8b%e3%81%97%e3%81%a6%e3%81%bf-8","status":"publish","type":"post","link":"http:\/\/yucchi.jp\/blog\/?p=694","title":{"rendered":"JDK8 Lambda \u305d\u306e\u4ed6\u3044\u308d\u3044\u308d \u306a\u3093\u3067\u3082\u3044\u3044\u304b\u3089\u52d5\u304b\u3057\u3066\u307f\u308b \u305d\u306e\uff19"},"content":{"rendered":"<p>\u4eca\u65e5\u3082\u306f\u3058\u307e\u308a\u307e\u3059\u3002<\/p>\n<p>JDK8 Lambda \u305d\u306e\u4ed6\u3044\u308d\u3044\u308d \u306a\u3093\u3067\u3082\u3044\u3044\u304b\u3089\u52d5\u304b\u3057\u3066\u307f\u308b \u6700\u7d42\u56de\u3067\u3059\u3002<\/p>\n<p>\u3084\u3063\u3068\u7d42\u308f\u308b\u306e\u304b\u3068\u601d\u3063\u3066\u3044\u308b\u4eba\u3082\u3044\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u306d\u3002<\/p>\n<p>\u3067\u306f\u3001\u6700\u7d42\u56de\u306e\u304a\u984c\u306f \u6700\u3082\u4e00\u756a\u58f2\u308c\u305f\u5546\u54c1 \u3092\u8868\u793a\u3055\u305b\u3066\u307f\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u30b3\u30fc\u30c9\u306f\u4e0b\u8a18\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<style type=\"text\/css\">\n<!--\ntable {color: #000000; background-color: #e9e8e2; font-family: \u3086\u305f\u307d\u3093\uff08\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\uff09}\n-->\n<\/style>\n<table width=\"100%\">\n<tbody>\n<tr>\n<td align=\"left\">mylambdaexamples\\MyLambdaExamples.java<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<pre start-line=\"114\">\r\n\/\/ \u6700\u3082\u4e00\u756a\u58f2\u308c\u305f\u5546\u54c1\r\nSystem.out.println(\"\\n<-- \u6700\u3082\u4e00\u756a\u58f2\u308c\u305f\u5546\u54c1 -->\");\r\nToIntFunction<Entry<Wristwatch, List<Sale>>> toSize = (e -> e.getValue().size());\r\nOptional<Wristwatch> mostBought;\r\nmostBought = sales.collect(groupingBy(Sale::getWristwatch))\r\n        .entrySet()\r\n        .stream()\r\n        .sorted(comparing(toSize).reverseOrder())\r\n        .map(Entry::getKey)\r\n        .findFirst();\r\nif (mostBought.isPresent()) {\r\n    System.out.println(mostBought.get().getBrand()\r\n            + \"  \" + mostBought.get().getModel());\r\n}\r\n<\/pre>\n<p>\u4eca\u56de\u3082\u30b7\u30f3\u30d7\u30eb\u306a\u30b3\u30fc\u30c9\u3067\u5b9f\u88c5\u3055\u308c\u3066\u307e\u3059\u3002\u7d20\u6575\u3067\u3059\uff01(*^o^*)<\/p>\n<p>116 \u884c\u76ee\u3067 Wristwatch \u3092\u30ad\u30fc\u306b List&lt;Sale&gt; \u3092\u5024\u3068\u3057\u3001Wristwatch \u3054\u3068\u306b\u58f2\u308c\u305f\u500b\u6570\u3092\uff08 int \u5024 ) \u3092 toSize \u306b\u683c\u7d0d\u3001<\/p>\n<p>117 \u884c\u76ee\u3067 Optional&lt;Wristwatch&gt; mostBought \u3092\u5ba3\u8a00<\/p>\n<p>118 \u884c\u76ee\u304b\u3089 sales \u30b9\u30c8\u30ea\u30fc\u30e0\u3092 Sale \u30af\u30e9\u30b9\u306e getWristwatch() \u30e1\u30bd\u30c3\u30c9\u3067\u53d6\u5f97\u3057\u305f wristwatch \u3067\u30b0\u30eb\u30fc\u30d4\u30f3\u30b0\u3057\u3066\u30ea\u30c0\u30af\u30b7\u30e7\u30f3\u3057\u3001<\/p>\n<blockquote>\n<p>\u30de\u30c3\u30d7\u306b\u683c\u7d0d\u3055\u308c\u3066\u3044\u308b\u30de\u30c3\u30d4\u30f3\u30b0\u306e\u30bb\u30c3\u30c8\u30d3\u30e5\u30fc\u3092\u8fd4\u3057\u3001\u305d\u308c\u3092\u30b9\u30c8\u30ea\u30fc\u30e0\u306b\u3057\u306a\u304a\u3057\u3066 toSize \u3092\u5f15\u6570\u306b\u3057\u3066 sorted() \u30e1\u30bd\u30c3\u30c9\u3067\u30bd\u30fc\u30c8\u3057\u305f\u3082\u306e\u3092\u30ea\u30d0\u30fc\u30b9\u3055\u305b\u3001<\/p>\n<p>map() \u30e1\u30bd\u30c3\u30c9\u306e\u5f15\u6570\u306b\u30a8\u30f3\u30c8\u30ea\u306b\u5bfe\u5fdc\u3059\u308b\u30ad\u30fc\u3092\u6e21\u3057\u3066\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u69cb\u7bc9\u3057\u306a\u3057\u3066\u3001findFirst() \u30e1\u30bd\u30c3\u30c9\u3067\u6700\u521d\u306e\u8981\u7d20\uff08\u6700\u3082\u4e00\u756a\u58f2\u308c\u305f\u5546\u54c1\uff09\u3092\u53d6\u5f97\u3002<\/p>\n<\/blockquote>\n<p>124 \u884c\u76ee\u3067 mostBought \u306b\u6700\u521d\u306e\u8981\u7d20\u304c\u3042\u308b\u304b isPresent() \u30e1\u30bd\u30c3\u30c9\u3067\u5224\u5b9a\u3057\u3001<\/p>\n<p>125 \u884c\u76ee\u3067\u305d\u306e\u8981\u7d20\u306e\u30d6\u30e9\u30f3\u30c9\u540d\u3068\u30e2\u30c7\u30eb\u540d\u3092\u8868\u793a\u3055\u305b\u3066\u307e\u3059\u3002<\/p>\n<p>\u3061\u3087\u3063\u3068\u3084\u3084\u3053\u3057\u304f\u611f\u3058\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u304c\u3053\u308c\u3060\u3051\u306e\u51e6\u7406\u3092\u3053\u308c\u3060\u3051\u7c21\u6f54\u306b\u8a18\u8ff0\u3067\u304d\u308b\u3063\u3066\u7d20\u6575\u3060\u3068\u601d\u3044\u307e\u305b\u3093\u304b\uff1f<\/p>\n<p>\u7591\u308a\u6df1\u3044\u3042\u306a\u305f\u306e\u70ba\u306b\u5b9f\u884c\u7d50\u679c\u306f\u6b21\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>&lt;&#8211; \u6700\u3082\u4e00\u756a\u58f2\u308c\u305f\u5546\u54c1 &#8211;&gt;<br \/>\u30c6\u30a3\u30d5\u30a1\u30cb\u30fc&nbsp; \u30dd\u30fc\u30bb\u30ea\u30f3<\/p>\n<p>\u3042\u3063\u3066\u307e\u3059\u306d\u3002<\/p>\n<p>\u3061\u306a\u307f\u306b\u3001\u3053\u306e\u3000\u30c6\u30a3\u30d5\u30a1\u30cb\u30fc\u3000\u30dd\u30fc\u30bb\u30ea\u30f3\u3000\u306f\u79c1\u306e\u597d\u304d\u306a\u8155\u6642\u8a08\u306e\u4e00\u3064\u3067\u3059\u3002<\/p>\n<p>\u8ab0\u304b\u6301\u3063\u3066\u3066\u3044\u3089\u306a\u3044\u4eba\u306f\u79c1\u306b\u7121\u511f\u3067\u30d7\u30ec\u30bc\u30f3\u30c8\u3057\u3066\u304f\u3060\u3055\u3044\uff01<\/p>\n<p>\u58ca\u308c\u3066\u3066\u52d5\u304b\u306a\u304f\u3066\u3082 OK \u3067\u3059\uff01<\/p>\n<p>\u304a\u3063\u3068\u3001\u3044\u3051\u306a\u3044\u3002\u304b\u306a\u308a\u79c1\u60c5\u304c\u306f\u3044\u3063\u3066\u3057\u307e\u3063\u305f\u3002(;\u00b4\u2200\uff40)<\/p>\n<p>\u3064\u3044\u3067\u306b\u3068\u8a00\u3063\u3066\u306f\u306a\u3093\u3067\u3059\u3051\u3069\u6700\u7d42\u56de\u3068\u3044\u3046\u3053\u3068\u3067\u9055\u3046\u65b9\u6cd5\u3082\u7d39\u4ecb\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<style type=\"text\/css\">\n<!--\ntable {color: #000000; background-color: #e9e8e2; font-family: \u3086\u305f\u307d\u3093\uff08\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\uff09}\n-->\n<\/style>\n<table width=\"100%\">\n<tbody>\n<tr>\n<td align=\"left\">mylambdaexamples\\MyLambdaExamples.java<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<pre start-line=\"130\">\r\n\/\/ \u6700\u3082\u4e00\u756a\u58f2\u308c\u305f\u5546\u54c1\r\nSystem.out.println(\"\\n<-- \u6700\u3082\u4e00\u756a\u58f2\u308c\u305f\u5546\u54c1 -->\");\r\nToIntFunction<Entry<Wristwatch, List<Sale>>> _toSize = (e -> e.getValue().size());\r\nsales.collect(groupingBy(Sale::getWristwatch))\r\n        .entrySet()\r\n        .stream()\r\n        .sorted(comparing(_toSize).reverseOrder())\r\n        .map(Entry::getKey)\r\n        .limit(1)\r\n        .forEach(e -> {\r\n            System.out.println(e.brand + \"  \" + e.model);\r\n        });\r\n\r\n<\/pre>\n<p>\u3053\u3061\u3089\u306e\u307b\u3046\u304c\u79c1\u7684\u306b\u306f\u3059\u3063\u304d\u308a\u3057\u307e\u3059\u306d\u3002<\/p>\n<p>\u305f\u3060\u3001\u8981\u7d20\u304c\u7121\u3044\u5834\u5408\u306e\u3053\u3068\u306f\u8003\u3048\u3066\u306a\u3044\u3067\u3059\u304c\u30fb\u30fb\u30fb<\/p>\n<p>\u3053\u3061\u3089\u3060\u3068 limit() \u30e1\u30bd\u30c3\u30c9\u306e\u5f15\u6570\u3092\u5909\u3048\u308b\u3060\u3051\u3067\u30d9\u30b9\u30c8\uff13\u3068\u304b\u8868\u793a\u3055\u305b\u308b\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<p>\u307e\u3060\u307e\u3060\u4ed6\u306b\u3082\u65b9\u6cd5\u306f\u3042\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u304c\u306f\u3063\u304d\u308a\u3044\u3048\u308b\u3053\u3068\u306f Java8 \u306f\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u304c\u3089\u307f\u304c\u975e\u5e38\u306b\u5f37\u5316\u3055\u308c\u308b\u3063\u3066\u3053\u3068\u3067\u3059\u306d\uff01<\/p>\n<p>\u305d\u308c\u3067\u306f\u6700\u5f8c\u306e\u304a\u7d04\u675f\u3067\u3059\u3002<\/p>\n<p>\u3053\u306e\u300cJDK8 Lambda \u305d\u306e\u4ed6\u3044\u308d\u3044\u308d \u306a\u3093\u3067\u3082\u3044\u3044\u304b\u3089\u52d5\u304b\u3057\u3066\u307f\u308b\u300d\u30b7\u30ea\u30fc\u30ba\u306f\u30a4\u30f3\u30bf\u30fc\u30cd\u30c3\u30c8\u4e0a\u3067\u5f97\u305f\u60c5\u5831\u3092\u5143\u306b\u305d\u308c\u3092\u5c11\u3057\u5909\u66f4\u3057\u3066\u3044\u308b\u3060\u3051\u3067\u3059\u3002 <\/p>\n<p>\u60b2\u3057\u3044\u3053\u3068\u306b\u305d\u306e\u60c5\u5831\u6e90\u306f\u82f1\u8a9e\u306a\u306e\u3067\u8a73\u3057\u3044\u5185\u5bb9\u306f\u308f\u304b\u308a\u307e\u305b\u3093\u3002 <\/p>\n<p>\u3088\u3063\u3066\u79c1\u306e\u63a8\u6e2c\u3067\u89e3\u91c8\u3055\u308c\u305f\u5185\u5bb9\u3068\u306a\u3063\u3066\u307e\u3059\u306e\u3067\u9593\u9055\u3044\u304c\u3042\u308b\u3068\u601d\u3044\u307e\u3059\u3002 <\/p>\n<p>Java8 \u3082\u307e\u3060 build83 \u3092\u4f7f\u7528\u3057\u3066\u3044\u307e\u3059\u306e\u3067 API \u306e\u5909\u66f4\u306b\u3088\u308a\u8a18\u8ff0\u65b9\u6cd5\u304c\u5909\u308f\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002 <\/p>\n<p>\u65e9\u304f\u6b63\u5f0f\u30ea\u30ea\u30fc\u30b9\u3055\u308c\u3066\u65e5\u672c\u8a9e\u3067\u3053\u306e\u8d85\u4fbf\u5229\u3067\u7d20\u6575\u306a\u65b0\u6a5f\u80fd\u3092\u52c9\u5f37\u3057\u305f\u3044\u4eca\u65e5\u3053\u306e\u9803\u3067\u3059\u3002 <\/p>\n<p>&nbsp;<\/p>\n<div id=\"scid:0767317B-992E-4b12-91E0-4F059A8CECA8:53d0d2b2-de8c-4281-8e2c-0533094b9589\" class=\"wlWriterEditableSmartContent\" style=\"float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px\">Hatena \u30bf\u30b0: <a href=\"http:\/\/b.hatena.ne.jp\/t\/Java\" rel=\"tag\">Java<\/a><\/div>\n<div class='wp_social_bookmarking_light'>\n            <div class=\"wsbl_hatena\"><a href='\/\/b.hatena.ne.jp\/add?mode=confirm&url=http%3A%2F%2Fyucchi.jp%2Fblog%2F%3Fp%3D694&title=JDK8%20Lambda%20%E3%81%9D%E3%81%AE%E4%BB%96%E3%81%84%E3%82%8D%E3%81%84%E3%82%8D%20%E3%81%AA%E3%82%93%E3%81%A7%E3%82%82%E3%81%84%E3%81%84%E3%81%8B%E3%82%89%E5%8B%95%E3%81%8B%E3%81%97%E3%81%A6%E3%81%BF%E3%82%8B%20%E3%81%9D%E3%81%AE%EF%BC%99' title='\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0' rel=nofollow class='wp_social_bookmarking_light_a' target=_blank><img src='http:\/\/yucchi.jp\/blog\/wp-content\/plugins\/wp-social-bookmarking-light\/public\/images\/hatena.gif' alt='\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0' title='\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0' width='16' height='12' class='wp_social_bookmarking_light_img' \/><\/a><\/div>\n            <div class=\"wsbl_facebook\"><a href='http:\/\/www.facebook.com\/share.php?u=http%3A%2F%2Fyucchi.jp%2Fblog%2F%3Fp%3D694&t=JDK8%20Lambda%20%E3%81%9D%E3%81%AE%E4%BB%96%E3%81%84%E3%82%8D%E3%81%84%E3%82%8D%20%E3%81%AA%E3%82%93%E3%81%A7%E3%82%82%E3%81%84%E3%81%84%E3%81%8B%E3%82%89%E5%8B%95%E3%81%8B%E3%81%97%E3%81%A6%E3%81%BF%E3%82%8B%20%E3%81%9D%E3%81%AE%EF%BC%99' title='Facebook \u306b\u30b7\u30a7\u30a2' rel=nofollow class='wp_social_bookmarking_light_a' target=_blank><img src='http:\/\/yucchi.jp\/blog\/wp-content\/plugins\/wp-social-bookmarking-light\/public\/images\/facebook.png' alt='Facebook \u306b\u30b7\u30a7\u30a2' title='Facebook \u306b\u30b7\u30a7\u30a2' width='16' height='16' class='wp_social_bookmarking_light_img' \/><\/a><\/div>\n            <div class=\"wsbl_google_plus_one\"><g:plusone size=\"medium\" annotation=\"none\" href=\"http:\/\/yucchi.jp\/blog\/?p=694\" ><\/g:plusone><\/div>\n            <div class=\"wsbl_twitter\"><a href=\"https:\/\/twitter.com\/share\" class=\"twitter-share-button\" data-url=\"http:\/\/yucchi.jp\/blog\/?p=694\" data-text=\"JDK8 Lambda \u305d\u306e\u4ed6\u3044\u308d\u3044\u308d \u306a\u3093\u3067\u3082\u3044\u3044\u304b\u3089\u52d5\u304b\u3057\u3066\u307f\u308b \u305d\u306e\uff19\" data-lang=\"ja\">Tweet<\/a><\/div>\n    <\/div>\n<br class='wp_social_bookmarking_light_clear' \/>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u65e5\u3082\u306f\u3058\u307e\u308a\u307e\u3059\u3002 JDK8 Lambda \u305d\u306e\u4ed6\u3044\u308d\u3044\u308d \u306a\u3093\u3067\u3082\u3044\u3044\u304b\u3089\u52d5\u304b\u3057\u3066\u307f\u308b \u6700\u7d42\u56de\u3067\u3059\u3002 \u3084\u3063\u3068\u7d42\u308f\u308b\u306e\u304b\u3068\u601d\u3063\u3066\u3044\u308b\u4eba\u3082\u3044\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u306d\u3002 \u3067\u306f\u3001\u6700\u7d42\u56de\u306e\u304a\u984c\u306f \u6700\u3082\u4e00\u756a\u58f2\u308c\u305f\u5546\u54c1 \u3092\u8868\u793a\u3055\u305b\u3066\u307f\u307e\u3059\u3002 \u3053\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u30b3\u30fc\u30c9\u306f\u4e0b\u8a18\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002 mylambdaexamples\\MyLambdaExamples.java \/\/ \u6700\u3082\u4e00\u756a\u58f2\u308c\u305f\u5546\u54c1 System.out.println(&#8220;\\n&#8221;); ToIntFunction toSize = (e -> e.getValue().size()); Optional mostBought; mostBought = \u2026<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[17],"class_list":["post-694","post","type-post","status-publish","format-standard","hentry","category-java","tag-java"],"_links":{"self":[{"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/694","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=694"}],"version-history":[{"count":2,"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/694\/revisions"}],"predecessor-version":[{"id":780,"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/694\/revisions\/780"}],"wp:attachment":[{"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=694"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=694"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=694"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}