JAL-2069 update spike branch with latest
[jalview.git] / src / jalview / datamodel / SequenceFeature.java
index 8f82a1a..2110632 100755 (executable)
@@ -21,6 +21,7 @@
 package jalview.datamodel;
 
 import jalview.datamodel.features.FeatureAttributeType;
+import jalview.datamodel.features.FeatureAttributes;
 import jalview.datamodel.features.FeatureLocationI;
 import jalview.datamodel.features.FeatureSourceI;
 import jalview.datamodel.features.FeatureSources;
@@ -392,6 +393,23 @@ public class SequenceFeature implements FeatureLocationI
   }
 
   /**
+   * Answers the value of the specified attribute as string, or null if no such
+   * value
+   * 
+   * @param key
+   * @return
+   */
+  public String getValueAsString(String key)
+  {
+    if (otherDetails == null)
+    {
+      return null;
+    }
+    Object value = otherDetails.get(key);
+    return value == null ? null : value.toString();
+  }
+
+  /**
    * Returns a property value for the given key if known, else the specified
    * default value
    * 
@@ -424,9 +442,31 @@ public class SequenceFeature implements FeatureLocationI
       }
 
       otherDetails.put(key, value);
+      recordAttribute(key, value);
     }
   }
 
+  /**
+   * Notifies the addition of a feature attribute. This lets us keep track of
+   * which attributes are present on each feature type, and also the range of
+   * numerical-valued attributes.
+   * 
+   * @param key
+   * @param value
+   */
+  protected void recordAttribute(String key, Object value)
+  {
+    String attDesc = null;
+    if (source != null)
+    {
+      attDesc = FeatureSources.getInstance().getSource(source)
+              .getAttributeName(key);
+    }
+
+    FeatureAttributes.getInstance().addAttribute(this.type, key, attDesc,
+            value.toString());
+  }
+
   /*
    * The following methods are added to maintain the castor Uniprot mapping file
    * for the moment.