JAL-3253 jalview.bin.Instance for AppCache and FeatureAttribute
[jalview.git] / src / jalview / datamodel / features / FeatureSources.java
1 package jalview.datamodel.features;
2
3 import jalview.bin.Instance;
4
5 import java.util.HashMap;
6 import java.util.Map;
7
8 public class FeatureSources
9 {
10
11   public static FeatureSources getInstance()
12   {
13     Instance i = Instance.getInstance();
14     return (i.featureSources == null
15             ? i.featureSources = new FeatureSources()
16             : i.featureSources);
17   }
18
19   private Map<String, FeatureSourceI> sources;
20
21   private FeatureSources()
22   {
23     sources = new HashMap<>();
24   }
25
26   /**
27    * Answers the FeatureSource with the given unique identifier, or null if not
28    * known
29    * 
30    * @param sourceId
31    * @return
32    */
33   public FeatureSourceI getSource(String sourceId)
34   {
35     return sources.get(sourceId);
36   }
37
38   /**
39    * Adds the given source under the given key. This will replace any existing
40    * source with the same id, it is the caller's responsibility to ensure keys
41    * are unique if necessary.
42    * 
43    * @param sourceId
44    * @param source
45    */
46   public void addSource(String sourceId, FeatureSource source)
47   {
48     sources.put(sourceId, source);
49   }
50 }