JAL-1369 JAL-1397 version check to support correct interpretation for older projects...
authorJim Procter <jprocter@dundee.ac.uk>
Fri, 2 May 2014 09:41:03 +0000 (10:41 +0100)
committerJim Procter <jprocter@dundee.ac.uk>
Fri, 2 May 2014 09:41:03 +0000 (10:41 +0100)
src/jalview/gui/Jalview2XML.java

index da81945..400fd94 100644 (file)
@@ -3178,7 +3178,62 @@ public class Jalview2XML
     // and finally return.
     return af;
   }
-  Vector<AppJmol> newStructureViewers=null;
+
+  /**
+   * 
+   * @param supported - minimum version we are comparing against
+   * @param version - version of data being processsed.
+   * @return true if version is development/null or evaluates to the same or
+   *         later X.Y.Z (where X,Y,Z are like [0-9]+b?[0-9]*)
+   */
+  private boolean isVersionStringLaterThan(String supported, String version)
+  {
+    if (version == null || version.equalsIgnoreCase("DEVELOPMENT BUILD")
+            || version.equalsIgnoreCase("Test"))
+    {
+      System.err.println("Assuming project file with "
+              + (version == null ? "null" : version)
+              + " is compatible with Jalview version " + supported);
+      return true;
+    }
+    else
+    {
+      StringTokenizer currentV = new StringTokenizer(supported, "."), fileV = new StringTokenizer(
+              version, ".");
+      while (currentV.hasMoreTokens() && fileV.hasMoreTokens())
+      {
+        // convert b to decimal to catch bugfix releases within a series
+        String curT = currentV.nextToken().toLowerCase().replace('b', '.');
+        String fileT = fileV.nextToken().toLowerCase().replace('b', '.');
+        try
+        {
+          if (Float.valueOf(curT) > Float.valueOf(fileT))
+          {
+            // current version is newer than the version that wrote the file
+            return false;
+          }
+        } catch (NumberFormatException nfe)
+        {
+          System.err
+                  .println("** WARNING: Version comparison failed for tokens ("
+                          + curT
+                          + ") and ("
+                          + fileT
+                          + ")\n** Current: '"
+                          + supported + "' and Version: '" + version + "'");
+        }
+      }
+      if (currentV.hasMoreElements())
+      {
+        // fileV has no minor version but identical series to current
+        return false;
+      }
+    }
+    return true;
+  }
+
+  Vector<AppJmol> newStructureViewers = null;
+
   protected void addNewStructureViewer(AppJmol sview)
   {
     if (newStructureViewers != null)