JAL-2446 FeatureStore with NCList - work in progress
[jalview.git] / src / jalview / datamodel / features / SequenceFeatures.java
1 package jalview.datamodel.features;
2
3 import jalview.datamodel.SequenceFeature;
4
5 import java.util.Collections;
6 import java.util.HashMap;
7 import java.util.List;
8 import java.util.Map;
9
10 public class SequenceFeatures
11 {
12
13   /*
14    * map from feature type to structured store of features for that type
15    */
16   private Map<String, FeatureStore> featureStore;
17
18   /**
19    * Constructor
20    */
21   public SequenceFeatures()
22   {
23     featureStore = new HashMap<String, FeatureStore>();
24   }
25
26   /**
27    * Add one sequence feature to the store
28    * 
29    * @param sf
30    */
31   public void add(SequenceFeature sf)
32   {
33     String type = sf.getType();
34     if (featureStore.get(type) == null)
35     {
36       featureStore.put(type, new FeatureStore());
37     }
38     featureStore.get(type).addFeature(sf);
39   }
40
41   /**
42    * Returns a (possibly empty) list of features of the given type which overlap
43    * the (inclusive) sequence position range
44    * 
45    * @param type
46    * @param from
47    * @param to
48    * @return
49    */
50   public List<SequenceFeature> findFeatures(String type, int from,
51           int to)
52   {
53     FeatureStore features = featureStore.get(type);
54     if (features == null)
55     {
56       return Collections.emptyList();
57     }
58     return features.findOverlappingFeatures(from, to);
59   }
60 }