|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
CollectionSqueezer.java | 83.3% | 90% | 100% | 90% |
|
1 |
/*
|
|
2 |
* Joey and its relative products are published under the terms
|
|
3 |
* of the Apache Software License.
|
|
4 |
*/
|
|
5 |
package org.asyrinx.brownie.core.collection;
|
|
6 |
|
|
7 |
import java.util.Collection;
|
|
8 |
import java.util.Iterator;
|
|
9 |
|
|
10 |
import org.apache.commons.collections.Predicate;
|
|
11 |
|
|
12 |
/**
|
|
13 |
* コレクションから条件に従って要素を抽出するクラスです。
|
|
14 |
*
|
|
15 |
* @author akima
|
|
16 |
*/
|
|
17 |
public class CollectionSqueezer { |
|
18 |
|
|
19 |
/**
|
|
20 |
* @param filter
|
|
21 |
*/
|
|
22 | 1 |
public CollectionSqueezer() {
|
23 | 1 |
this(null); |
24 |
} |
|
25 |
|
|
26 |
/**
|
|
27 |
* @param filter
|
|
28 |
*/
|
|
29 | 7 |
public CollectionSqueezer(Predicate filter) {
|
30 | 7 |
super();
|
31 | 7 |
this.filter = filter;
|
32 |
} |
|
33 |
|
|
34 |
private Predicate filter;
|
|
35 |
|
|
36 |
/**
|
|
37 |
* 抽出を実行します。
|
|
38 |
*
|
|
39 |
* @param iterator
|
|
40 |
* 抽出もととなるiterator
|
|
41 |
* @param destinationt
|
|
42 |
* 抽出された要素を格納するCollection
|
|
43 |
* @see org.asyrinx.util.Filter#execute(java.util.Iterator,
|
|
44 |
* java.util.Collection)
|
|
45 |
*/
|
|
46 | 7 |
public void execute(Iterator iterator, Collection destination) { |
47 | 7 |
while (iterator.hasNext()) {
|
48 | 34 |
Object element = iterator.next(); |
49 | 34 |
if (evaluate(element))
|
50 | 23 |
destination.add(element); |
51 |
} |
|
52 |
} |
|
53 |
|
|
54 |
/**
|
|
55 |
* 抽出対象かどうかを判断します。 filterが指定されている場合はそれを用いて判断します。
|
|
56 |
*
|
|
57 |
* @param element
|
|
58 |
* @return
|
|
59 |
*/
|
|
60 | 28 |
protected boolean evaluate(Object element) { |
61 | 28 |
if (filter != null) |
62 | 28 |
return filter.evaluate(element);
|
63 |
else
|
|
64 | 0 |
return false; |
65 |
} |
|
66 |
} |
|