More work on AAConWS not finished yet!
[jabaws.git] / datamodel / compbio / data / sequence / MultiAnnotatedSequence.java
1 package compbio.data.sequence;\r
2 \r
3 import java.util.ArrayList;\r
4 import java.util.EnumMap;\r
5 import java.util.List;\r
6 import java.util.Map;\r
7 \r
8 import javax.xml.bind.annotation.XmlAccessType;\r
9 import javax.xml.bind.annotation.XmlAccessorType;\r
10 \r
11 import compbio.util.annotation.NotThreadSafe;\r
12 \r
13 /**\r
14  * TODO complete\r
15  * \r
16  * @author pvtroshin\r
17  * \r
18  * @param <T>\r
19  *            enum type\r
20  */\r
21 @NotThreadSafe\r
22 @XmlAccessorType(XmlAccessType.FIELD)\r
23 public class MultiAnnotatedSequence<T extends Enum<T>> {\r
24 \r
25         private EnumMap<T, ArrayList<Float>> annotations;\r
26 \r
27         MultiAnnotatedSequence() {\r
28                 // default constructor for JAXB\r
29         }\r
30 \r
31         public MultiAnnotatedSequence(Class<T> enumeration) {\r
32                 this.annotations = new EnumMap<T, ArrayList<Float>>(enumeration);\r
33         }\r
34 \r
35         public void addAnnotation(T type, ArrayList<Float> annotation) {\r
36                 assert type != null : "Type is expected";\r
37                 assert annotation != null : "Not empty value is expected!";\r
38                 if (!annotations.isEmpty()) {\r
39                         assert annotations.values().iterator().next().size() == annotation\r
40                                         .size() : "Annotations must contain the same number of elements!";\r
41                 }\r
42                 this.annotations.put(type, annotation);\r
43         }\r
44 \r
45         public Map<T, List<Float>> getAnnotations() {\r
46                 return new EnumMap<T, List<Float>>(this.annotations);\r
47         }\r
48 \r
49         @Override\r
50         public int hashCode() {\r
51                 final int prime = 31;\r
52                 int result = 1;\r
53                 result = prime * result\r
54                                 + ((annotations == null) ? 0 : annotations.hashCode());\r
55                 return result;\r
56         }\r
57 \r
58         @Override\r
59         public boolean equals(Object obj) {\r
60                 if (this == obj)\r
61                         return true;\r
62                 if (obj == null)\r
63                         return false;\r
64                 if (getClass() != obj.getClass())\r
65                         return false;\r
66                 MultiAnnotatedSequence other = (MultiAnnotatedSequence) obj;\r
67                 if (annotations == null) {\r
68                         if (other.annotations != null)\r
69                                 return false;\r
70                 } else if (!annotations.equals(other.annotations))\r
71                         return false;\r
72                 return true;\r
73         }\r
74 \r
75         @Override\r
76         public String toString() {\r
77                 String value = "";\r
78                 for (Map.Entry<T, ArrayList<Float>> annt : annotations.entrySet()) {\r
79                         value += annt.getKey() + " ";\r
80                         value += annt.getValue() + "\n";\r
81                 }\r
82                 return value;\r
83         }\r
84 \r
85         public JalviewAnnotation toJalviewAnnotation() {\r
86                 // TODO Auto-generated method stub\r
87                 return null;\r
88         }\r
89 }\r