JAL-1775 patch regression bug when displayChar is null and secondaryStructure contain...
[jalview.git] / src / jalview / datamodel / AlignmentAnnotation.java
index 09d9ee0..7966f5e 100755 (executable)
@@ -27,9 +27,8 @@ import jalview.analysis.WUSSParseException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Enumeration;
 import java.util.HashMap;
-import java.util.Hashtable;
+import java.util.Iterator;
 import java.util.Map;
 import java.util.Map.Entry;
 
@@ -41,6 +40,15 @@ import java.util.Map.Entry;
  */
 public class AlignmentAnnotation
 {
+  /*
+   * Identifers for different types of profile data
+   */
+  public static final int SEQUENCE_PROFILE = 0;
+
+  public static final int STRUCTURE_PROFILE = 1;
+
+  public static final int CDNA_PROFILE = 2;
+
   /**
    * If true, this annotations is calculated every edit, eg consensus, quality
    * or conservation graphs
@@ -155,7 +163,7 @@ public class AlignmentAnnotation
   /**
    * map of positions in the associated annotation
    */
-  public java.util.Hashtable<Integer, Annotation> sequenceMapping;
+  private Map<Integer, Annotation> sequenceMapping;
 
   /** DOCUMENT ME!! */
   public float graphMin;
@@ -494,11 +502,16 @@ public class AlignmentAnnotation
     public char charAt(int index)
     {
       return ((index + offset < 0) || (index + offset) >= max
-              || annotations[index + offset] == null || (annotations[index
- + offset].secondaryStructure < ' ') ? ' '
-              : annotations[index + offset].secondaryStructure);
+              || annotations[index + offset] == null
+              || (annotations[index + offset].secondaryStructure <= ' ') ? ' '
+              : annotations[index + offset].displayCharacter == null
+                      || annotations[index + offset].displayCharacter
+                              .length() == 0 ? annotations[index + offset].secondaryStructure
+                      : annotations[index + offset].displayCharacter
+                              .charAt(0));
     }
 
+    @Override
     public String toString()
     {
       char[] string = new char[max - offset];
@@ -506,8 +519,10 @@ public class AlignmentAnnotation
 
       for (int i = offset; i < mx; i++)
       {
-        string[i] = (annotations[i] == null || (annotations[i].secondaryStructure < 32)) ? ' '
-                : annotations[i].secondaryStructure;
+        string[i] = (annotations[i] == null || (annotations[i].secondaryStructure <= 32)) ? ' '
+                : (annotations[i].displayCharacter == null
+                        || annotations[i].displayCharacter.length() == 0 ? annotations[i].secondaryStructure
+                        : annotations[i].displayCharacter.charAt(0));
       }
       return new String(string);
     }
@@ -710,12 +725,13 @@ public class AlignmentAnnotation
       if (annotation.sequenceMapping != null)
       {
         Integer p = null;
-        sequenceMapping = new Hashtable();
-        Enumeration pos = annotation.sequenceMapping.keys();
-        while (pos.hasMoreElements())
+        sequenceMapping = new HashMap<Integer, Annotation>();
+        Iterator<Integer> pos = annotation.sequenceMapping.keySet()
+                .iterator();
+        while (pos.hasNext())
         {
           // could optimise this!
-          p = (Integer) pos.nextElement();
+          p = pos.next();
           Annotation a = annotation.sequenceMapping.get(p);
           if (a == null)
           {
@@ -789,11 +805,11 @@ public class AlignmentAnnotation
       int epos = sequenceRef.findPosition(endRes);
       if (sequenceMapping != null)
       {
-        Hashtable newmapping = new Hashtable();
-        Enumeration e = sequenceMapping.keys();
-        while (e.hasMoreElements())
+        Map<Integer, Annotation> newmapping = new HashMap<Integer, Annotation>();
+        Iterator<Integer> e = sequenceMapping.keySet().iterator();
+        while (e.hasNext())
         {
-          Integer pos = (Integer) e.nextElement();
+          Integer pos = e.next();
           if (pos.intValue() >= spos && pos.intValue() <= epos)
           {
             newmapping.put(pos, sequenceMapping.get(pos));
@@ -836,9 +852,10 @@ public class AlignmentAnnotation
    * 
    * @return DOCUMENT ME!
    */
+  @Override
   public String toString()
   {
-    StringBuffer buffer = new StringBuffer();
+    StringBuilder buffer = new StringBuilder(256);
 
     for (int i = 0; i < annotations.length; i++)
     {
@@ -911,7 +928,7 @@ public class AlignmentAnnotation
     {
       return;
     }
-    sequenceMapping = new java.util.Hashtable();
+    sequenceMapping = new HashMap<Integer, Annotation>();
 
     int seqPos;
 
@@ -1223,7 +1240,7 @@ public class AlignmentAnnotation
             .getTo() == sq.getDatasetSequence()) : false;
 
     // TODO build a better annotation element map and get rid of annotations[]
-    Hashtable<Integer, Annotation> mapForsq = new Hashtable();
+    Map<Integer, Annotation> mapForsq = new HashMap<Integer, Annotation>();
     if (sequenceMapping != null)
     {
       if (sp2sq != null)
@@ -1275,7 +1292,8 @@ public class AlignmentAnnotation
   {
     if (mapping != null)
     {
-      Hashtable<Integer, Annotation> old = sequenceMapping, remap = new Hashtable<Integer, Annotation>();
+      Map<Integer, Annotation> old = sequenceMapping;
+      Map<Integer, Annotation> remap = new HashMap<Integer, Annotation>();
       int index = -1;
       for (int mp[] : mapping)
       {