Adding AAConWS
[jabaws.git] / datamodel / compbio / data / sequence / MultiAnnotatedSequence.java
index 580a22e..1a889e3 100644 (file)
@@ -2,6 +2,9 @@ package compbio.data.sequence;
 \r
 import java.util.EnumMap;\r
 import java.util.List;\r
+import java.util.Map;\r
+\r
+import compbio.util.annotation.NotThreadSafe;\r
 \r
 /**\r
  * TODO complete\r
@@ -11,23 +14,67 @@ import java.util.List;
  * @param <T>\r
  *            enum type\r
  */\r
+@NotThreadSafe\r
 public class MultiAnnotatedSequence<T extends Enum<T>> {\r
 \r
-    private final EnumMap<T, List<Float>> annotation;\r
+       private final Map<T, List<Float>> annotations;\r
+\r
+       public MultiAnnotatedSequence(Class<T> enumeration) {\r
+               this.annotations = new EnumMap<T, List<Float>>(enumeration);\r
+       }\r
+\r
+       public void addAnnotation(T type, List<Float> annotation) {\r
+               assert type != null : "Type is expected";\r
+               assert annotation != null : "Not empty value is expected!";\r
+               if (!annotations.isEmpty()) {\r
+                       assert annotations.values().iterator().next().size() == annotation\r
+                                       .size() : "Annotations must contain the same number of elements!";\r
+               }\r
+               this.annotations.put(type, annotation);\r
+       }\r
+\r
+       public Map<T, List<Float>> getAnnotations() {\r
+               return new EnumMap<T, List<Float>>(this.annotations);\r
+       }\r
 \r
-    private MultiAnnotatedSequence(Class<T> type) {\r
-       this.annotation = new EnumMap<T, List<Float>>(type);\r
-    }\r
+       @Override\r
+       public int hashCode() {\r
+               final int prime = 31;\r
+               int result = 1;\r
+               result = prime * result\r
+                               + ((annotations == null) ? 0 : annotations.hashCode());\r
+               return result;\r
+       }\r
 \r
-    //    public MultiAnnotatedSequence getFloatInstance(FastaSequence fsequence) {\r
-    // return null;\r
-    //}\r
+       @Override\r
+       public boolean equals(Object obj) {\r
+               if (this == obj)\r
+                       return true;\r
+               if (obj == null)\r
+                       return false;\r
+               if (getClass() != obj.getClass())\r
+                       return false;\r
+               MultiAnnotatedSequence other = (MultiAnnotatedSequence) obj;\r
+               if (annotations == null) {\r
+                       if (other.annotations != null)\r
+                               return false;\r
+               } else if (!annotations.equals(other.annotations))\r
+                       return false;\r
+               return true;\r
+       }\r
 \r
-    public EnumMap<T, List<Integer>> getIntegerInstance(Class<T> enumeration) {\r
-       return new EnumMap<T, List<Integer>>(enumeration);\r
-    }\r
+       @Override\r
+       public String toString() {\r
+               String value = "";\r
+               for (Map.Entry<T, List<Float>> annt : annotations.entrySet()) {\r
+                       value += annt.getKey() + " ";\r
+                       value += annt.getValue() + "\n";\r
+               }\r
+               return value;\r
+       }\r
 \r
-    public EnumMap<T, List<Float>> getFloatInstance(Class<T> enumeration) {\r
-       return new EnumMap<T, List<Float>>(enumeration);\r
-    }\r
+       public JalviewAnnotation toJalviewAnnotation() {\r
+               // TODO Auto-generated method stub\r
+               return null;\r
+       }\r
 }\r