JAL-2446 FeatureStore with NCList - work in progress
[jalview.git] / src / jalview / datamodel / features / SequenceFeatures.java
diff --git a/src/jalview/datamodel/features/SequenceFeatures.java b/src/jalview/datamodel/features/SequenceFeatures.java
new file mode 100644 (file)
index 0000000..d177566
--- /dev/null
@@ -0,0 +1,60 @@
+package jalview.datamodel.features;
+
+import jalview.datamodel.SequenceFeature;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class SequenceFeatures
+{
+
+  /*
+   * map from feature type to structured store of features for that type
+   */
+  private Map<String, FeatureStore> featureStore;
+
+  /**
+   * Constructor
+   */
+  public SequenceFeatures()
+  {
+    featureStore = new HashMap<String, FeatureStore>();
+  }
+
+  /**
+   * Add one sequence feature to the store
+   * 
+   * @param sf
+   */
+  public void add(SequenceFeature sf)
+  {
+    String type = sf.getType();
+    if (featureStore.get(type) == null)
+    {
+      featureStore.put(type, new FeatureStore());
+    }
+    featureStore.get(type).addFeature(sf);
+  }
+
+  /**
+   * Returns a (possibly empty) list of features of the given type which overlap
+   * the (inclusive) sequence position range
+   * 
+   * @param type
+   * @param from
+   * @param to
+   * @return
+   */
+  public List<SequenceFeature> findFeatures(String type, int from,
+          int to)
+  {
+    FeatureStore features = featureStore.get(type);
+    if (features == null)
+    {
+      return Collections.emptyList();
+    }
+    return features.findOverlappingFeatures(from, to);
+  }
+}