﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-子在川上曰-随笔分类-Jakarta Commons</title><link>http://www.blogjava.net/chengang/category/28246.html</link><description>　　　　逝者如斯夫不舍昼夜</description><language>zh-cn</language><lastBuildDate>Wed, 19 Dec 2007 13:47:21 GMT</lastBuildDate><pubDate>Wed, 19 Dec 2007 13:47:21 GMT</pubDate><ttl>60</ttl><item><title>Jakarta Commons Cookbook笔记（2）</title><link>http://www.blogjava.net/chengang/archive/2007/12/19/168858.html</link><dc:creator>陈刚</dc:creator><author>陈刚</author><pubDate>Wed, 19 Dec 2007 13:11:00 GMT</pubDate><guid>http://www.blogjava.net/chengang/archive/2007/12/19/168858.html</guid><wfw:comment>http://www.blogjava.net/chengang/comments/168858.html</wfw:comment><comments>http://www.blogjava.net/chengang/archive/2007/12/19/168858.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/chengang/comments/commentRss/168858.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/chengang/services/trackbacks/168858.html</trackback:ping><description><![CDATA[
		<h3 class="cjk">日期的格式化</h3>
		<p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;">
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">String
s = DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(new Date())</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;">
				<br />
		</p>
		<h3 class="cjk" style="line-height: 0.55cm; widows: 0; orphans: 0;" align="justify">
日期的四舍五入</h3>
		<p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;">
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">Date
d = DateUtils.round(new Date(), Calendar.HOUR)   --&gt; 
2004-03-28T14:00:00  </font>
				</font>
				<font style="font-size: 10pt;" size="2">（小时四舍五入，分秒被清零）</font>
		</p>
		<p style="margin-bottom: 0cm;">
				<br />
		</p>
		<h3 class="cjk" style="line-height: 0.55cm; widows: 0; orphans: 0;" align="justify">
日期部份清除</h3>
		<p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;">
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">Date
d = DateUtils.truncate(new Date(), Calendar.MONTH)  --&gt; 
2004-03-01T00:00:00  </font>
				</font>
				<font style="font-size: 10pt;" size="2">（日时分秒被清零）</font>
		</p>
		<p style="margin-bottom: 0cm;">
				<br />
		</p>
		<h3 class="cjk">唯一<font face="Arial, sans-serif">ID</font>值的获取</h3>
		<p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;">
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">//</font>
				</font>
				<font style="font-size: 10pt;" size="2">参数</font>
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">1</font>
				</font>
				<font style="font-size: 10pt;" size="2">为</font>
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">true
= </font>
				</font>
				<font style="font-size: 10pt;" size="2">到最大值后会从头开始，参数</font>
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">2=0,</font>
				</font>
				<font style="font-size: 10pt;" size="2">从</font>
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">0</font>
				</font>
				<font style="font-size: 10pt;" size="2">开始</font>
		</p>
		<p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;">
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">LongIdentifierFactory
idf = IdentifierUtils.longGenerator(false,0);  </font>
				</font>
		</p>
		<p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;">
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">idf.nextLongIdentifier()
;</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;">
				<br />
		</p>
		<p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;">
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">StringIdentifierFactory
idf = IdentifierUtils.stringAlphanumericIdentifierFactory(true,4);  </font>
				</font>
		</p>
		<p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm; widows: 0; orphans: 0;" align="justify">
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">idf.nextStringIdentifier();
   --&gt;   0000, 0001 ... 000a ... 001b ....</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;">
				<br />
		</p>
		<p style="margin-bottom: 0cm;">
				<br />
		</p>
		<h3 class="cjk" style="line-height: 0.55cm; widows: 0; orphans: 0;" align="justify">
方法参数检查</h3>
		<p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;">
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">Validate.isTrue(p
&gt;0, "</font>
				</font>
				<font style="font-size: 10pt;" size="2">参数必须大于</font>
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">0")
  //</font>
				</font>
				<font style="font-size: 10pt;" size="2">当</font>
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">p&lt;=0</font>
				</font>
				<font style="font-size: 10pt;" size="2">时，会抛出</font>
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">IllegalArgumentException</font>
				</font>
				<font style="font-size: 10pt;" size="2">异常</font>
		</p>
		<p style="margin-bottom: 0cm;">此外还有<font face="Times New Roman, serif">notEmpty(Object
o)</font>、<font face="Times New Roman, serif">noNullElements(Coolection
c)</font>、<font face="Times New Roman, serif">notNull(Object
o)</font>等方法可用。</p>
		<p style="margin-bottom: 0cm;">
				<br />
		</p>
		<h3 class="cjk"> 秒表</h3>
		<p style="margin-bottom: 0cm;">例<font face="Times New Roman, serif">1</font>、</p>
		<p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;">
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">StopWatch
clock = new StopWatch();</font>
				</font>
		</p>
		<p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;">
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">clock.start();</font>
				</font>
		</p>
		<p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;">
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">...
...</font>
				</font>
		</p>
		<p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;">
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">clock.stop();</font>
				</font>
		</p>
		<p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;">
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">System.out.println("</font>
				</font>
				<font style="font-size: 10pt;" size="2">耗时</font>
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">="
+ clock.getTime());</font>
				</font>
		</p>
		<p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;">
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">clock.reset();
 //</font>
				</font>
				<font style="font-size: 10pt;" size="2">清零后可以再用</font>
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">start()</font>
				</font>
				<font style="font-size: 10pt;" size="2">和</font>
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">stop()</font>
				</font>
				<font style="font-size: 10pt;" size="2">记时</font>
		</p>
		<p style="margin-bottom: 0cm;">
				<br />
		</p>
		<p style="margin-bottom: 0cm;">例<font face="Times New Roman, serif">2</font>、</p>
		<p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;">
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">StopWatch
clock = new StopWatch();</font>
				</font>
		</p>
		<p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;">
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">clock.start();
</font>
				</font>
		</p>
		<p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;">
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">...
...    //</font>
				</font>
				<font style="font-size: 10pt;" size="2">耗时</font>
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">1</font>
				</font>
				<font style="font-size: 10pt;" size="2">秒的语句</font>
		</p>
		<p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;">
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">clock.split();</font>
				</font>
		</p>
		<p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;">
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">System.out.println("</font>
				</font>
				<font style="font-size: 10pt;" size="2">耗时</font>
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">="
+ clock.getTime());   //</font>
				</font>
				<font style="font-size: 10pt;" size="2">打印
</font>
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">1</font>
				</font>
				<font style="font-size: 10pt;" size="2">秒</font>
		</p>
		<p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;">
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">...
...    //</font>
				</font>
				<font style="font-size: 10pt;" size="2">耗时</font>
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">1</font>
				</font>
				<font style="font-size: 10pt;" size="2">秒的语句</font>
		</p>
		<p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;">
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">System.out.println("</font>
				</font>
				<font style="font-size: 10pt;" size="2">耗时</font>
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">="
+ clock.getTime());   // </font>
				</font>
				<font style="font-size: 10pt;" size="2">打印
</font>
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">1</font>
				</font>
				<font style="font-size: 10pt;" size="2">秒</font>
		</p>
		<p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;">
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">clock.unsplit();</font>
				</font>
		</p>
		<p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;">
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">...
...    //</font>
				</font>
				<font style="font-size: 10pt;" size="2">耗时</font>
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">1</font>
				</font>
				<font style="font-size: 10pt;" size="2">秒的语句</font>
		</p>
		<p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;">
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">System.out.println("</font>
				</font>
				<font style="font-size: 10pt;" size="2">耗时</font>
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">="
+ clock.getTime());   //</font>
				</font>
				<font style="font-size: 10pt;" size="2">打印</font>
				<font face="Times New Roman, serif">
						<font style="font-size: 10pt;" size="2">3</font>
				</font>
				<font style="font-size: 10pt;" size="2">秒</font>
		</p>
		<p style="margin-bottom: 0cm;">
				<br />
		</p>
<img src ="http://www.blogjava.net/chengang/aggbug/168858.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/chengang/" target="_blank">陈刚</a> 2007-12-19 21:11 <a href="http://www.blogjava.net/chengang/archive/2007/12/19/168858.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Jakarta Commons Cookbook笔记（1）</title><link>http://www.blogjava.net/chengang/archive/2007/12/18/168591.html</link><dc:creator>陈刚</dc:creator><author>陈刚</author><pubDate>Tue, 18 Dec 2007 13:33:00 GMT</pubDate><guid>http://www.blogjava.net/chengang/archive/2007/12/18/168591.html</guid><wfw:comment>http://www.blogjava.net/chengang/comments/168591.html</wfw:comment><comments>http://www.blogjava.net/chengang/archive/2007/12/18/168591.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/chengang/comments/commentRss/168591.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/chengang/services/trackbacks/168591.html</trackback:ping><description><![CDATA[从图书馆借了《Jakarta Commons Cookbook》，系统的了解了一下Apache的commons包，将一些以后可能会常用到的记录如下。陈刚（www.chengang.com.cn）于2007-12-18.深圳。由于工作平台是Linux，所以是记在OpenOffice里，粘帖过来的时候排版有些失真，也不想修整了，等笔记完成之后直接再出一个PDF版本吧。<br /><br /><h1 class="cjk"><font color="#000000">Jakarta Commons Cookbook笔记</font></h1><h2 class="cjk"><font face="Times New Roman, serif"><font color="#000000">lang</font></font><font color="#000000">包</font></h2><h3 class="cjk"><font face="Arial, sans-serif"><font color="#000000">ReflectionToStringBuilder.</font><font color="#000000"><i>toString</i></font><font color="#000000">()</font></font></h3><p class="cjk"><font color="#000000">例<font face="微软雅黑, Times New Roman">1.</font></font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#000000">ReflectionToStringBuilder.</font><font color="#000000"><i>toString</i></font><font color="#000000">(</font><font color="#7f0055"><b>new</b></font><font color="#161616"></font><font color="#000000">Model())</font></font></p><p class="cjk" style="margin-bottom: 0cm;" align="left"><font color="#000000"><font face="YaHei Consolas Hybrid"><font size="2"><a href="mailto:Model@14318bb">Model@14318bb</a>[url=www.chengang.com.cn,port=80]</font></font></font></p><p class="cjk" style="margin-bottom: 0cm;" align="left"><br /></p><p class="cjk" style="margin-bottom: 0cm;" align="left"><font color="#000000"><font face="YaHei Consolas Hybrid"><font size="2">例</font></font><font face="YaHei Consolas Hybrid"><font size="2">2.</font></font></font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;" align="left"><font color="#000000"><font face="YaHei Consolas Hybrid"><font size="2">ReflectionToStringBuilder.<i>toString</i>(<font color="#7f0055"><b>new</b></font><font color="#161616"></font>Model(),ToStringStyle.<font color="#0000c0"><i>MULTI_LINE_STYLE</i></font>));</font></font></font></p><p class="cjk" style="margin-bottom: 0cm;" align="left"><font color="#000000"><font face="YaHei Consolas Hybrid"><font size="2">Model@14318bb[</font></font></font></p><p class="cjk" style="margin-bottom: 0cm;" align="left"><font color="#000000"><font face="YaHei Consolas Hybrid"><font size="2">url=www.chengang.com.cn</font></font></font></p><p class="cjk" style="margin-bottom: 0cm;" align="left"><font color="#000000"><font face="YaHei Consolas Hybrid"><font size="2">port=80</font></font></font></p><p class="cjk" style="margin-bottom: 0cm;" align="left"><font color="#000000"><font face="YaHei Consolas Hybrid"><font size="2">]</font></font></font></p><p class="cjk" style="margin-bottom: 0cm;" align="left"><br /></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#7f0055"><b>class</b></font><font color="#161616"></font><font color="#000000">Model{</font></font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#161616"></font><font color="#000000">String</font><font color="#161616"></font><font color="#0000c0">url</font><font color="#000000">=</font><font color="#2a00ff">"www.chengang.com.cn"</font><font color="#000000">;</font></font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#161616"></font><font color="#7f0055"><b>int</b></font><font color="#161616"></font><font color="#0000c0">port</font><font color="#000000">=80;</font></font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif">}</font></p><p class="cjk" style="margin-bottom: 0cm;" align="left"><br /></p><h3 class="cjk"><font face="Arial, sans-serif">ToStringBuilder.<i>reflectionToString</i>();</font></h3><p class="cjk" style="margin-bottom: 0cm;" align="left"><font color="#000000"><font face="YaHei Consolas Hybrid"><font size="2">例</font></font><font face="YaHei Consolas Hybrid"><font size="2">1.</font></font></font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif">ToStringBuilder.<i>reflectionToString</i>(<font color="#7f0055"><b>new</b></font><font color="#161616"></font>Model());</font></p><p class="cjk" style="margin-bottom: 0cm;" align="left"><font color="#000000"><font face="YaHei Consolas Hybrid"><font size="2"><a href="mailto:Model@14318bb">Model@14318bb</a>[url=www.chengang.com.cn,port=80]</font></font></font></p><h3 class="cjk">改写类的三方法<font face="Arial, sans-serif">toString</font>、<font face="Arial, sans-serif">hashCode</font>、<font face="Arial, sans-serif">equals</font></h3><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#7f0055"><b>class</b></font><font color="#161616"></font><font color="#000000">Model{</font></font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#161616"></font><font color="#000000">String</font><font color="#161616"></font><font color="#0000c0">url</font><font color="#000000">=</font><font color="#2a00ff">"www.chengang.com.cn"</font><font color="#000000">;</font></font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#161616"></font><font color="#7f0055"><b>int</b></font><font color="#161616"></font><font color="#0000c0">port</font><font color="#000000">=80;</font></font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"></font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#161616"></font><font color="#7f0055"><b>public</b></font><font color="#161616"></font><font color="#000000">String</font><font color="#161616"></font><font color="#000000">toString(){</font></font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#161616"></font><font color="#7f0055"><b>return</b></font><font color="#161616"></font><font color="#7f0055"><b>new</b></font><font color="#161616"></font><font color="#000000">ToStringBuilder(</font><font color="#7f0055"><b>this</b></font><font color="#000000">).append(</font><font color="#2a00ff">"url"</font><font color="#000000">,</font><font color="#0000c0">url</font><font color="#000000">).append(</font><font color="#2a00ff">"port"</font><font color="#000000">,</font><font color="#0000c0">port</font><font color="#000000">).toString();</font></font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#161616"></font><font color="#000000">}</font></font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"></font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#161616"></font><font color="#7f0055"><b>public</b></font><font color="#161616"></font><font color="#7f0055"><b>int</b></font><font color="#161616"></font><font color="#000000">hashCode(){</font></font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font color="#000000"><font face="Times New Roman, serif">//17,37</font></font><font color="#000000">要求为质数</font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#161616"></font><font color="#7f0055"><b>return</b></font><font color="#161616"></font><font color="#7f0055"><b>new</b></font><font color="#161616"></font><font color="#000000">HashCodeBuilder(17,37).append(</font><font color="#0000c0">url</font><font color="#000000">).append(</font><font color="#0000c0">port</font><font color="#000000">).toHashCode();</font></font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#000000">		//
HashCodeBuilder.reflectionHashCode(this);</font></font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#161616"></font><font color="#000000">}</font></font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"></font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#161616"></font><font color="#7f0055"><b>public</b></font><font color="#161616"></font><font color="#7f0055"><b>boolean</b></font><font color="#161616"></font><font color="#000000">equals(Object</font><font color="#161616"></font><font color="#000000">o){		</font></font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#161616"></font><font color="#7f0055"><b>boolean</b></font><font color="#161616"></font><font color="#000000">result</font><font color="#161616"></font><font color="#000000">=</font><font color="#161616"></font><font color="#7f0055"><b>false</b></font><font color="#000000">;</font></font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#161616"></font><font color="#7f0055"><b>if</b></font><font color="#161616"></font><font color="#000000">(o!=</font><font color="#7f0055"><b>null</b></font><font color="#161616"></font><font color="#000000">&amp;&amp;</font><font color="#161616"></font><font color="#000000">Model.</font><font color="#7f0055"><b>class</b></font><font color="#000000">.isAssignableFrom(o.getClass())){</font></font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#161616"></font><font color="#000000">Model</font><font color="#161616"></font><font color="#000000">m</font><font color="#161616"></font><font color="#000000">=</font><font color="#161616"></font><font color="#000000">(Model)o;</font></font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#161616"></font><font color="#000000">result</font><font color="#161616"></font><font color="#000000">=</font><font color="#161616"></font><font color="#7f0055"><b>new</b></font><font color="#161616"></font><font color="#000000">EqualsBuilder().append(</font><font color="#0000c0">url</font><font color="#000000">,</font><font color="#161616"></font><font color="#000000">m.</font><font color="#0000c0">url</font><font color="#000000">).append(</font><font color="#0000c0">port</font><font color="#000000">,</font><font color="#161616"></font><font color="#000000">m.</font><font color="#0000c0">port</font><font color="#000000">).isEquals();</font></font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#161616"></font><font color="#000000">}</font></font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#161616"></font><font color="#7f0055"><b>return</b></font><font color="#161616"></font><font color="#000000">result;</font></font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#000000">		//EqualsBuilder.reflectionEquals(this,o);</font></font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#161616"></font><font color="#000000">}</font></font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#000000"><font face="YaHei Consolas Hybrid"><font size="2">}</font></font></font></font></p><h3 class="cjk"><font face="Arial, sans-serif"><font color="#000000">CompareToBuilder.</font><font color="#000000"><i>reflectionCompare</i></font><font color="#000000">(</font><font color="#7f0055"><b>this</b></font><font color="#000000">,</font><font color="#161616"></font><font color="#000000">o);</font></font></h3><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#161616"><font face="YaHei Consolas Hybrid"><font size="2">	public
int compareTo(Object o){</font></font></font></font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#161616"><font face="YaHei Consolas Hybrid"><font size="2">		return
</font></font></font><font color="#000000"><font face="YaHei Consolas Hybrid"><font size="2">CompareToBuilder.</font></font></font><font color="#000000"><font face="YaHei Consolas Hybrid"><font size="2"><i>reflectionCompare</i></font></font></font><font color="#000000"><font face="YaHei Consolas Hybrid"><font size="2">(</font></font></font><font color="#7f0055"><font face="YaHei Consolas Hybrid"><font size="2"><b>this</b></font></font></font><font color="#000000"><font face="YaHei Consolas Hybrid"><font size="2">,</font></font></font><font color="#161616"><font face="YaHei Consolas Hybrid"><font size="2"></font></font></font><font color="#000000"><font face="YaHei Consolas Hybrid"><font size="2">o);</font></font></font></font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#161616"><font face="YaHei Consolas Hybrid"><font size="2">	}</font></font></font></font></p><p class="cjk" style="margin-bottom: 0cm;"><br /></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#161616"><font face="YaHei Consolas Hybrid"><font size="2">	public
int compareTo(Object o){</font></font></font></font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#161616"><font face="YaHei Consolas Hybrid"><font size="2">		int
result = -1;</font></font></font></font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#161616"><font face="YaHei Consolas Hybrid"><font size="2">		if
(o!=null &amp;&amp; Model.class.isAssignableFrom(o.getClass()){</font></font></font></font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#161616"><font face="YaHei Consolas Hybrid"><font size="2">			Model
m = (Model)o;</font></font></font></font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#161616"><font face="YaHei Consolas Hybrid"><font size="2">			result
= new </font></font></font><font color="#000000"><font face="YaHei Consolas Hybrid"><font size="2">CompareToBuilder().append(url,m.url).append(port,m.port)</font></font></font></font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#000000"><font face="YaHei Consolas Hybrid"><font size="2">.toComparison();</font></font></font></font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#161616"><font face="YaHei Consolas Hybrid"><font size="2">		}</font></font></font></font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#161616"><font face="YaHei Consolas Hybrid"><font size="2">		return
result;</font></font></font></font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#161616"><font face="YaHei Consolas Hybrid"><font size="2">	}</font></font></font></font></p><p class="cjk" style="margin-bottom: 0cm;"><br /></p><h3 class="cjk">打印数组</h3><p class="cjk" style="margin-bottom: 0cm;"><font size="3"><font color="#000000"><font face="YaHei Consolas Hybrid"><font size="2">用</font></font></font></font><font face="Times New Roman, serif"><font size="3"><font color="#000000"><font face="YaHei Consolas Hybrid"><font size="2">commons</font></font></font></font></font><font size="3"><font color="#000000"><font face="YaHei Consolas Hybrid"><font size="2">的：</font></font></font></font><font face="Times New Roman, serif"><font size="3"><font color="#000000"><font face="YaHei Consolas Hybrid"><font size="2">ArrayUtils.</font></font></font>toString<font color="#000000"><font face="YaHei Consolas Hybrid"><font size="2">();</font></font></font></font></font></p><p class="cjk" style="margin-bottom: 0cm;"><font face="YaHei Consolas Hybrid"><font size="2"><font color="#000000">用</font></font></font><font face="YaHei Consolas Hybrid"><font size="2"><font color="#000000">JDK</font></font></font><font face="YaHei Consolas Hybrid"><font size="2"><font color="#000000">的：</font></font></font><font face="YaHei Consolas Hybrid"><font size="2"><font color="#000000">Arrays.</font><font color="#000000"><i>toString</i></font><font color="#000000">();</font></font></font></p><p class="cjk" style="margin-bottom: 0cm;"><br /></p><h3 class="cjk"><font color="#000000">基础类型和包装类型的数组互转</font></h3><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#000000">Long[]
objectArray = ArrayUtils.toObject(primitiveArray);</font></font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#000000">long[]
primitiveArray =  ArrayUtils.toprimitive(objectArray);</font></font></p><h3 class="cjk"><font color="#000000">在数组中查找</font></h3><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#000000">boolean b =
ArrayUtils.contains(stringArray, "glchengang");</font></font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#000000">int  i =
ArrayUtils.indexOf(stringArray, "glchengang");   //</font></font><font color="#000000">找不到返回<font face="Times New Roman, serif">-1</font></font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#000000">int  l =
ArrayUtils.lastIndexOf(stringArray, "glchengang");</font></font></p><h3 class="cjk"><font color="#000000">多维数组转<font face="Arial, sans-serif">Map</font></font></h3><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#000000">Object[]
array = new Object[][]{{"A", new Double(1.007)}, ... ,
{"F", new Double(1.007)}};</font></font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#000000">Map map =
ArrayUtils.toMap(array);</font></font></p><p style="background: rgb(224, 224, 224) none repeat scroll 0% 50%; margin-bottom: 0cm; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 0.46cm;"><font face="Times New Roman, serif"><font color="#000000">Double  d =
map.get("A");</font></font></p><img src ="http://www.blogjava.net/chengang/aggbug/168591.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/chengang/" target="_blank">陈刚</a> 2007-12-18 21:33 <a href="http://www.blogjava.net/chengang/archive/2007/12/18/168591.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>