{"id":457,"date":"2016-04-23T20:06:47","date_gmt":"2016-04-23T12:06:47","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=457"},"modified":"2016-04-23T20:06:47","modified_gmt":"2016-04-23T12:06:47","slug":"google-guava%e5%ba%93%e7%94%a8%e6%b3%95%e5%a4%a7%e5%85%a8","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=457","title":{"rendered":"Google Guava\u5e93\u7528\u6cd5\u5927\u5168"},"content":{"rendered":"<p>\n\t\u5199java\u4ee3\u7801\u5199\u591a\u4e86\uff0c\u4f60\u5c31\u4f1a\u53d1\u73b0java\u4ee3\u7801\u6216\u8bed\u6cd5\u6709\u5f88\u591a\u53ef\u4ee5\u6539\u8fdb\u7684\u5730\u65b9\uff0c\u5305\u62ec\u4e00\u4e9b\u8bed\u6cd5\u4e0a\u7684\u91cd\u590d\u5b9a\u4e49\u7b49\u3002\u91cd\u590d\u7684\u53d1\u660e\u8f6e\u5b50\uff0c\u5c31\u4f1a\u8ba9\u5927\u5bb6\u611f\u5230\u538c\u70e6\u3002\u4e3a\u4e86\u4e0d\u518d\u5fcd\u53d7\u75db\u82e6\uff0c\u6211\u4eec\u53ef\u4ee5\u603b\u7ed3\u81ea\u5df1\u7684\u7c7b\u5e93\uff0c\u968f\u7740\u65f6\u95f4\u7684\u63a8\u79fb\u6211\u4eec\u9700\u8981\u4e0d\u65ad\u7684\u5bf9\u7c7b\u5e93\u8fdb\u884c\u5347\u7ea7\u7ef4\u62a4\u3002\u8fd9\u5bf9\u4e8e\u5927\u591a\u6570\u4eba\u6765\u8bf4\uff0c\u662f\u707e\u96be\u6027\u7684\u3002\u8fd9\u662fGoogle\u516c\u53f8\u7ad9\u51fa\u6765\u4e86\uff0cguava\u6b63\u662f\u51fa\u4e8e\u8fd9\u6837\u7684\u76ee\u7684\u800c\u6765\u89e3\u653e\u6211\u4eec\u7684\u75db\u82e6\u7684\u3002<br \/>\n\t<strong>Guava\u662f\u4e00\u4e2a\u5f00\u6e90\u7684Java\u5e93\uff0c\u5176\u4e2d\u7684\u6838\u5fc3\u5e93\u90fd\u662f\u7531\u8c37\u6b4c\u63d0\u4f9b\u7684\u3002Guava\u5e93\u63d0\u4f9b\u4e86\u7528\u4e8e\u96c6\u5408\u3001\u7f13\u5b58\u3001\u539f\u751f\u7c7b\u578b\u3001\u5e76\u53d1\u3001\u5e38\u7528\u6ce8\u89e3\u3001\u57fa\u672c\u5b57\u7b26\u4e32\u64cd\u4f5c\u548cI\/O\u7b49\u65b9\u6cd5\u3002<\/strong><br \/>\n\t<strong>Guava\u7684\u597d\u5904<\/strong><br \/>\n\t&nbsp;&nbsp; &nbsp;<span style=\"color:#FF0000\">\u6807\u51c6\u5316 &#8211; Guava\u5e93\u662f\u7531\u8c37\u6b4c\u6258\u7ba1\u3002<br \/>\n\t&nbsp;&nbsp; &nbsp;\u9ad8\u6548 &#8211; \u53ef\u9760\uff0c\u5feb\u901f\u548c\u6709\u6548\u7684\u6269\u5c55JAVA\u6807\u51c6\u5e93<br \/>\n\t&nbsp;&nbsp; &nbsp;\u4f18\u5316 -Guava\u5e93\u7ecf\u8fc7\u9ad8\u5ea6\u7684\u4f18\u5316\u3002<br \/>\n\t&nbsp;&nbsp; &nbsp;\u51fd\u6570\u5f0f\u7f16\u7a0b -\u589e\u52a0JAVA\u529f\u80fd\u548c\u5904\u7406\u80fd\u529b\u3002<br \/>\n\t&nbsp;&nbsp; &nbsp;\u5b9e\u7528\u7a0b\u5e8f &#8211; \u63d0\u4f9b\u4e86\u7ecf\u5e38\u9700\u8981\u5728\u5e94\u7528\u7a0b\u5e8f\u5f00\u53d1\u7684\u8bb8\u591a\u5b9e\u7528\u7a0b\u5e8f\u7c7b\u3002<br \/>\n\t&nbsp;&nbsp; &nbsp;\u9a8c\u8bc1 -\u63d0\u4f9b\u6807\u51c6\u7684\u6545\u969c\u5b89\u5168\u9a8c\u8bc1\u673a\u5236\u3002<br \/>\n\t&nbsp;&nbsp; &nbsp;\u6700\u4f73\u5b9e\u8df5 &#8211; \u5f3a\u8c03\u6700\u4f73\u7684\u505a\u6cd5\u3002<\/span><br \/>\n\t\u4e0b\u9762\u4e3e\u4f8b\u8bf4\u8bf4Guava\u7684\u5b9e\u9645\u7528\u6cd5\uff1a<br \/>\n\t<strong>\u9488\u5bf9\u53ef\u53d8\u96c6\u5408\u7684\u58f0\u660e<\/strong>\n<\/p>\n<pre class=\"brush:java;\">\r\nMap&lt;String, Map&lt;Long, List&lt;String&gt;&gt;&gt; java = new HashMap&lt;String, Map&lt;Long,List&lt;String&gt;&gt;&gt;(); &nbsp;\r\nMap&lt;String, Map&lt;Long, List&lt;String&gt;&gt;&gt; guava = Maps.newHashMap();<\/pre>\n<p>\n\t<strong>\u9488\u5bf9\u4e0d\u53ef\u53d8\u96c6\u5408<\/strong>\n<\/p>\n<pre class=\"brush:java;\">\r\nList&lt;String&gt; list = new ArrayList&lt;String&gt;();\r\nlist.add(&quot;java&quot;);\r\nlist.add(&quot;b&quot;);\r\nlist.add(&quot;c&quot;);\r\nlist.add(&quot;d&quot;);\r\nImmutableList&lt;String&gt; of = ImmutableList.of(&quot;guava&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;);\r\nImmutableMap&lt;String,String&gt; map = ImmutableMap.of(&quot;xttblog&quot;, &quot;\u4e1a\u4f59\u8349&quot;, &quot;key2&quot;, &quot;value2&quot;);<\/pre>\n<p>\n\t<strong>ImmutableList.copyOf<\/strong>\n<\/p>\n<pre class=\"brush:java;\">\r\npublic java(Address from, Address to, List&lt;Step&gt; steps) {\r\n&nbsp;&nbsp; &nbsp;this.from = from;\r\n&nbsp;&nbsp; &nbsp;this.to = to;\r\n&nbsp;&nbsp; &nbsp;this.steps = Collections.unmodifiableList(new ArrayList&lt;Step&gt;(steps));\r\n}\r\npublic guava(Address from, Address to, List&lt;Step&gt; steps) {\r\n&nbsp; &nbsp; this.from = from;\r\n&nbsp; &nbsp; this.to = to;\r\n&nbsp; &nbsp; this.steps = ImmutableList.of(steps);\r\n}<\/pre>\n<p>\n\t<strong>Iterables.concat()<\/strong>&nbsp;\n<\/p>\n<pre class=\"brush:java;\">\r\npublic boolean java() {\r\n&nbsp; &nbsp; List&lt;Xttblog&gt; list = new ArrayList&lt;Xttblog&gt;();\r\n&nbsp; &nbsp; list.addAll(getList0());\r\n&nbsp; &nbsp; list.addAll(getList1());\r\n&nbsp; &nbsp; for (Xttblog item : list) {\r\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if (item.text() == &quot;\u4e1a\u4f59\u8349&quot;) {\r\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return true;\r\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}\r\n&nbsp; &nbsp; }\r\n&nbsp; &nbsp; return false;\r\n}\r\npublic boolean guava() {\r\n&nbsp; &nbsp; for (Xttblog item : Iterables.concat(getList0(), getList1())) {\r\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if (item.text() == &quot;\u4e1a\u4f59\u8349&quot;) {\r\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return true;\r\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}\r\n&nbsp; &nbsp; }\r\n&nbsp; &nbsp; return false;\r\n}<\/pre>\n<p>\n\t<strong>\u5b57\u7b26\u4e32\u6bd4\u8f83<\/strong>\n<\/p>\n<pre class=\"brush:java;\">\r\nif(str !=null &amp;&amp; !str.isEmpty()){\r\n&nbsp; &nbsp; \/\/java\r\n}\r\nif(!Strings.isNullOrEmpty(str)){\r\n&nbsp; &nbsp; \/\/guava\r\n}<\/pre>\n<p>\n\t<strong>Jioner<\/strong>\n<\/p>\n<pre class=\"brush:java;\">\r\nString join=&quot;-&quot;,java= &quot;2016&quot;+join+&quot;04&quot;+join+&quot;23&quot;;\r\nString guava = Joiner.on(join).join(&quot;2016&quot;, &quot;04&quot;, &quot;23&quot;);<\/pre>\n<p>\n\t<strong>Splitter<\/strong>\n<\/p>\n<pre class=\"brush:java;\">\r\n\/\/java\r\nString str=&quot;java,guava,\u4e1a\u4f59\u8349&quot;;\r\nString [] java=str.split(&quot;,&quot;);\r\n\/\/Guava\r\nSplitter.on(&quot;,&quot;).split(&quot;java,guava,\u4e1a\u4f59\u8349&quot;); \/\/\u7ed3\u679c\u8fd4\u56deIterable&lt;String&gt; &nbsp;\r\n\/\/\u5c06\u7ed3\u679c\u4e2d\u7684\u5143\u7d20trim &nbsp;&nbsp;\r\nSplitter.on(&quot;,&quot;).trimResults().split(&quot;java , guava,\u4e1a\u4f59 \u8349&quot;); &nbsp;&nbsp;\r\n\/\/\u5ffd\u7565\u7a7a\u5b57\u7b26\u4e32\r\nSplitter.on(&quot;,&quot;).omitEmptyStrings().split(&quot;java,guava,,\u4e1a\u4f59\u8349&quot;);&nbsp;<\/pre>\n<p>\n\t<strong>Preconditions<\/strong>\n<\/p>\n<pre class=\"brush:java;\">\r\nif (count &lt;= 0) {\/\/java\r\n&nbsp;&nbsp; &nbsp;throw new IllegalArgumentException(&quot;must be positive: &quot; + count); &nbsp;\r\n}&nbsp;\r\n\/\/guava\r\nPreconditions.checkArgument(count &gt; 0, &quot;must be positive: %s&quot;, count);<\/pre>\n<p>\n\t<strong>I\/O\u64cd\u4f5c<\/strong>\n<\/p>\n<pre class=\"brush:java;\">\r\nInputStream from;\r\nOutputStream to;\r\n\/\/...\r\nByteStreams.copy(from,to);\r\nReader from;\r\nWriter to;\r\n\/\/...\r\nCharStreams.copy(from, to);\r\nFile from;\r\nFile to;\r\n\/\/...\r\nFiles.copy(from, to);\r\n\/\/\u5220\u9664\u6587\u4ef6\u5939\u4e0b\u7684\u5185\u5bb9(\u5305\u62ec\u6587\u4ef6\u4e0e\u5b50\u6587\u4ef6\u5939)\r\nFiles.deleteDirectoryContents(File directory);&nbsp;\r\n\/\/\u5220\u9664\u6587\u4ef6\u6216\u8005\u6587\u4ef6\u5939\r\nFiles.deleteRecursively(File file);&nbsp;\r\n\/\/\u79fb\u52a8\u6587\u4ef6\r\nFiles.move(File from, File to);&nbsp;<\/pre>\n<p>\n\t<strong>\u7248\u6743\u58f0\u660e\uff1a\u672c\u6587\u4e3a\u535a\u4e3b\u539f\u521b\u6587\u7ae0\uff0c\u672a\u7ecf\u535a\u4e3b\u5141\u8bb8\u4e0d\u5f97\u8f6c\u8f7d\u3002<\/strong>\u539f\u6587\u5730\u5740\uff1a<a href=\"http:\/\/www.xttblog.com\/?p=457\" target=\"_blank\">http:\/\/www.xttblog.com\/?p=457<\/a><\/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=457\">Google Guava\u5e93\u7528\u6cd5\u5927\u5168<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u5199java\u4ee3\u7801\u5199\u591a\u4e86\uff0c\u4f60\u5c31\u4f1a\u53d1\u73b0java\u4ee3\u7801\u6216\u8bed\u6cd5\u6709\u5f88\u591a\u53ef\u4ee5\u6539\u8fdb\u7684\u5730\u65b9\uff0c\u5305\u62ec\u4e00\u4e9b\u8bed\u6cd5\u4e0a\u7684\u91cd\u590d\u5b9a\u4e49\u7b49\u3002\u91cd\u590d\u7684\u53d1\u660e [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[186,187],"class_list":["post-457","post","type-post","status-publish","format-standard","hentry","category-java","tag-guava","tag-java"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/457","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=457"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/457\/revisions"}],"predecessor-version":[{"id":458,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/457\/revisions\/458"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=457"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=457"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=457"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}