Project

General

Profile

Download (3.89 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.molecular;
11

    
12

    
13
import java.util.HashSet;
14
import java.util.Set;
15

    
16
import javax.persistence.Entity;
17
import javax.persistence.FetchType;
18
import javax.persistence.ManyToMany;
19
import javax.validation.constraints.NotNull;
20
import javax.xml.bind.annotation.XmlAccessType;
21
import javax.xml.bind.annotation.XmlAccessorType;
22
import javax.xml.bind.annotation.XmlElement;
23
import javax.xml.bind.annotation.XmlElementWrapper;
24
import javax.xml.bind.annotation.XmlIDREF;
25
import javax.xml.bind.annotation.XmlRootElement;
26
import javax.xml.bind.annotation.XmlSchemaType;
27
import javax.xml.bind.annotation.XmlType;
28

    
29
import org.apache.logging.log4j.LogManager;
30
import org.apache.logging.log4j.Logger;
31
import org.hibernate.envers.Audited;
32

    
33
import eu.etaxonomy.cdm.model.media.Media;
34

    
35
/**
36
 * "A phylogenetic tree or evolutionary tree is a branching diagram or "tree" showing the
37
 * inferred evolutionary relationships among various biological species or other entities
38
 * based upon similarities and differences in their physical and/or genetic characteristics.
39
 * The taxa joined together in the tree are implied to have descended from a common ancestor."
40
 * (Wikipedia).
41
 * <BR> In the CDM we currently store phylogenetic trees only as media. This may change in future.
42
 *
43
 * @author m.doering
44
 * @since 08-Nov-2007
45
 */
46
@XmlAccessorType(XmlAccessType.FIELD)
47
@XmlType(name = "PhylogeneticTree", propOrder = {
48
	"usedSequences"
49
})
50
@XmlRootElement(name = "PhylogeneticTree")
51
@Entity
52
//@Indexed disabled to reduce clutter in indexes, since this type is not used by any search
53
//@Indexed(index = "eu.etaxonomy.cdm.model.media.Media")
54
@Audited
55
public class PhylogeneticTree extends Media {
56

    
57
	private static final long serialVersionUID = -7020182117362324067L;
58
    private static final Logger logger = LogManager.getLogger();
59

    
60

    
61
	@XmlElementWrapper(name = "UsedSequences")
62
	@XmlElement(name = "UsedSequence")
63
    @XmlIDREF
64
    @XmlSchemaType(name = "IDREF")
65
    @ManyToMany(fetch = FetchType.LAZY)
66
    @NotNull
67
	private Set<Sequence> usedSequences = new HashSet<Sequence>();
68

    
69
//********************** Factory Method **********************************/
70

    
71
    /**
72
     * Factory method
73
     * @return
74
     */
75
    public static PhylogeneticTree NewInstance(){
76
        return new PhylogeneticTree();
77
    }
78

    
79

    
80
//***************** Constructor ****************************/
81

    
82
    private PhylogeneticTree(){
83
    	super();
84
    }
85

    
86

    
87

    
88
// ********************** GETTER / SETTER **************************/
89

    
90
	public Set<Sequence> getUsedSequences() {
91
		if(usedSequences == null) {
92
			this.usedSequences = new HashSet<Sequence>();
93
		}
94
		return usedSequences;
95
	}
96

    
97
	public void addUsedSequences(Sequence usedSequence) {
98
		this.usedSequences.add(usedSequence);
99
	}
100

    
101
	public void removeUsedSequences(Sequence usedSequence) {
102
		this.usedSequences.remove(usedSequence);
103

    
104
	}
105

    
106
//*********** CLONE **********************************/
107

    
108
	/**
109
	 * Clones <i>this</i> phylogenetic tree. This is a shortcut that enables to
110
	 * create a new instance that differs only slightly from <i>this</i> phylogenetic tree
111
	 * by modifying only some of the attributes.<BR>
112
	 * This method overrides the clone method from {@link Media Media}.
113
	 *
114
	 * @see eu.etaxonomy.cdm.model.media.Media#clone()
115
	 * @see java.lang.Object#clone()
116
	 */
117
	@Override
118

    
119
	public PhylogeneticTree clone(){
120
		PhylogeneticTree result;
121
		try{
122
			result= (PhylogeneticTree) super.clone();
123
			result.usedSequences = new HashSet<Sequence>();
124
			for (Sequence seq: this.usedSequences){
125
				result.addUsedSequences(seq.clone());
126
			}
127

    
128
			return result;
129
		}catch (CloneNotSupportedException e) {
130
			logger.warn("Object does not implement cloneable");
131
			e.printStackTrace();
132
			return null;
133
		}
134
	}
135
}
(6-6/14)