|
|||||||||||||||||||
| 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 | |||||||||||||||
| MapTreeVisitor.java | 66.7% | 84.2% | 66.7% | 77.4% |
|
||||||||||||||
| 1 |
/*
|
|
| 2 |
* Joey and its relative products are published under the terms
|
|
| 3 |
* of the Apache Software License.
|
|
| 4 |
*/
|
|
| 5 |
/*
|
|
| 6 |
* Created on 2004/01/05
|
|
| 7 |
*/
|
|
| 8 |
package org.asyrinx.brownie.core.collection;
|
|
| 9 |
|
|
| 10 |
import java.util.Iterator;
|
|
| 11 |
import java.util.Map;
|
|
| 12 |
|
|
| 13 |
import org.apache.commons.collections.ArrayStack;
|
|
| 14 |
import org.apache.commons.collections.Closure;
|
|
| 15 |
|
|
| 16 |
/**
|
|
| 17 |
* Mapによるツリー構造に対するアクションを表現するクラスの抽象クラスです。
|
|
| 18 |
* MapTreeオブジェクトと関係しますが、このクラスはMapTreeオブジェクトを使用しません。
|
|
| 19 |
*
|
|
| 20 |
* @author akima
|
|
| 21 |
*/
|
|
| 22 |
public class MapTreeVisitor { |
|
| 23 |
|
|
| 24 |
/**
|
|
| 25 |
*
|
|
| 26 |
*/
|
|
| 27 | 1 |
public MapTreeVisitor(Map root, Closure closure) {
|
| 28 | 1 |
super();
|
| 29 | 1 |
this.root = root;
|
| 30 | 1 |
this.closure = closure;
|
| 31 |
} |
|
| 32 |
|
|
| 33 |
/**
|
|
| 34 |
*
|
|
| 35 |
*/
|
|
| 36 | 1 |
public MapTreeVisitor(Map root) {
|
| 37 | 1 |
this(root, null); |
| 38 |
} |
|
| 39 |
|
|
| 40 |
protected final Map root;
|
|
| 41 |
|
|
| 42 |
private Closure closure;
|
|
| 43 |
|
|
| 44 |
protected final ArrayStack keyStack = new ArrayStack(); |
|
| 45 |
|
|
| 46 | 1 |
public void execute() { |
| 47 | 1 |
keyStack.clear(); |
| 48 | 1 |
doOnMap(root); |
| 49 |
} |
|
| 50 |
|
|
| 51 | 6 |
public void doOnMap(Map map) { |
| 52 | 6 |
final Iterator iterator = map.keySet().iterator(); |
| 53 | 6 |
while (iterator.hasNext()) {
|
| 54 | 12 |
Object key = iterator.next(); |
| 55 | 12 |
Object value = map.get(key); |
| 56 | 12 |
keyStack.push(key); |
| 57 | 12 |
try {
|
| 58 | 12 |
if (value instanceof Map) { |
| 59 | 5 |
doOnMap((Map) value); |
| 60 |
} else {
|
|
| 61 | 7 |
doOnLeaf(value); |
| 62 |
} |
|
| 63 |
} finally {
|
|
| 64 | 12 |
keyStack.pop(); |
| 65 |
} |
|
| 66 |
} |
|
| 67 |
} |
|
| 68 |
|
|
| 69 | 0 |
public void doOnLeaf(Object value) { |
| 70 | 0 |
if (closure != null) |
| 71 | 0 |
closure.execute(value); |
| 72 |
} |
|
| 73 |
|
|
| 74 |
/**
|
|
| 75 |
* @return
|
|
| 76 |
*/
|
|
| 77 | 0 |
public Closure getClosure() {
|
| 78 | 0 |
return closure;
|
| 79 |
} |
|
| 80 |
|
|
| 81 |
} |
|
||||||||||