JAL-3990 gradle spotlessApply
[jalview.git] / src / jalview / io / SequenceAnnotationReport.java
index 9ffdf21..c831366 100644 (file)
 package jalview.io;
 
 import java.util.Locale;
-
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Comparator;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
+import com.google.common.collect.Lists;
+
 import jalview.api.FeatureColourI;
 import jalview.datamodel.DBRefEntry;
 import jalview.datamodel.DBRefSource;
@@ -59,7 +62,7 @@ public class SequenceAnnotationReport
 
   private static String linkImageURL;
 
- // public static final String[][] PRIMARY_SOURCES  moved to DBRefSource.java
+  // public static final String[][] PRIMARY_SOURCES moved to DBRefSource.java
 
   /*
    * Comparator to order DBRefEntry by Source + accession id (case-insensitive),
@@ -91,32 +94,32 @@ public class SequenceAnnotationReport
       {
         return 1;
       }
-      int comp = s1 == null ? -1 : (s2 == null ? 1 : s1
-              .compareToIgnoreCase(s2));
+      int comp = s1 == null ? -1
+              : (s2 == null ? 1 : s1.compareToIgnoreCase(s2));
       if (comp == 0)
       {
         String a1 = ref1.getAccessionId();
         String a2 = ref2.getAccessionId();
-        comp = a1 == null ? -1 : (a2 == null ? 1 : a1
-                .compareToIgnoreCase(a2));
+        comp = a1 == null ? -1
+                : (a2 == null ? 1 : a1.compareToIgnoreCase(a2));
       }
       return comp;
     }
 
-//    private boolean isPrimarySource(String source)
-//    {
-//      for (String[] primary : DBRefSource.PRIMARY_SOURCES)
-//      {
-//        for (String s : primary)
-//        {
-//          if (source.equals(s))
-//          {
-//            return true;
-//          }
-//        }
-//      }
-//      return false;
-//    }
+    // private boolean isPrimarySource(String source)
+    // {
+    // for (String[] primary : DBRefSource.PRIMARY_SOURCES)
+    // {
+    // for (String s : primary)
+    // {
+    // if (source.equals(s))
+    // {
+    // return true;
+    // }
+    // }
+    // }
+    // return false;
+    // }
   };
 
   private boolean forTooltip;
@@ -150,9 +153,9 @@ public class SequenceAnnotationReport
    * @param minmax
    * @param maxlength
    */
-  public int appendFeatures(final StringBuilder sb,
-          int residuePos, List<SequenceFeature> features,
-          FeatureRendererModel fr, int maxlength)
+  public int appendFeatures(final StringBuilder sb, int residuePos,
+          List<SequenceFeature> features, FeatureRendererModel fr,
+          int maxlength)
   {
     for (int i = 0; i < features.size(); i++)
     {
@@ -412,21 +415,19 @@ public class SequenceAnnotationReport
           {
             for (List<String> urllink : createLinksFrom(null, urlstring))
             {
-              sb.append("<br/> <a href=\""
-                      + urllink.get(3)
-                      + "\" target=\""
-                      + urllink.get(0)
-                      + "\">"
-                      + (urllink.get(0).toLowerCase(Locale.ROOT)
-                              .equals(urllink.get(1).toLowerCase(Locale.ROOT)) ? urllink
-                              .get(0) : (urllink.get(0) + ":" + urllink
-                                              .get(1)))
+              sb.append("<br/> <a href=\"" + urllink.get(3) + "\" target=\""
+                      + urllink.get(0) + "\">"
+                      + (urllink.get(0).toLowerCase(Locale.ROOT).equals(
+                              urllink.get(1).toLowerCase(Locale.ROOT))
+                                      ? urllink.get(0)
+                                      : (urllink.get(0) + ":"
+                                              + urllink.get(1)))
                       + "</a><br/>");
             }
           } catch (Exception x)
           {
-            System.err.println("problem when creating links from "
-                    + urlstring);
+            System.err.println(
+                    "problem when creating links from " + urlstring);
             x.printStackTrace();
           }
         }
@@ -495,6 +496,7 @@ public class SequenceAnnotationReport
       sb.append(tmp);
       maxWidth = Math.max(maxWidth, tmp.length());
     }
+    sb.append("\n");
     SequenceI ds = sequence;
     while (ds.getDatasetSequence() != null)
     {
@@ -505,6 +507,7 @@ public class SequenceAnnotationReport
     {
       maxWidth = Math.max(maxWidth, appendDbRefs(sb, ds, summary));
     }
+    sb.append("\n");
 
     /*
      * add non-positional features if wanted
@@ -536,12 +539,19 @@ public class SequenceAnnotationReport
   protected int appendDbRefs(final StringBuilder sb, SequenceI ds,
           boolean summary)
   {
-    List<DBRefEntry> dbrefs = ds.getDBRefs();
-    if (dbrefs == null)
+    List<DBRefEntry> dbrefs, dbrefset = ds.getDBRefs();
+
+    if (dbrefset == null)
     {
       return 0;
     }
 
+    // PATCH for JAL-3980 defensive copy
+
+    dbrefs = new ArrayList<DBRefEntry>();
+
+    dbrefs.addAll(dbrefset);
+
     // note this sorts the refs held on the sequence!
     dbrefs.sort(comparator);
     boolean ellipsis = false;
@@ -578,7 +588,7 @@ public class SequenceAnnotationReport
       countForSource++;
       if (countForSource == 1 || !summary)
       {
-        sb.append("<br/>");
+        sb.append("<br/>\n");
       }
       if (countForSource <= MAX_REFS_PER_SOURCE || !summary)
       {
@@ -586,7 +596,7 @@ public class SequenceAnnotationReport
         lineLength += accessionId.length() + 1;
         if (countForSource > 1 && summary)
         {
-          sb.append(", ").append(accessionId);
+          sb.append(",\n ").append(accessionId);
           lineLength++;
         }
         else
@@ -604,11 +614,11 @@ public class SequenceAnnotationReport
     }
     if (moreSources)
     {
-      sb.append("<br/>").append(source).append(COMMA).append(ELLIPSIS);
+      sb.append("<br/>\n").append(source).append(COMMA).append(ELLIPSIS);
     }
     if (ellipsis)
     {
-      sb.append("<br/>(");
+      sb.append("<br/>\n(");
       sb.append(MessageManager.getString("label.output_seq_details"));
       sb.append(")");
     }
@@ -620,8 +630,8 @@ public class SequenceAnnotationReport
           SequenceI sequence, boolean showDbRefs, boolean showNpFeats,
           FeatureRendererModel fr)
   {
-    int maxWidth = createSequenceAnnotationReport(tip, sequence,
-            showDbRefs, showNpFeats, fr, true);
+    int maxWidth = createSequenceAnnotationReport(tip, sequence, showDbRefs,
+            showNpFeats, fr, true);
 
     if (maxWidth > 60)
     {