http://commons.apache.org/proper/commons-lang/javadocs/api-3.1/index.html
2.toString方法,ReflectionToStringBuilder.toString(obj)能夠按默認格式打印對象的內容,也能夠用toStringBuilder.append來設置打印的內容,並能夠設置ToStringBuilder的ToStringStyle。
3.hashCode方法,能夠用new HashCodeBuilder(17,37).append(firstName).append(lastName).toHashCode()方法來生成hashCode,若是要讓對象的全部field都做用於hashCode,能夠調用HashCodeBuilder.reflectionHashCode(obj).
4.isEquals方法,EqualsBuilder用法相似HashCodeBuilder,能夠用append(支持全部原始類型及對象,也支持數組比較元素),也能夠用reflectionEquals(this,obj)來比較對象的每一個field。
5.compareTo方法,用於排序或比較對象,CompareToBuilder.reflectionCompare(this,obj)比較的是對象的field,不考慮static field和transient field,注意若是是append(first,obj.first).append(last,obj.last).toComparison()方法,則有一個比較順序問題,是從最後一個append開始往前比較,只有當前比較的的結果相同時纔會比較前一個append的值。固然,若是要比較bean能夠用BeanComparator,更細緻的比較能夠chain Comparetor......
6.ArrayUtils實用方法簡介,具體可參考:
1.toString方法打印數組內容
2.clone出徹底新的數組
3.reverse反轉數組元素,Java提供的Collections.reverse參數是list
4.clone方法,內部調用了java自帶的clone方法,只是對null作了判斷,若是是null則返回null
5.toObject/toPrimitive方法提供了裝箱與拆箱方法,java1.5後用不上了
6.contains/indexOf/lastIndexOf用於判斷某數是否在數組中以及查找其位置,對象比較內部使用的是object.equals方法
7.toMap方法,能夠將一個二維數組轉換爲map,第二維的數組必須至少有兩個元素,第一個爲key,第二個爲value
7.日期操做函數,用DataFormatUtils的多種格式建立線程安全的FastDateFormat來替換java原生的線程不安全的SimpleDateFormat.通常來講Sun提供的全部format類好比SimpleDateFormat,MessageFormat,NumberFormat,DecimalFOrmat,CoiceFormat等都是線程不安全的,DateUtils提供的一下實用方法:
1.靈活的set方法,方便設置年月日,時間等
2.round四捨五入及ceil去尾數法
3.turncate能夠清除到指定時間幅度的值,好比將2014-1-8 23:06:03 作小時truncate會到2014-1-8 23:00:00
8.Validate類能夠提供一些基本的爲空,非null,數組範圍,正則等,若是驗不過則拋出exception,能夠在方法中作斷言用,能夠配Range範圍類來作一些邊界等判斷
9.StopWatch方法能夠像秒錶同樣提供時間的準確計算,能夠用在程序耗時方面,固然用System.nanoTime也能夠來作,可是StopWatch提供的start,stop,split等方式更具可讀性。
10.StringUtils處理字符串,主要方法以下:
-
abbreviate 縮寫
- IsEmpty/IsBlank - checks if a String contains text
- Trim/Strip - removes leading and trailing whitespace,strip提供了豐富的截除部分字符串的功能
- Equals - compares two strings null-safe
- startsWith - check if a String starts with a prefix null-safe
- endsWith - check if a String ends with a suffix null-safe
- IndexOf/LastIndexOf/Contains - null-safe index-of checks
- IndexOfAny/LastIndexOfAny/IndexOfAnyBut/LastIndexOfAnyBut - index-of any of a set of Strings
- ContainsOnly/ContainsNone/ContainsAny - does String contains only/none/any of these characters
- Substring/Left/Right/Mid - null-safe substring extractions
- SubstringBefore/SubstringAfter/SubstringBetween - substring extraction relative to other strings
- Split/Join - splits a String into an array of substrings and vice versa
- repeat 克隆字符
- Remove/Delete - removes part of a String
- Replace/Overlay - Searches a String and replaces one String with another
- Chomp/Chop - removes the last part of a String
- LeftPad/RightPad/Center/Repeat - pads a String
- UpperCase/LowerCase/SwapCase/Capitalize/Uncapitalize - changes the case of a String
- CountMatches - counts the number of occurrences of one String in another
- IsAlpha/IsNumeric/IsWhitespace/IsAsciiPrintable - checks the characters in a String
- DefaultString - protects against a null input String
- Reverse/ReverseDelimited - reverses a String
- Abbreviate - abbreviates a string using ellipsis
- Difference/indexOfDifference - compares Strings and reports on their differences
- LevenshteinDistance - the number of changes needed to change one String into another
11.WordUtils提供對字符串大小寫轉換,縮寫等操做,方法capitalize/uncapitalize/swapCase/initials等
12 Lang All Classes :
AggregateTranslator ,AnnotationUtils ,ArrayUtils ,AtomicInitializer ,AtomicSafeInitializer ,BackgroundInitializer ,BasicThreadFactory ,BasicThreadFactory.Builder ,BitField ,BooleanUtils ,Builder ,CallableBackgroundInitializer ,CharEncoding ,CharSequenceTranslator ,CharSequenceUtils ,CharSet ,CharSetUtils ,CharUtils ,ClassUtils ,CloneFailedException ,CodePointTranslator ,CompareToBuilder ,CompositeFormat ,ConcurrentException ,ConcurrentInitializer ,ConcurrentRuntimeException ,ConcurrentUtils ,ConstantInitializer ,ConstructorUtils ,ContextedException ,ContextedRuntimeException ,DateFormatUtils ,DateUtils ,DefaultExceptionContext ,DurationFormatUtils ,EntityArrays ,EnumUtils ,EqualsBuilder ,EventListenerSupport ,EventUtils ,ExceptionContext ,ExceptionUtils ,ExtendedMessageFormat ,FastDateFormat ,FieldUtils ,FormatFactory ,FormattableUtils ,Fraction ,HashCodeBuilder ,IEEE754rUtils ,ImmutablePair ,JavaVersion ,LazyInitializer ,LocaleUtils ,LookupTranslator ,MethodUtils ,MultiBackgroundInitializer ,MultiBackgroundInitializer.MultiBackgroundInitializerResults ,Mutable ,MutableBoolean ,MutableByte ,MutableDouble ,MutableFloat ,MutableInt ,MutableLong ,MutableObject ,MutablePair ,MutableShort ,NumberUtils ,NumericEntityEscaper ,NumericEntityUnescaper ,NumericEntityUnescaper.OPTION ,ObjectUtils ,ObjectUtils.Null ,OctalUnescaper ,Pair ,RandomStringUtils ,Range ,ReflectionToStringBuilder ,SerializationException ,SerializationUtils ,StandardToStringStyle ,StopWatch ,StrBuilder ,StringEscapeUtils ,StringUtils ,StrLookup ,StrMatcher ,StrSubstitutor ,StrTokenizer ,SystemUtils ,TimedSemaphore ,ToStringBuilder ,ToStringStyle ,TypeUtils ,UnicodeEscaper ,UnicodeUnescaper ,Validate ,WordUtils
// Lang包的一些補充說明: 2014年3月13日
12.1.Fraction是一個分數的類,提供分子分母或分式型的字符串來生成一個Fraction對象,此類封裝了加減乘除,約分,變號,指數等常見的數學操做
12.2.NumberUtil提供了一些字符串解析成各類數字型的方法,包括解析成Number類型,同時提供了參數是各類數組或多個參數裏找出min/max的使用工具方法。Math包也提供了Min/Max類
12.3.Range類提供了抽象類型的範圍類,根據默認或傳入的comparator來肯定範圍和判斷是否屬於此範圍
//----------------------------------------------------Commons Codes --------------------------------------------------
Commons Codes All Classes AbstractCaverphone,Base32,Base32InputStream,Base32OutputStream,Base64,Base64InputStream,Base64OutputStream,BaseNCodec,BaseNCodecInputStream,BaseNCodecOutputStream,BCodec,BeiderMorseEncoder,BinaryCodec,BinaryDecoder,BinaryEncoder,Caverphone,Caverphone1,Caverphone2,CharEncoding,Charsets,ColognePhonetic,Crypt,Decoder,DecoderException,DigestUtils,DoubleMetaphone,Encoder,EncoderException,Hex,Lang,Languages,Languages.LanguageSet,Languages.SomeLanguages,MatchRatingApproachEncoder,Md5Crypt,MessageDigestAlgorithms,Metaphone,NameType,Nysiis,PhoneticEngine,QCodec,QuotedPrintableCodec,RefinedSoundex,Rule,Rule.Phoneme,Rule.PhonemeExpr,Rule.PhonemeList,Rule.RPattern,RuleType,Sha2Crypt,Soundex,StringDecoder,StringEncoder,StringEncoderComparator,StringUtils,UnixCrypt,URLCodec
//----------------------------------------------------Commons BeanUtils--------------------------------------------------
14.beanutils是Struts等web開源框架的最基本思想實現庫,主要用於操做類及屬性,經過發射等手段提供方便對bean的基本工具方法:
15.PropertyUtils主要方法及使用:
- 中提供了獲取bean中普通元素,bean元素,list元素,Map元素的值方法,分別是getSimpleProperty(bean,"name"),getNestedProperty(bean,"ext.balance"),getIndexedProperty(bean,"list[1]"),getMappedProperty(bean,"map(key)"),也能夠直接調用getProperty(bean,"ext.list[0].map(key)")組合的形式,被解析的時候根據具體形式再調用上面的具體方法,相應的set方法使用,尤爲是JEXL的描述用法很方便
- isReadable/isWritable(bean,"name")能夠查看此屬性是否可讀/可寫
- describe方法返回全部get方法可訪問的bean元素到一個Map中,key爲屬性名。BeanMap類經過傳入一個bean構造一個map,在此map上用map的基本方法直接操做bean,酷啊。
16.BeanComparator提供比較具體bean屬性從而排序的方法,此類也支持傳入具體的Comparator實現具體排序的算法
17.克隆bean能夠用PropertyUtils.copyProperties(destBean,sourBean),也能夠直接調用BeanUtils.cloneBean(sourBean)直接返回一個新的bean,可是須要注意,bean裏面若是是對象元素,則對象元素是兩個bean共同"引用"的,也就是在一個bean裏修改了對象元素,另外一個bean能看到。BeanUtils裏有一些和PropertyUtils重複的方法,可是BeanUtils裏的方法能靈活的convert,尤爲是setProperty的時候,如BeanUtils.setProperty(bean,"age","50"),而bean中的age爲int型,若是是用PropertyUtils.setProperty則會報類型錯誤
18.經過設置DynaProperty,DynaClass可用new出一個動態的bean用於靈活的表明一個data model。如能夠經過一個xml文件的配置來建立一個dynabean
19.BeanPredicae能夠利用collections提供的多種類型的Predicate來經過bean中的具體屬性對bean的某些屬性條件進行驗證,全部Predicate的子類:
AbstractQuantifierPredicate, AllPredicate, AndPredicate, AnyPredicate, ComparatorPredicate, EqualPredicate, ExceptionPredicate, FalsePredicate,IdentityPredicate, InstanceofPredicate, NonePredicate, NotNullPredicate, NotPredicate, NullIsExceptionPredicate, NullIsFalsePredicate,NullIsTruePredicate, NullPredicate, OnePredicate, OrPredicate, TransformedPredicate, TransformerPredicate, TruePredicate, UniquePredicate
//----------------------------------------------------Commons Collections--------------------------------------------------
20.ReverseComparator/ComparatorChain/NullComparator/FixedOrderComparator比較器,ComparatorChain能夠add多個comparator,從最後一個add的comparator開始比較直到不爲0,NullComparator經過構造的時候傳入false/ture來比較null對象與其餘對象相比時是-1/1, FixedOrderComparator則是經過預設的數組或list順序來比較傳入的對象,按此預設的值來決定順序
21.PredicateUtil提供了建立多種Predicate對象的方法,用於對bean進行判斷,TransForm用於根據傳入的對象來create 新對象,而Closure則是對傳入的對象進行修改,本質都至關於Decorator模式,根據傳入的對象作一些處理
22.LoopIterator能夠作循環iter,經過設置reset來重置,ArrayListIterator能夠iter部分list,FilterIterator能夠根據Predicate對象對集合遍歷時作一些條件限制,符合條件的才iter,好比UniqueFilterIterator就是一個惟一性遍歷的子實現
23.Bag能夠用來控制對象使用的數量,HashBag/TreeBag
24.一些牛B的Map
25.Predicate*提供了對多種集合進行decorate的驗證的類,用於控制集合的有效性,如PredicatedBag,PredicatedSortedBag,PredicatedCollection,PredicateDecorator,PredicateTransformer,PredicatedList,PredicatedMap,PredicatedSortedMap,PredicatedQueue,PredicatedSet,PredicatedSortedSet
示例:
List list = PredicatedList.decorate(new ArrayList(),new Predicate<String>() {
public boolean evaluate(String str) {
return str.startWith("cfca");
}
}); // PredicatedList繼承了list,並重寫了add方法,在add里加入了驗證
26.能夠利用CollecionUtils裏的transform對Collection系列類裏的元素進行一些轉換,傳入collection及former便可將collection 裏的各元素轉換,此CollecionUtils還有一個方法transformingCollection()用法相似,只不過是返回一個collection,在往此collection加入元素時纔開始進行轉換
CollecionUtils裏一些常見靜態工具方法:
- countMatches(collection,predicate)計算符合predicate的collection中的元素的個數
- cardinality(ele,collection)計算ele在collection出現的次數
- getCardinalityMap(collection)獲得一個map,key爲collection中的元素,value爲每一個元素出現的次數
- union,intersection,disjunction,subtract能夠實現兩個iterable對象的並集,交集,非交集,不包括集
27.LRUMap根據Least Recently Used算法來淘汰放入裏面的元素,注意它是線程不安全的,須要用Collections.synchronized***來保障線程安全。
28.
LazyMap.lazyMap(map,factory) 能夠將一個普通的map轉化成lazymap,即當get的時候若是map裏沒有對應的key,則會調用factory裏面一次生成value放到map中。
29.MapUtils裏封裝了不少轉化成不一樣功能map 的方法:
fixedSizeMap(Map)
fixedSizeSortedMap(SortedMap)
lazyMap(Map,Factory)
lazyMap(Map,Transformer)
lazySortedMap(SortedMap,Factory)
lazySortedMap(SortedMap,Transformer)
predicatedMap(Map,Predicate,Predicate)
predicatedSortedMap(SortedMap,Predicate,Predicate)
transformedMap(Map, Transformer, Transformer)
transformedSortedMap(SortedMap, Transformer, Transformer)
multiValueMap( Map )
multiValueMap( Map, Class )
multiValueMap( Map, Factory )
get***Value能夠將獲得的object或泛型V轉化成***對應的類型,比較方便
//----------------------------------------------------Commons Digester/Betwixt--------------------------------------------------
30.Digester能夠將xml文件轉成javabean,其原理是利用sax棧解析,根據定義好的rules(rules能夠是文件也能夠是Rules實例)
31.rules的做用就是告訴digester的parser當遇到xml中的某個節點時,應該按照什麼方式去解析,是生成對象,仍是設置屬性之類的。
demo:
Digester digester = new Digester();
//設置對XML文檔資料是否進行DTD驗證
digester.setValidating( false );
//當碰見 catalog 元素的時候,產生一個Catalog對象
digester.addObjectCreate( "catalog", Catalog.class );
//當碰見 catalog 元素下面的book的時候,產生一個Book對象
digester.addObjectCreate( "catalog/book", Book.class );
// 當碰見 catalog 元素下面的book的author時候,調用author屬性的Set方法
digester.addBeanPropertySetter( "catalog/book/author", "author" );
digester.addBeanPropertySetter( "catalog/book/title", "title" );
//當再一次碰見 catalog 元素下面的book的時候,調用catalog類的addBook()方法
digester.addSetNext( "catalog/book", "addBook" );
32.若是有多個namespace,則須要分別設置不一樣的namesapce後再設置不一樣的RuleSet,如:
33.全部的rule其實就是根據xpath的規則告訴digester按照不一樣的方式去處理當前處理到的這個節點,其優點相比較於sax在於匹配規則的靈活性及調用的方便性,如digester.addRule("*/email",new EmailRule());這樣在EmailRule能夠經過繼承Rule類來本身重載begin(),body(),end(),finish()等方法來實現特殊操做,好比真發emial。(繼承Rule的方式其實和sax解析實現ContentHandler接口思想是一致的)
34.digester也能夠經過setSubstitutor方法來設置解析時提供的值來替換xml裏相似${name}來實現相似「模板」解析,很方便
//----------------------------------------------------Commons CLI/Configuration--------------------------------------------------
36.cli包能夠方便執行java應用時設置一些命令及參數,相似ls -l,rm -rf之類的,有多中命令方式: