JAL-1807 explicit imports (jalview.datamodel)
[jalview.git] / src / jalview / datamodel / AlignmentAnnotation.java
index a7e635f..f6b633c 100755 (executable)
@@ -23,6 +23,7 @@ package jalview.datamodel;
 import jalview.analysis.Rna;
 import jalview.analysis.SecStrConsensus.SimpleBP;
 import jalview.analysis.WUSSParseException;
+import jalview.schemes.ResidueProperties;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -40,6 +41,8 @@ import java.util.Map.Entry;
  */
 public class AlignmentAnnotation
 {
+  private static final String ANNOTATION_ID_PREFIX = "ann";
+
   /*
    * Identifers for different types of profile data
    */
@@ -49,6 +52,8 @@ public class AlignmentAnnotation
 
   public static final int CDNA_PROFILE = 2;
 
+  private static long counter = 0;
+
   /**
    * If true, this annotations is calculated every edit, eg consensus, quality
    * or conservation graphs
@@ -282,6 +287,7 @@ public class AlignmentAnnotation
   public AlignmentAnnotation(String label, String description,
           Annotation[] annotations)
   {
+    setAnnotationId();
     // always editable?
     editable = true;
     this.label = label;
@@ -412,9 +418,9 @@ public class AlignmentAnnotation
                 && firstChar != 'Y'
                 && firstChar != 'Z'
                 && firstChar != '-'
-                && firstChar < jalview.schemes.ResidueProperties.aaIndex.length)
+                && firstChar < ResidueProperties.aaIndex.length)
         {
-          if (jalview.schemes.ResidueProperties.aaIndex[firstChar] < 23) // TODO:
+          if (ResidueProperties.aaIndex[firstChar] < 23) // TODO:
                                                                          // parameterise
                                                                          // to
                                                                          // gap
@@ -458,8 +464,6 @@ public class AlignmentAnnotation
         _updateRnaSecStr(new AnnotCharSequence());
       }
     }
-
-    annotationId = this.hashCode() + "";
   }
 
   /**
@@ -502,9 +506,13 @@ 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].displayCharacter.charAt(0));
+              || 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
@@ -516,7 +524,9 @@ public class AlignmentAnnotation
       for (int i = offset; i < mx; i++)
       {
         string[i] = (annotations[i] == null || (annotations[i].secondaryStructure <= 32)) ? ' '
-                : annotations[i].displayCharacter.charAt(0);
+                : (annotations[i].displayCharacter == null
+                        || annotations[i].displayCharacter.length() == 0 ? annotations[i].secondaryStructure
+                        : annotations[i].displayCharacter.charAt(0));
       }
       return new String(string);
     }
@@ -559,6 +569,7 @@ public class AlignmentAnnotation
   public AlignmentAnnotation(String label, String description,
           Annotation[] annotations, float min, float max, int graphType)
   {
+    setAnnotationId();
     // graphs are not editable
     editable = graphType == 0;
 
@@ -644,7 +655,7 @@ public class AlignmentAnnotation
       {
         if (annotations[i] != null)
         {
-          annotations[i].displayCharacter = "X";
+          annotations[i].displayCharacter = "";
         }
       }
     }
@@ -658,6 +669,7 @@ public class AlignmentAnnotation
    */
   public AlignmentAnnotation(AlignmentAnnotation annotation)
   {
+    setAnnotationId();
     this.label = new String(annotation.label);
     if (annotation.description != null)
     {
@@ -1376,4 +1388,18 @@ public class AlignmentAnnotation
     return sequenceMapping == null ? null : sequenceMapping.get(position);
 
   }
+
+  /**
+   * Set the id to "ann" followed by a counter that increments so as to be
+   * unique for the lifetime of the JVM
+   */
+  protected final void setAnnotationId()
+  {
+    this.annotationId = ANNOTATION_ID_PREFIX + Long.toString(nextId());
+  }
+
+  protected static synchronized long nextId()
+  {
+    return counter++;
+  }
 }