Collections扩展——commons
DogJay
2017-07-15
【后端技术】
522人已围观
一、下载
http://commons.apache.org/collections/
二、文档制作:HugeChm
三、扩展
1、解耦 函数式编程
1)、Predicate 断言
封装条件或判别式 if..else替代
a)、 new EqualPredicate<类型>(值)
EqualPredicate.equalPredicate(值);
b)、NotNullPredicate.INSTANCE
c)、UniquePredicate.uniquePredicate()
d)、自定义
new Predicate() +evaluate
PredicateUtils.allPredicate andPredicate anyPredicate
PredicatedXxx.predicatedXxx(容器,判断)
2)、Transformer 类型转化
a)、new Transformer() +transform
b)、SwitchTransformer
CollectionUtils.collect(容器,转换器)
3)、 Closure 闭包 封装特定的业务功能
a)、Closure
b)、IfClosure IfClosure.ifClosure(断言,功能1,功能2)
c)、WhileClosure WhileClosure.whileClosure(断言,功能,标识)
d)、ChainedClosure.chainedClosure(功能列表);
CollectionUtils.forAllDo(容器,功能类对象);
2、集合操作
1)、并集
CollectionUtils.union();
2)、交集
CollectionUtils.intersection();
CollectionUtils.retainAll();
3)、差集
CollectionUtils.subtract();
3、Queue队列
1)、循环队列:CircularFifoQueue
2)、只读队列:不可改变队列 UnmodifiableQueue
3)、断言队列:PredicatedQueue.predicatedQueue()
4、迭代器的扩展
1)、MapIterator 以后不再使用map.keySet.iterator访问
IterableMap HashedMap
2)、UniqueFilterIterator 去重迭代器
3)、FilterIterator 自定义过滤 +Predicate
4)、LoopingIterator 循环迭代器
5)、ArrayListIterator 数组迭代器
5、双向Map 要求键与值都不能重复
BidiMap inverseBidiMap()
1)、DualTreeBidiMap :有序
2)、DualHashBidiMap :无序
6、Bag 包 允许重复
1)、HashBag 无序
2)、TreeBag 有序
统计单词的出现次数
吐槽(0)