root/trunk/cdmlib/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/molecular/PhylogeneticTree.java

Revision 12706, 3.0 kB (checked in by a.mueller, 9 months ago)

change name of ReferencedMedia? to ReferencedMediaBase? (#2381)

  • Property svn:keywords set to Id
Line 
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
10package eu.etaxonomy.cdm.model.molecular;
11
12
13import eu.etaxonomy.cdm.model.media.ReferencedMediaBase;
14
15import org.apache.log4j.Logger;
16import org.hibernate.envers.Audited;
17import org.hibernate.search.annotations.Indexed;
18
19import java.util.*;
20
21import javax.persistence.*;
22import javax.validation.constraints.NotNull;
23import javax.xml.bind.annotation.XmlAccessType;
24import javax.xml.bind.annotation.XmlAccessorType;
25import javax.xml.bind.annotation.XmlElement;
26import javax.xml.bind.annotation.XmlElementWrapper;
27import javax.xml.bind.annotation.XmlIDREF;
28import javax.xml.bind.annotation.XmlRootElement;
29import javax.xml.bind.annotation.XmlSchemaType;
30import javax.xml.bind.annotation.XmlType;
31
32/**
33 * @author m.doering
34 * @version 1.0
35 * @created 08-Nov-2007 13:06:43
36 */
37@XmlAccessorType(XmlAccessType.FIELD)
38@XmlType(name = "PhylogeneticTree", propOrder = {
39        "usedSequences"
40})
41@XmlRootElement(name = "PhylogeneticTree")
42@Entity
43@Indexed(index = "eu.etaxonomy.cdm.model.media.Media")
44@Audited
45public class PhylogeneticTree extends ReferencedMediaBase implements Cloneable{
46        private static final long serialVersionUID = -7020182117362324067L;
47        private static final  Logger logger = Logger.getLogger(PhylogeneticTree.class);
48       
49        @XmlElementWrapper(name = "UsedSequences")
50        @XmlElement(name = "UsedSequence")
51    @XmlIDREF
52    @XmlSchemaType(name = "IDREF")
53    @OneToMany(fetch = FetchType.LAZY)// FIXME surely should be ManyToMany - you can use a sequence to construct several different phylogenetic trees
54    @NotNull
55        private Set<Sequence> usedSequences = new HashSet<Sequence>();
56       
57        public Set<Sequence> getUsedSequences() {
58                if(usedSequences == null) {
59                        this.usedSequences = new HashSet<Sequence>();
60                }
61                return usedSequences;
62        }
63
64        public void addUsedSequences(Sequence usedSequence) {
65                this.usedSequences.add(usedSequence);
66        }
67       
68        public void removeUsedSequences(Sequence usedSequence) {
69                this.usedSequences.remove(usedSequence);
70               
71        }
72       
73//*********** CLONE **********************************/
74       
75        /**
76         * Clones <i>this</i> phylogenetic tree. This is a shortcut that enables to
77         * create a new instance that differs only slightly from <i>this</i> phylogenetic tree
78         * by modifying only some of the attributes.<BR>
79         * This method overrides the clone method from {@link Media Media}.
80         *
81         * @see eu.etaxonomy.cdm.model.media.Media#clone()
82         * @see java.lang.Object#clone()
83         */
84        @Override
85       
86        public Object clone(){
87                PhylogeneticTree result;
88                try{
89                        result= (PhylogeneticTree) super.clone();
90                        result.usedSequences = new HashSet<Sequence>();
91                        for (Sequence seq: this.usedSequences){
92                                result.addUsedSequences((Sequence)seq.clone());
93                        }
94                       
95                        return result;
96                }catch (CloneNotSupportedException e) {
97                        logger.warn("Object does not implement cloneable");
98                        e.printStackTrace();
99                        return null;
100                }
101        }
102}
Note: See TracBrowser for help on using the browser.