Project

General

Profile

Download (1.64 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
 * @version 1.0
26
 */
27
public class TreeCreator {
28
	@SuppressWarnings("unused")
29
	private static final Logger logger = Logger.getLogger(TreeCreator.class);
30

    
31
	public static FeatureTree flatTree(UUID featureTreeUuid, Map<Integer, Feature> featureMap, Object[] featureKeyList){
32
		FeatureTree result = FeatureTree.NewInstance(featureTreeUuid);
33
		FeatureNode root = result.getRoot();
34
		
35
		for (Object featureKey : featureKeyList){
36
			Feature feature = featureMap.get(featureKey);
37
			if (feature != null){
38
				FeatureNode child = FeatureNode.NewInstance(feature);
39
				root.addChild(child);	
40
			}
41
		}
42
		return result;
43
	}
44
	
45
	
46
	/**
47
	 * @param args
48
	 */
49
	public static void main(String[] args) {
50
		Map<Integer, Feature>  map = new HashMap<Integer, Feature>(null);
51
		map.put(1, Feature.DISTRIBUTION());
52
		map.put(2, Feature.ECOLOGY());
53

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

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