1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.cdm.app.berlinModelImport;
|
11
|
|
12
|
import java.util.HashMap;
|
13
|
import java.util.Map;
|
14
|
import java.util.UUID;
|
15
|
|
16
|
import org.apache.log4j.Logger;
|
17
|
|
18
|
import eu.etaxonomy.cdm.app.berlinModelImport.TreeCreator;
|
19
|
import eu.etaxonomy.cdm.model.description.Feature;
|
20
|
import eu.etaxonomy.cdm.model.description.FeatureNode;
|
21
|
import eu.etaxonomy.cdm.model.description.FeatureTree;
|
22
|
|
23
|
/**
|
24
|
* @author a.mueller
|
25
|
* @created 03.07.2008
|
26
|
* @version 1.0
|
27
|
*/
|
28
|
public class TreeCreator {
|
29
|
@SuppressWarnings("unused")
|
30
|
private static final Logger logger = Logger.getLogger(TreeCreator.class);
|
31
|
|
32
|
public static FeatureTree flatTree(UUID featureTreeUuid, Map<Integer, Feature> featureMap, Object[] featureKeyList){
|
33
|
FeatureTree result = FeatureTree.NewInstance(featureTreeUuid);
|
34
|
FeatureNode root = result.getRoot();
|
35
|
|
36
|
for (Object featureKey : featureKeyList){
|
37
|
Feature feature = featureMap.get(featureKey);
|
38
|
if (feature != null){
|
39
|
FeatureNode child = FeatureNode.NewInstance(feature);
|
40
|
root.addChild(child);
|
41
|
}
|
42
|
}
|
43
|
return result;
|
44
|
}
|
45
|
|
46
|
|
47
|
/**
|
48
|
* @param args
|
49
|
*/
|
50
|
public static void main(String[] args) {
|
51
|
Map<Integer, Feature> map = new HashMap<Integer, Feature>(null);
|
52
|
map.put(1, Feature.DISTRIBUTION());
|
53
|
map.put(2, Feature.ECOLOGY());
|
54
|
|
55
|
Object[] strFeatureList = new Integer[]{1,2};
|
56
|
|
57
|
FeatureTree tree = TreeCreator.flatTree(UUID.randomUUID(), map, strFeatureList);
|
58
|
System.out.println(tree.getRootChildren());
|
59
|
}
|
60
|
}
|