Project

General

Profile

Download (4.26 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
package eu.etaxonomy.cdm.model.molecular;
10

    
11
import java.io.Serializable;
12

    
13
import javax.persistence.Embeddable;
14
import javax.persistence.Lob;
15
import javax.persistence.Transient;
16
import javax.xml.bind.annotation.XmlAccessType;
17
import javax.xml.bind.annotation.XmlAccessorType;
18
import javax.xml.bind.annotation.XmlElement;
19
import javax.xml.bind.annotation.XmlRootElement;
20
import javax.xml.bind.annotation.XmlType;
21

    
22
import org.apache.log4j.Logger;
23

    
24
import eu.etaxonomy.cdm.common.CdmUtils;
25

    
26
/**
27
 * A sequence contains the genetic code of a DNA or RNA part. It is basically a string
28
 * based on 4 letters: ATGC (Adenin, Thymin, Guanin, Cytosin) for DNA and AUGC (Thymin replaced by Uracil)
29
 * for RNA.
30
 * <BR>
31
 * The direction of the string shall always be 5'-3' which is a convention.
32
 * <BR>
33
 * The sequence has a length which is stored as such if no further information is given. If the sequence
34
 * string is given the length is computed automatically.
35
 *
36
 * @author a.mueller
37
 * @since 2013-07-05
38
 */
39
@XmlAccessorType(XmlAccessType.FIELD)
40
@XmlType(name = "SequenceString", propOrder = {
41
	"string",
42
	"length"
43
})
44
@XmlRootElement(name = "SequenceString")
45
@Embeddable
46
public class SequenceString implements Cloneable, Serializable{
47
	private static final long serialVersionUID = 45735207807329055L;
48
	private static final Logger logger = Logger.getLogger(SequenceString.class);
49

    
50
	/**{@link #getString()}*/
51
	@XmlElement(name = "String")
52
    @Lob
53
	private String string;
54

    
55
	@XmlElement(name = "Length")
56
	private Integer length;
57

    
58

    
59
// ******************** FACTORY METHOD ******************/
60

    
61
	public static SequenceString NewInstance(){
62
		SequenceString result = new SequenceString();
63
		return result;
64
	}
65

    
66
	public static SequenceString NewInstance(String sequence){
67
		SequenceString result = new SequenceString();
68
		result.setString(sequence);
69
		return result;
70
	}
71

    
72
// ********************* CONSTRUCTOR ********************/
73

    
74
	private SequenceString(){}
75

    
76
// ********************* GETTER / SETTER ********************/
77

    
78
	/**
79
	 * The sequence as a string of base pairs in direction 5'->3'.
80
	 */
81
	public String getString(){
82
		return this.string;
83
	}
84

    
85
	/**
86
	 * Sets the sequence. Also {@link #getLength() length information} will be set automatically.
87
	 * @see #getString()
88
	 * @param sequence    sequence
89
	 */
90
	public void setString(String sequence){
91
		this.string = sequence;
92
		this.length = (sequence == null ? 0 : sequence.length());
93
	}
94

    
95

    
96
	/**
97
	 * The length of the sequence. Will be calculated if the {@link #getString() sequence}  is set.
98
	 * @return the length of the sequence.
99
	 */
100
	public Integer getLength(){
101
		return this.length;
102
	}
103

    
104
	/**
105
	 * Sets the {@link #getLength() length}, if the {@link #getString() sequence} is not set.
106
	 * If {@link #getString() sequence}  is available, length has no effect.
107
	 * @see #getLength()
108
	 * @param length    length
109
	 */
110
	public void setLength(Integer length){
111
		if (CdmUtils.isBlank(string)){
112
			this.length = length;
113
		}
114
	}
115

    
116

    
117
    /**
118
     * <code>true</code>, if none of the attributes (string, length) is set.
119
     */
120
    @Transient
121
    public boolean isEmpty(){
122
        if ((string == null || string.isEmpty())
123
                && length == null){
124
            return true;
125
        }else{
126
            return false;
127
        }
128
    }
129

    
130

    
131
	// ********************* CLONE ********************/
132

    
133
	/**
134
	 * Clones <i>this</i> sequence. This is a shortcut that enables to create
135
	 * a new instance that differs only slightly from <i>this</i> sequencing by
136
	 * modifying only some of the attributes.<BR><BR>
137
	 *
138
	 *
139
	 * @see eu.etaxonomy.cdm.model.media.IdentifiableEntity#clone()
140
	 * @see java.lang.Object#clone()
141
	 */
142
	@Override
143
	public Object clone()  {
144
		try{
145
		SequenceString result = (SequenceString)super.clone();
146

    
147
		//don't change sequence, length
148

    
149
		return result;
150
		}catch (CloneNotSupportedException e) {
151
			logger.warn("Object does not implement cloneable");
152
			e.printStackTrace();
153
			return null;
154
		}
155
	}
156
}
(10-10/14)