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