Project

General

Profile

Download (1.6 KB) Statistics
| Branch: | Revision:
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.common;
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.model.description.Feature;
19
import eu.etaxonomy.cdm.model.description.FeatureNode;
20
import eu.etaxonomy.cdm.model.description.FeatureTree;
21

    
22
/**
23
 * @author a.mueller
24
 * @since 03.07.2008
25
 */
26
public class TreeCreator {
27
	@SuppressWarnings("unused")
28
	private static final Logger logger = Logger.getLogger(TreeCreator.class);
29

    
30
	public static FeatureTree flatTree(UUID featureTreeUuid, Map<Integer, Feature> featureMap, Object[] featureKeyList){
31
		FeatureTree result = FeatureTree.NewInstance(featureTreeUuid);
32
		FeatureNode root = result.getRoot();
33

    
34
		for (Object featureKey : featureKeyList){
35
			Feature feature = featureMap.get(featureKey);
36
			if (feature != null){
37
				FeatureNode child = FeatureNode.NewInstance(feature);
38
				root.addChild(child);
39
			}
40
		}
41
		return result;
42
	}
43

    
44

    
45
	/**
46
	 * @param args
47
	 */
48
	public static void main(String[] args) {
49
		Map<Integer, Feature>  map = new HashMap<>(null);
50
		map.put(1, Feature.DISTRIBUTION());
51
		map.put(2, Feature.ECOLOGY());
52

    
53
		Object[] strFeatureList = new Integer[]{1,2};
54

    
55
		FeatureTree tree = TreeCreator.flatTree(UUID.randomUUID(), map, strFeatureList);
56
		System.out.println(tree.getRootChildren());
57
	}
58
}
(3-3/3)