Replacing web site content with fresh version from JWS2 (JABAWS production ) branch
[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 compbio.util.annotation.NotThreadSafe;\r
9 \r
10 /**\r
11  * TODO complete\r
12  * \r
13  * @author pvtroshin\r
14  * \r
15  * @param <T>\r
16  *            enum type\r
17  */\r
18 @NotThreadSafe\r
19 // @XmlAccessorType(XmlAccessType.FIELD)\r
20 public class MultiAnnotatedSequence<T extends Enum<T>> {\r
21 \r
22         private EnumMap<T, ArrayList<Float>> annotations;\r
23 \r
24         MultiAnnotatedSequence() {\r
25                 // default constructor for JAXB\r
26         }\r
27 \r
28         public MultiAnnotatedSequence(Class<T> enumeration) {\r
29                 this.annotations = new EnumMap<T, ArrayList<Float>>(enumeration);\r
30         }\r
31 \r
32         public void addAnnotation(T type, ArrayList<Float> annotation) {\r
33                 assert type != null : "Type is expected";\r
34                 assert annotation != null : "Not empty value is expected!";\r
35                 if (!annotations.isEmpty()) {\r
36                         assert annotations.values().iterator().next().size() == annotation\r
37                                         .size() : "Annotations must contain the same number of elements!";\r
38                 }\r
39                 this.annotations.put(type, annotation);\r
40         }\r
41 \r
42         public Map<T, List<Float>> getAnnotations() {\r
43                 return new EnumMap<T, List<Float>>(this.annotations);\r
44         }\r
45 \r
46         @Override\r
47         public int hashCode() {\r
48                 final int prime = 31;\r
49                 int result = 1;\r
50                 result = prime * result\r
51                                 + ((annotations == null) ? 0 : annotations.hashCode());\r
52                 return result;\r
53         }\r
54 \r
55         @Override\r
56         public boolean equals(Object obj) {\r
57                 if (this == obj)\r
58                         return true;\r
59                 if (obj == null)\r
60                         return false;\r
61                 if (getClass() != obj.getClass())\r
62                         return false;\r
63                 MultiAnnotatedSequence other = (MultiAnnotatedSequence) obj;\r
64                 if (annotations == null) {\r
65                         if (other.annotations != null)\r
66                                 return false;\r
67                 } else if (!annotations.equals(other.annotations))\r
68                         return false;\r
69                 return true;\r
70         }\r
71 \r
72         @Override\r
73         public String toString() {\r
74                 String value = "";\r
75                 for (Map.Entry<T, ArrayList<Float>> annt : annotations.entrySet()) {\r
76                         value += annt.getKey() + " ";\r
77                         value += annt.getValue() + "\n";\r
78                 }\r
79                 return value;\r
80         }\r
81 \r
82 }\r