Merge branch 'feature/JAL-3187linkedFeatures' into feature/JAL-3251biotypedMappings
[jalview.git] / src / jalview / datamodel / SequenceMappings.java
1 package jalview.datamodel;
2
3 import java.util.ArrayList;
4 import java.util.Collections;
5 import java.util.HashMap;
6 import java.util.List;
7 import java.util.Map;
8
9 /**
10  * A singleton object that holds all mappings between sequences
11  * 
12  * @author gmcarstairs
13  *
14  */
15 public class SequenceMappings
16 {
17   private static SequenceMappings instance;
18
19   private Map<SequenceI, List<SequenceMapping>> mappingsFrom;
20
21   private Map<SequenceI, List<SequenceMapping>> mappingsTo;
22
23   /**
24    * Non-instantiable class
25    */
26   private SequenceMappings()
27   {
28     mappingsFrom = new HashMap<>();
29     mappingsTo = new HashMap<>();
30   }
31
32   /**
33    * Answers the singleton instance of this class
34    * 
35    * @return
36    */
37   public SequenceMappings getInstance()
38   {
39     return instance;
40   }
41
42   /**
43    * Answers a (possibly empty) unmodifiable list of mappings from the given
44    * sequence
45    * 
46    * @param seq
47    * @return
48    */
49   public List<SequenceMapping> getMappingsFromSequence(SequenceI seq)
50   {
51     List<SequenceMapping> from = mappingsFrom.get(seq);
52     return from == null ? Collections.emptyList()
53             : Collections.unmodifiableList(from);
54   }
55
56   /**
57    * Answers a (possibly empty) unmodifiable list of mappings to the given
58    * sequence
59    * 
60    * @param seq
61    * @return
62    */
63   public List<SequenceMapping> getMappingsToSequence(SequenceI seq)
64   {
65     List<SequenceMapping> from = mappingsTo.get(seq);
66     return from == null ? Collections.emptyList()
67             : Collections.unmodifiableList(from);
68   }
69
70   /**
71    * Answers a (possibly empty) list of mappings from the given sequence to its
72    * complement(s), defined as mappings that are either CdsToPeptide or
73    * PeptideToCds
74    * 
75    * @param seq
76    * @return
77    */
78   public List<SequenceMapping> getMappingsToComplement(SequenceI seq)
79   {
80     List<SequenceMapping> from = mappingsTo.get(seq);
81     List<SequenceMapping> result = new ArrayList<>();
82     for (SequenceMapping mapping : from)
83     {
84       MappingType type = mapping.getType();
85     }
86     return result;
87   }
88 }