Project

General

Profile

Download (2.64 KB) Statistics
| Branch: | Tag: | 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.model.description;
11

    
12

    
13
import java.util.ArrayList;
14
import java.util.List;
15
import java.util.UUID;
16

    
17
import javax.persistence.Entity;
18
import javax.persistence.ManyToOne;
19
import javax.persistence.Transient;
20

    
21
import org.apache.log4j.Logger;
22
import org.hibernate.annotations.Cascade;
23
import org.hibernate.annotations.CascadeType;
24

    
25
import eu.etaxonomy.cdm.model.common.TermBase;
26

    
27
/**
28
 * Feature type trees arrange feature types (characters). They may also be used to
29
 * define flat feature types subsets for filtering purposes. 
30
 * A feature type tree is build out of feature type nodes, which can be hierarchically organised.
31
 * @author m.doering
32
 * @version 1.0
33
 * @created 08-Nov-2007 13:06:16
34
 */
35
@Entity
36
public class FeatureTree extends TermBase {
37
	static Logger logger = Logger.getLogger(FeatureTree.class);
38
	//private Set<FeatureNode> nodes = new HashSet<FeatureNode>();
39
	private FeatureNode root;
40
	private boolean isDescriptionSeparated = false;
41
	
42
	/**
43
	 * @return the isDescriptionSeperated
44
	 */
45
	public boolean isDescriptionSeparated() {
46
		return isDescriptionSeparated;
47
	}
48

    
49
	/**
50
	 * @param isDescriptionSeperated the isDescriptionSeperated to set
51
	 */
52
	public void setDescriptionSeparated(boolean isDescriptionSeperated) {
53
		this.isDescriptionSeparated = isDescriptionSeperated;
54
	}
55

    
56
	public static FeatureTree NewInstance(){
57
		return new FeatureTree();
58
	}
59

    
60
	public static FeatureTree NewInstance(UUID uuid){
61
		FeatureTree result =  new FeatureTree();
62
		result.setUuid(uuid);
63
		return result;
64
	}
65
	
66
	public static FeatureTree NewInstance(List<Feature> featureList){
67
		FeatureTree result =  new FeatureTree();
68
		FeatureNode root = result.getRoot();
69
		
70
		for (Feature feature : featureList){
71
			FeatureNode child = FeatureNode.NewInstance(feature);
72
			root.addChild(child);	
73
		}
74
		
75
		return result;
76
	}
77
		
78
	protected FeatureTree() {
79
		super();
80
		root = FeatureNode.NewInstance();
81
	}
82
	
83
//	@OneToMany
84
//	@Cascade({CascadeType.SAVE_UPDATE})
85
//	public Set<FeatureNode> getNodes() {
86
//		return nodes;
87
//	}
88
//	public void setNodes(Set<FeatureNode> nodes) {
89
//		this.nodes = nodes;
90
//	}
91

    
92
	@ManyToOne
93
	@Cascade({CascadeType.SAVE_UPDATE})
94
	public FeatureNode getRoot() {
95
		return root;
96
	}
97
	public void setRoot(FeatureNode root) {
98
		this.root = root;
99
	}
100
	
101
	@Transient
102
	public List<FeatureNode> getRootChildren(){
103
		List<FeatureNode> result = new ArrayList<FeatureNode>();
104
		result.addAll(root.getChildren());
105
		return result;
106
	}
107

    
108
}
(9-9/30)