JAL-1297 JAL-1295 JAL-1294 sensible toString for benefit of annotation IO test
[jalview.git] / src / jalview / datamodel / Annotation.java
index dde0822..b7a83a5 100755 (executable)
@@ -1,13 +1,13 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
- * Copyright (C) 2011 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
+ * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
  * 
  * This file is part of Jalview.
  * 
  * Jalview is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License 
  * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
- * 
+ *  
  * Jalview is distributed in the hope that it will be useful, but 
  * WITHOUT ANY WARRANTY; without even the implied warranty 
  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
@@ -117,4 +117,57 @@ public class Annotation
   {
     this(null, null, ' ', val);
   }
+
+  @Override
+  public String toString()
+  {
+    StringBuffer sb = new StringBuffer();
+    if (displayCharacter != null)
+    {
+      sb.append("\'");
+      sb.append(displayCharacter);
+      sb.append("\'");
+    }
+    {
+      sb.append(",");
+    }
+    if (secondaryStructure != 0
+            && !("" + displayCharacter).equals("" + secondaryStructure))
+    {
+      sb.append("\'");
+      sb.append(secondaryStructure);
+      sb.append("\'");
+    }
+    {
+      sb.append(",");
+    }
+    if (description != null && description.length() > 0)
+    {
+      sb.append("\"");
+      sb.append(description);
+      sb.append("\"");
+    }
+    {
+      sb.append(",");
+    }
+    if (value != Float.NaN)
+    {
+      sb.append(value);
+    }
+    if (colour != null)
+    {
+      if (sb.length() > 0)
+      {
+        sb.append(",");
+      }
+      sb.append("[");
+      sb.append(colour.getRed());
+      sb.append(",");
+      sb.append(colour.getGreen());
+      sb.append(",");
+      sb.append(colour.getBlue());
+      sb.append("]");
+    }
+    return sb.toString();
+  }
 }