{"id":3740,"date":"2019-01-16T15:59:43","date_gmt":"2019-01-16T07:59:43","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=3740"},"modified":"2019-01-16T15:59:43","modified_gmt":"2019-01-16T07:59:43","slug":"%e5%87%bd%e6%95%b0%e5%bc%8f%e7%bc%96%e7%a8%8b%e7%9a%84%e5%8e%9f%e7%90%86%e5%92%8c%e4%bc%98%e7%82%b9","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=3740","title":{"rendered":"\u51fd\u6570\u5f0f\u7f16\u7a0b\u7684\u539f\u7406\u548c\u4f18\u70b9"},"content":{"rendered":"<p>\n\t\u6211\u5728 <a href=\"https:\/\/www.xttblog.com\/spring-webflux.html\" name=\"WebFlux \u6559\u7a0b\" target=\"_blank\" title=\"WebFlux \u6559\u7a0b\">WebFlux \u6559\u7a0b<\/a>\u4e2d\u5df2\u7ecf\u9610\u660e\u4e86\u4e00\u79cd\u89c2\u70b9\uff0c\u51fd\u6570\u5f0f\u7f16\u7a0b\uff08Functional programming\uff09\u5c06\u6210\u4e3a\u672a\u6765\u7f16\u7a0b\u7684\u4e00\u79cd\u8d8b\u52bf\u3002\u6211\u4eec\u4e5f\u53ef\u4ee5\u4ece Java 8 \u7b49\u65b0\u7248\u672c\u4e2d\u770b\u5230\u8fd9\u79cd\u8d8b\u52bf\u3002\u6240\u4ee5\u5173\u4e8e\u51fd\u6570\u5f0f\u7f16\u7a0b\u7684\u539f\u7406\uff0c\u4f18\u7f3a\u70b9\uff1f\u4ec0\u4e48\u662f\u51fd\u6570\u5f0f\u7f16\u7a0b\uff1f\u7b49\u95ee\u9898\uff0c\u6211\u505a\u4e00\u4e2a\u603b\u7ed3\uff0c\u5e0c\u671b\u80fd\u591f\u65b9\u4fbf\u5230\u5927\u5bb6\u7684\u5b66\u4e60\u548c\u7406\u89e3\uff01\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"\u51fd\u6570\u5f0f\u7f16\u7a0b\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/wx1.sinaimg.cn\/large\/8fa5dcfcgy1fz8fuehsiwj20dz07gt9k.jpg\" style=\"width: 503px;height: 268px\" \/>\n<\/p>\n<h2>\n\t\u4ec0\u4e48\u662f\u51fd\u6570\u5f0f\u7f16\u7a0b\uff1f<br \/>\n<\/h2>\n<p>\n\t\u51fd\u6570\u5f0f\u7f16\u7a0b\u7684\u7b2c\u4e00\u4e2a\u7279\u70b9\u5c31\u662f\u53ef\u4ee5\u628a\u51fd\u6570\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9\u53e6\u4e00\u4e2a\u51fd\u6570\uff0c\u4e5f\u5c31\u662f\u6240\u8c13\u7684\u9ad8\u9636\u51fd\u6570\u3002\u4f8b\u5982\uff0c\u5bf9\u6570\u7ec4\u8fdb\u884c\u6392\u5e8f\uff0c\u53ef\u4ee5\u4f20\u5165\u4e00\u4e2a\u6392\u5e8f\u51fd\u6570\u4f5c\u4e3a\u53c2\u6570\uff1a\n<\/p>\n<pre class=\"brush:java;\">\r\nString[] array = { &quot;xttblog&quot;, &quot;yyucao&quot;, &quot;www.xttblog.com&quot; };\r\nArrays.sort(array, String::compareToIgnoreCase);<\/pre>\n<p>\n\t\u51fd\u6570\u5f0f\u7f16\u7a0b\u7684\u7b2c\u4e8c\u4e2a\u7279\u70b9\u5c31\u662f\u53ef\u4ee5\u8fd4\u56de\u4e00\u4e2a\u51fd\u6570\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u5b9e\u73b0\u95ed\u5305\u6216\u8005\u60f0\u6027\u8ba1\u7b97\u3002\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"\u51fd\u6570\u5f0f\u7f16\u7a0b\" src=\"http:\/\/www.ruanyifeng.com\/blogimg\/asset\/2017\/bg2017022202.jpg\" style=\"width: 642px;height: 350px\" \/>\n<\/p>\n<h2>\n\t\u51fd\u6570\u5f0f\u7f16\u7a0b\u7684\u597d\u5904<br \/>\n<\/h2>\n<p>\n\t\u90a3\u4e48\u6839\u636e\u7b80\u5316\u4e86\u7684\u51fd\u6570\u5f0f\u7f16\u7a0b\u7684\u7279\u70b9\uff0c\u51fd\u6570\u5f0f\u7f16\u7a0b\u6709\u4ec0\u4e48\u597d\u5904\u5462\uff1f\n<\/p>\n<p>\n\t\u4ece\u4ee3\u7801\u7684\u53ef\u7ef4\u62a4\u6027\u4e0a\u8bb2\uff0c\u51fd\u6570\u5f0f\u7f16\u7a0b\u6700\u5927\u7684\u597d\u5904\u662f\u5f15\u7528\u900f\u660e\uff0c\u5373\u51fd\u6570\u8fd0\u884c\u7684\u7ed3\u679c\u53ea\u4f9d\u8d56\u4e8e\u8f93\u5165\u7684\u53c2\u6570\uff0c\u800c\u4e0d\u4f9d\u8d56\u4e8e\u5916\u90e8\u72b6\u6001\uff0c\u56e0\u6b64\uff0c\u6211\u4eec\u5e38\u5e38\u8bf4\u51fd\u6570\u5f0f\u7f16\u7a0b\u6ca1\u6709\u526f\u4f5c\u7528\u3002\n<\/p>\n<p>\n\t\u6ca1\u6709\u526f\u4f5c\u7528\u6709\u4e2a\u5de8\u5927\u7684\u597d\u5904\uff0c\u5c31\u662f\u51fd\u6570\u5185\u90e8\u65e0\u72b6\u6001\uff0c\u5373\u8f93\u5165\u786e\u5b9a\uff0c\u8f93\u51fa\u5c31\u662f\u786e\u5b9a\u7684\uff0c\u5bb9\u6613\u6d4b\u8bd5\u548c\u7ef4\u62a4\u3002\n<\/p>\n<p>\n\t\u4e0b\u9762\u6211\u4eec\u901a\u8fc7\u4e00\u4e2a\u4f8b\u5b50\u6765\u770b\u5b83\u7684\u597d\u5904\uff01\n<\/p>\n<p>\n\t\u6bd4\u5982\u4e00\u4e2a\u8d22\u52a1\u8f6f\u4ef6\uff0c\u9700\u8981\u4e00\u4e2a\u51fd\u6570\u4e13\u95e8\u8ba1\u7b97\u4e2a\u4eba\u6240\u5f97\u7a0e\uff0c\u8f93\u5165\u662f\u4e00\u4e2a IncomeRecord\uff0c\u8f93\u51fa\u662f\u4e2a\u7a0e\u91d1\u989d\uff1a\n<\/p>\n<pre class=\"brush:java;\">\r\ndouble calculateIncomeTax(IncomeRecord record) {\r\n    \/\/ \u7701\u7565\u5177\u4f53\u5b9e\u73b0\r\n}<\/pre>\n<p>\n\t\u7136\u540e\u5047\u8bbe IncomeRecord \u957f\u8fd9\u6837\uff1a\n<\/p>\n<pre class=\"brush:java;\">\r\nclass IncomeRecord {\r\n    String carId; \/\/ \u8eab\u4efd\u8bc1\u53f7\r\n    String name; \/\/ \u59d3\u540d\r\n    double salary; \/\/ \u5de5\u8d44\r\n    String address;\/\/ \u5730\u533a\r\n}<\/pre>\n<p>\n\t\u7136\u540e\uff0c\u6211\u4eec\u4e0d\u8003\u8651\u5176\u5b83\u7684\u793e\u4fdd\u3001\u516c\u79ef\u91d1\u7b49\u4e71\u4e03\u516b\u7cdf\u7684\u4e1c\u897f\u5185\u5bb9\u3002\u6211\u4eec\u53ea\u7b80\u5316\u4e3a\uff0c\u6263\u51cf\u4e00\u4e2a\u514d\u5f81\u989d\u540e\u591a\u6708\u7684\u6309 20% \u7684\u7a0e\u6536\u8ba1\u7b97\u3002\n<\/p>\n<pre class=\"brush:java;\">\r\ndouble threshold = 3500; \/\/ \u514d\u5f81\u989d\r\ndouble calculateIncomeTax(IncomeRecord record) {\r\n    if(record.salary &lt;= threshold){\r\n    \treturn 0;\r\n    }else{\r\n    \treturn (record.salary - threshold) * 0.2;\r\n    }\r\n}<\/pre>\n<p>\n\t\u4e0a\u9762\u8fd9\u4e2a\u7a0b\u5e8f\u5728 2018 \u5e74 10 \u6708 1 \u53f7\u524d\u662f\u6ca1\u95ee\u9898\u7684\uff0c\u95ee\u9898\u662f 2018 \u5e74 10 \u6708 1 \u53f7\u540e\u8d77\u5f81\u70b9\u8c03\u6574\u5230\u4e86 5000\uff0c\u90a3 2018 \u5e74 9 \u6708\u548c 2018 \u5e74 10 \u6708\uff0c\u8ba1\u7b97\u7ed3\u679c\u5e94\u8be5\u4e0d\u4e00\u6837\u3002\u4e0a\u9762\u7684\u7a0e\u6536\u65b9\u5f0f\u5c31\u9700\u8981\u8c03\u6574\uff1f\u600e\u4e48\u8c03\u6574\u5462\uff1f\n<\/p>\n<pre class=\"brush:java;\">\r\ndouble threshold = today() &lt; date(2018, 10, 1) ? 3500 : 5000; \/\/ \u514d\u5f81\u989d\r\ndouble calculateIncomeTax(IncomeRecord record) {\r\n    if(record.salary &lt;= threshold){\r\n    \treturn 0;\r\n    }else{\r\n    \treturn (record.salary - threshold) * 0.2;\r\n    }\r\n}<\/pre>\n<p>\n\t\u8fd9\u6837\u6539\u4ee3\u7801\uff0c\u770b\u8d77\u6765\u6ca1\u9519\uff0c\u4f46\u662f\u5728\u5b9e\u9645\u8fd0\u884c\u4e2d\uff0c\u53ef\u80fd\u4f1a\u51fa\u95ee\u9898\u3002\n<\/p>\n<p>\n\t\u6bd4\u5982\uff0c\u6211\u4eec 10 \u6708\u4efd\uff0c\u5b9e\u9645\u4e0a\u53d1\u7684\u662f 9 \u6708\u4efd\u7684\u5de5\u8d44\u5427\u3002\u8fd9\u4e2a\u7cfb\u7edf\uff0c\u5728 9 \u6708 30 \u53f7\u8dd1\uff0c\u548c 10 \u6708 1 \u53f7\u8dd1\uff0c\u7ed3\u679c\u4e0d\u4e00\u6837\u3002\u6bd4\u5982\uff0c\u6211\u4eec\u5728 10 \u6708 2 \u53f7\u8fd9\u5929\u53d1\u5de5\u8d44\u3002\u4f46\u662f\u8fd9\u6b21\u53d1\u5de5\u8d44\u6211\u4eec\u662f\u6309\u7167\u4e0a\u6708\u7684\u8003\u52e4\u6765\u7edf\u8ba1\u4e2a\u7a0e\u7684\uff0c\u7136\u540e\u4f1a\u8ba1\u8981\u5728 10 \u6708 1 \u53f7\u505a 9 \u6708\u4efd\u7684\u5de5\u8d44\u6761\uff0c\u548c 9 \u6708 30 \u53f7\u505a\u5de5\u8d44\u6761\uff0c\u7ed3\u679c\u5e76\u4e0d\u4e00\u81f4\u3002\u96be\u9053\u8981\u6c42\u4f1a\u8ba1\u5fc5\u987b\u628a\u7535\u8111\u7684\u65f6\u95f4\u5148\u8c03\u5230 9 \u6708\u4efd\uff1f\n<\/p>\n<p>\n\t\u6240\u4ee5\uff0c\u8fd9\u4e2a\u95ee\u9898\uff0c\u6211\u4eec\u7528\u51fd\u6570\u5f0f\u7f16\u7a0b\u601d\u7ef4\u5c31\u5f88\u597d\u89e3\u51b3\u4e86\u3002calculateIncomeTax() \u4e0d\u518d\u662f\u4e00\u4e2a\u7eaf\u51fd\u6570\uff0c\u5b83\u4e0e\u5f53\u524d\u65f6\u95f4\u76f8\u5173\u4e86\u3002\u73b0\u5728\u6211\u4eec\u628a\u5b83\u53d8\u6210\u4e00\u4e2a\u7eaf\u51fd\u6570\u3002\n<\/p>\n<pre class=\"brush:java;\">\r\nclass IncomeRecord {\r\n    String id; \/\/ \u8eab\u4efd\u8bc1\u53f7\r\n    String name; \/\/ \u59d3\u540d\r\n    double salary; \/\/ \u5de5\u8d44\r\n    String address;\/\/ \u5730\u533a\r\n    int year; \/\/ \u5e74\r\n    int month; \/\/ \u6708\r\n}<\/pre>\n<p>\n\tcalculateIncomeTax \u51fd\u6570\u4e5f\u5728\u8c03\u6574\u4e00\u4e0b\uff1a\n<\/p>\n<pre class=\"brush:java;\">\r\ndouble calculateIncomeTax(IncomeRecord record) {\r\n    double threshold = date(record.year, record.month) &lt; date(2018, 10) ? 3500 : 5000;\r\n    if(record.salary &lt;= threshold){\r\n        return 0;\r\n    }else{\r\n        return (record.salary - threshold) * 0.2;\r\n    }\r\n}<\/pre>\n<p>\n\t\u867d\u7136\u8fd9\u4e2a\u95ee\u9898\uff0c\u4e0d\u7528\u51fd\u6570\u5f0f\u7f16\u7a0b\u4e5f\u80fd\u89e3\u51b3\u3002\u4f46\u662f\u62e5\u6709\u51fd\u6570\u5f0f\u7f16\u7a0b\u601d\u7ef4\u6bd4\u89e3\u51b3\u95ee\u9898\u672c\u8eab\u66f4\u91cd\u8981\u3002\n<\/p>\n<p>\n\t\u603b\u7684\u6765\u8bf4\uff0c\u51fd\u6570\u5f0f\u7f16\u7a0b\u5f3a\u8c03\u5c06\u8ba1\u7b97\u8fc7\u7a0b\u5206\u89e3\u6210\u53ef\u590d\u7528\u7684\u51fd\u6570\uff0c\u5178\u578b\u4f8b\u5b50\u5c31\u662f&nbsp;map \u65b9\u6cd5\u548c reduce<code>&nbsp;<\/code>\u65b9\u6cd5\u7ec4\u5408\u800c\u6210&nbsp;<a href=\"https:\/\/zh.wikipedia.org\/wiki\/MapReduce\" target=\"_blank\">MapReduce \u7b97\u6cd5<\/a>\u3002\u66f4\u591a\u51fd\u6570\u5f0f\u7f16\u7a0b\u77e5\u8bc6\uff0c\u8bf7\u53c2\u8003\u6211\u7684 <a href=\"https:\/\/www.xttblog.com\/spring-webflux.html\" name=\"WebFlux \u6559\u7a0b\" target=\"_blank\" title=\"WebFlux \u6559\u7a0b\">WebFlux \u6559\u7a0b<\/a>\uff01<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=3740\">\u51fd\u6570\u5f0f\u7f16\u7a0b\u7684\u539f\u7406\u548c\u4f18\u70b9<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u6211\u5728 WebFlux \u6559\u7a0b\u4e2d\u5df2\u7ecf\u9610\u660e\u4e86\u4e00\u79cd\u89c2\u70b9\uff0c\u51fd\u6570\u5f0f\u7f16\u7a0b\uff08Functional programming\uff09\u5c06\u6210 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,435],"tags":[1708,1701,621,1200,629],"class_list":["post-3740","post","type-post","status-publish","format-standard","hentry","category-java","category-xpcode","tag-webfilter","tag-webflux","tag-621","tag-1200","tag-629"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3740","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3740"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3740\/revisions"}],"predecessor-version":[{"id":3741,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3740\/revisions\/3741"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3740"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3740"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3740"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}