Gramma improved
[jabaws.git] / datamodel / compbio / data / sequence / AnnotatedSequence.java
1 package compbio.data.sequence;\r
2 \r
3 import java.util.Arrays;\r
4 \r
5 public class AnnotatedSequence extends FastaSequence {\r
6 \r
7         private float[] annotation;\r
8 \r
9         private AnnotatedSequence() {\r
10                 super();\r
11                 // JAXB default constructor\r
12         }\r
13 \r
14         public AnnotatedSequence(String id, String sequence, float[] annotation) {\r
15                 super(id, sequence);\r
16                 this.annotation = annotation;\r
17                 if (annotation == null || annotation.length != sequence.length()) {\r
18                         throw new IllegalArgumentException("The length of the annotation ("\r
19                                         + ((annotation != null) ? annotation.length : "0")\r
20                                         + ") does not match the length of the sequence ("\r
21                                         + sequence.length() + ")!");\r
22                 }\r
23         }\r
24 \r
25         public AnnotatedSequence(FastaSequence fsequence, float[] annotation) {\r
26                 this(fsequence.getId(), fsequence.getSequence(), annotation);\r
27         }\r
28 \r
29         public float[] getAnnotation() {\r
30                 return annotation;\r
31         }\r
32 \r
33         @Override\r
34         public int hashCode() {\r
35                 final int prime = 7;\r
36                 int result = super.hashCode();\r
37                 result = prime * result + Arrays.hashCode(annotation);\r
38                 return result;\r
39         }\r
40 \r
41         @Override\r
42         public boolean equals(Object obj) {\r
43                 if (this == obj)\r
44                         return true;\r
45                 if (!super.equals(obj))\r
46                         return false;\r
47                 if (getClass() != obj.getClass())\r
48                         return false;\r
49                 AnnotatedSequence other = (AnnotatedSequence) obj;\r
50                 if (!Arrays.equals(annotation, other.annotation))\r
51                         return false;\r
52                 return true;\r
53         }\r
54 \r
55         @Override\r
56         public String toString() {\r
57                 return super.toString() + "Annotation:\n "\r
58                                 + Arrays.toString(annotation) + "\n";\r
59         }\r
60 \r
61 }\r