JAL-1432 updated copyright notices
[jalview.git] / src / jalview / io / ModellerDescription.java
index b590a6d..a57cefa 100755 (executable)
@@ -1,19 +1,20 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
- * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
+ * Copyright (C) 2014 The Jalview Authors
  * 
  * 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 
  * PURPOSE.  See the GNU General Public License for more details.
  * 
  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
  */
 package jalview.io;
 
@@ -119,7 +120,9 @@ public class ModellerDescription
   private java.util.Hashtable parseDescription(String desc)
   {
     java.util.Hashtable fields = new java.util.Hashtable();
-    java.util.StringTokenizer st = new java.util.StringTokenizer(desc, ":");
+    java.util.StringTokenizer st = new java.util.StringTokenizer(desc, ":",
+            true);
+
     String field;
     int type = -1;
     if (st.countTokens() > 0)
@@ -137,6 +140,7 @@ public class ModellerDescription
 
       if (i < seqTypes.length)
       {
+        st.nextToken(); // skip ':'
         // valid seqType for modeller
         type = i;
         i = 1; // continue parsing fields
@@ -144,24 +148,35 @@ public class ModellerDescription
         {
           if ((field = st.nextToken(":")) != null)
           {
-            // validate residue field value
-            if (Types[i] == 1)
+            if (!field.equals(":"))
             {
-              resCode val = validResidueCode(field);
-              if (val != null)
+              // validate residue field value
+              if (Types[i] == 1)
               {
-                fields.put(new String(Fields[i] + "num"), val);
+                resCode val = validResidueCode(field);
+                if (val != null)
+                {
+                  fields.put(new String(Fields[i] + "num"), val);
+                }
+                else
+                {
+                  // jalview.bin.Cache.log.debug(
+                  // "Ignoring non-Modeller description: invalid integer-like
+                  // field '" + field + "'");
+                  type = -1; /* invalid field! - throw the FieldSet away */
+                }
+                ;
               }
-              else
+              fields.put(Fields[i++], field);
+              if (st.hasMoreTokens())
               {
-                // jalview.bin.Cache.log.debug(
-                // "Ignoring non-Modeller description: invalid integer-like
-                // field '" + field + "'");
-                type = -1; /* invalid field! - throw the FieldSet away */
+                st.nextToken(); // skip token sep.
               }
-              ;
             }
-            fields.put(Fields[i++], field);
+            else
+            {
+              i++;
+            }
           }
         }
         if (i == TAIL)
@@ -169,7 +184,8 @@ public class ModellerDescription
           // slurp remaining fields
           while (st.hasMoreTokens())
           {
-            field += ":" + st.nextToken(":");
+            String tl = st.nextToken(":");
+            field += tl.equals(":") ? tl : (":" + tl);
           }
           fields.put(Fields[TAIL], field);
         }
@@ -229,12 +245,15 @@ public class ModellerDescription
     {
       // Set start and end before we update the type (in the case of a
       // synthesized field set)
-      if (getStartNum() != seq.getStart() && getStartCode().val != null)
+      if (getStartCode() == null
+              || (getStartNum() != seq.getStart() && getStartCode().val != null))
       {
+        // unset or user updated sequence start position
         setStartCode(seq.getStart());
       }
 
-      if (getEndNum() != seq.getEnd() && getStartCode().val != null)
+      if (getEndCode() == null
+              || (getEndNum() != seq.getEnd() && getStartCode() != null && getStartCode().val != null))
       {
         setEndCode(seq.getEnd());
       }
@@ -337,7 +356,7 @@ public class ModellerDescription
   {
     int start = 0;
     resCode val = getStartCode();
-    if (val.val != null)
+    if (val != null && val.val != null)
     {
       return val.val.intValue();
     }
@@ -366,7 +385,7 @@ public class ModellerDescription
   {
     int end = 0;
     resCode val = getEndCode();
-    if (val.val != null)
+    if (val != null && val.val != null)
     {
       return val.val.intValue();
     }
@@ -384,7 +403,8 @@ public class ModellerDescription
   {
     if (isModellerFieldset())
     {
-      if (getStartCode().val != null)
+      resCode rc = getStartCode();
+      if (rc != null && rc.val != null)
       {
         newSeq.setStart(getStartNum());
       }
@@ -392,7 +412,8 @@ public class ModellerDescription
       {
         newSeq.setStart(1);
       }
-      if (getEndCode().val != null)
+      rc = getEndCode();
+      if (rc != null && rc.val != null)
       {
         newSeq.setEnd(getEndNum());
       }