JAL-3664 support for user.home, user.dir, user
[jalview.git] / src / jalview / datamodel / features / FeatureAttributes.java
index 01f04d5..655d1eb 100644 (file)
@@ -48,6 +48,11 @@ public class FeatureAttributes implements ApplicationSingletonI
             .getInstance(FeatureAttributes.class);
   }
 
+  private FeatureAttributes()
+  {
+    attributes = new HashMap<>();
+  }
+
   /*
    * map, by feature type, of a map, by attribute name, of
    * attribute description and min-max range (if known)
@@ -132,7 +137,7 @@ public class FeatureAttributes implements ApplicationSingletonI
          * Parse numeric value unless we have previously
          * seen text data for this attribute type
          */
-        if (type == null || type == Datatype.Number)
+        if (type == null && couldBeNumber(value) || type == Datatype.Number)
         {
           try
           {
@@ -199,11 +204,6 @@ public class FeatureAttributes implements ApplicationSingletonI
     }
   }
 
-  private FeatureAttributes()
-  {
-    attributes = new HashMap<>();
-  }
-
   /**
    * Answers the attribute names known for the given feature type, in
    * alphabetical order (not case sensitive), or an empty set if no attributes
@@ -224,6 +224,27 @@ public class FeatureAttributes implements ApplicationSingletonI
   }
 
   /**
+   * This quick check will save significant time avoiding numerous NumberFormatExceptions.
+   * 
+   * @param f
+   * @return
+   */
+  public boolean couldBeNumber(String f)
+  {
+    int len = f.length();
+    if (len == 0)
+      return false;
+    char ch = f.charAt(0);
+    switch (ch) {
+    case '.':
+    case '+':
+    case '-':
+      return len > 1;
+    }
+    return (ch <= '9' &&  ch >= '0');
+  }
+
+  /**
    * Answers true if at least one attribute is known for the given feature type,
    * else false
    *